easymodel.treemodel.TreeModel¶
-
class
easymodel.treemodel.TreeModel(root, parent=None)[source]¶ Bases:
PySide.QtCore.QAbstractItemModelA tree model that uses the
TreeItemto represent a general tree.The model uses
TreeIteminstances in an hierarchy to build a tree. Each tree item represents a row. The tree items can hold arbitraryItemDatainstances.The model will get automatically updated, when the hierarchy of the tree items changes. You rarely have to use model methods for that. Just use methods of the tree items.
All models need at least a root. The root is responsible for the headers. So the
ItemDataof the root should have a columns for each header and return a string for them when queried withQtCore.Qt.DisplayRole. Only horizontal headers are supported at the moment. Vertical headers get numbers.Initialize a new tree model with the given root treeitem
Parameters: - root (
TreeItem) – the root tree item. The root tree item is responsible for the headers. AListItemDatawith the headers is suitable as data for the item. - parent (
QtCore.QObject) – the parent for the model
Raises: None
-
__init__(root, parent=None)[source]¶ Initialize a new tree model with the given root treeitem
Parameters: - root (
TreeItem) – the root tree item. The root tree item is responsible for the headers. AListItemDatawith the headers is suitable as data for the item. - parent (
QtCore.QObject) – the parent for the model
Raises: None
- root (
Methods
__init__(root[, parent])Initialize a new tree model with the given root treeitem beginInsertColumnsbeginInsertRowsbeginMoveColumnsbeginMoveRowsbeginRemoveColumnsbeginRemoveRowsbeginResetModelblockSignalsbuddycanFetchMorechangePersistentIndexchangePersistentIndexListchildEventchildrencolumnCount(parent)Return the number of columns for the children of the given parent. connectconnectNotifycreateIndexcustomEventdata(index[, role])Return the data stored under the given role for the item referred to by the index. decodeDatadeleteLaterdisconnectdisconnectNotifydropMimeDatadumpObjectInfodumpObjectTreedynamicPropertyNamesemitencodeDataendInsertColumnsendInsertRowsendMoveColumnsendMoveRowsendRemoveColumnsendRemoveRowsendResetModeleventeventFilterfetchMorefindChildfindChildrenflags(index)Return the flags for the given index hasChildrenhasIndexheaderData(section, orientation, role)Return the header data index(row, column[, parent])Return the index of the item in the model specified by the given row, column and parent index. index_of_item(item[, column])Get the index for the given TreeItem inheritsinsertColumninsertColumnsinsertRow(row, item, parent)Insert a single item before the given row in the child items of the parent specified. insertRowsinstallEventFilterisWidgetTypeitemDatakillTimermatchmetaObjectmimeDatamimeTypesmoveToThreadobjectNameparent(index)Return the parent of the model item with the given index. persistentIndexListpropertyreceiversregisterUserDataremoveColumnremoveColumnsremoveEventFilterremoveRow(row, parent)Remove row from parent removeRowsresetresetInternalDatarevertroleNamesrowCount(parent)Return the number of rows under the given parent. sendersenderSignalIndexsetData(index, value[, role])Set the data of the given index to value setHeaderDatasetItemDatasetObjectNamesetParentsetPropertysetRoleNamessetSupportedDragActionssiblingsignalsBlockedsortspanstartTimersubmitsupportedDragActionssupportedDropActionsthreadtimerEventtrtrUtf8Attributes
columnsAboutToBeInsertedcolumnsAboutToBeMovedcolumnsAboutToBeRemovedcolumnsInsertedcolumnsMovedcolumnsRemoveddataChangeddestroyedheaderDataChangedlayoutAboutToBeChangedlayoutChangedmodelAboutToBeResetmodelResetrootReturn the root tree item rowsAboutToBeInsertedrowsAboutToBeMovedrowsAboutToBeRemovedrowsInsertedrowsMovedrowsRemovedstaticMetaObject-
index(row, column, parent=None)[source]¶ Return the index of the item in the model specified by the given row, column and parent index.
Parameters: Returns: the index of the item
Return type: QtCore.QModelIndexRaises: None
-
parent(index)[source]¶ Return the parent of the model item with the given index. If the item has no parent, return an invalid QModelIndex.
Parameters: index ( QtCore.QModelIndex) – the index that you want to know the parent ofReturns: parent index Return type: QtCore.QModelIndexRaises: None
-
rowCount(parent)[source]¶ Return the number of rows under the given parent. When the parent is valid return rowCount the number of children of parent.
Parameters: parent ( QtCore.QModelIndex:) – the parent indexReturns: the row count Return type: int Raises: None
-
columnCount(parent)[source]¶ Return the number of columns for the children of the given parent.
Parameters: parent ( QtCore.QModelIndex:) – the parent indexReturns: the column count Return type: int Raises: None
-
data(index, role=PySide.QtCore.Qt.ItemDataRole.DisplayRole)[source]¶ Return the data stored under the given role for the item referred to by the index.
Parameters: - index (
QtCore.QModelIndex) – the index - role (QtCore.Qt.ItemDataRole) – the data role
Returns: some data depending on the role
Raises: None
- index (
-
setData(index, value, role=PySide.QtCore.Qt.ItemDataRole.EditRole)[source]¶ Set the data of the given index to value
Parameters: - index (
QtCore.QModelIndex) – the index to set - value – the value to set
- role (
QtCore.Qt.ItemDataRole) – the role, usually edit role
Returns: True, if successfull, False if unsuccessfull
Return type: Raises: None
- index (
-
headerData(section, orientation, role)[source]¶ Return the header data
Will call
TreeItem.data()of the rootTreeItemwith the given section (column) and role for horizontal orientations.Vertical orientations are numbered.
Parameters: - section (int) – the section in the header view
- orientation (
QtCore.Qt.Vertical|QtCore.Qt.Horizontal) – vertical or horizontal orientation - role (
QtCore.Qt.ItemDataRole) – the data role.
Returns: data for the header
Raises: None
-
insertRow(row, item, parent)[source]¶ Insert a single item before the given row in the child items of the parent specified.
Parameters: Returns: Returns true if the row is inserted; otherwise returns false.
Return type: Raises: None
-
removeRow(row, parent)[source]¶ Remove row from parent
Parameters: - row (int) – the row index
- parent (
QtCore.QModelIndex) – the parent index
Returns: True if row is inserted; otherwise returns false.
Return type: Raises: None
-
flags(index)[source]¶ Return the flags for the given index
This will call
TreeItem.flags()for valid ones.Parameters: index ( QtCore.QModelIndex) – the index to queryReturns: None Return type: None Raises: None
-
staticMetaObject= <PySide.QtCore.QMetaObject object>¶
- root (