spinetoolbox.mvcmodels.project_item_model
¶
Contains a class for storing project items.
authors: |
|
---|---|
date: | 23.1.2018 |
Module Contents¶
-
class
spinetoolbox.mvcmodels.project_item_model.
ProjectItemModel
(toolbox, root)[source]¶ Bases:
PySide2.QtCore.QAbstractItemModel
Class to store project tree items and ultimately project items in a tree structure.
Parameters: - toolbox (ToolboxUI) – QMainWindow instance
- root (RootProjectTreeItem) – Root item for the project item tree
-
rowCount
(self, parent=QModelIndex())[source]¶ Reimplemented rowCount method.
Parameters: parent (QModelIndex) – Index of parent item whose children are counted. Returns: Number of children of given parent Return type: int
-
flags
(self, index)[source]¶ Returns flags for the item at given index
Parameters: index (QModelIndex) – Flags of item at this index.
-
parent
(self, index=QModelIndex())[source]¶ Returns index of the parent of given index.
Parameters: index (QModelIndex) – Index of item whose parent is returned Returns: Index of parent item Return type: QModelIndex
-
index
(self, row, column, parent=QModelIndex())[source]¶ Returns index of item with given row, column, and parent.
Parameters: - row (int) – Item row
- column (int) – Item column
- parent (QModelIndex) – Parent item index
Returns: Item index
Return type: QModelIndex
-
data
(self, index, role=None)[source]¶ Returns data in the given index according to requested role.
Parameters: - index (QModelIndex) – Index to query
- role (int) – Role to return
Returns: Data depending on role.
Return type: object
-
item
(self, index)[source]¶ Returns item at given index.
Parameters: index (QModelIndex) – Index of item Returns: - Item at given index or root project
- item if index is not valid
Return type: RootProjectTreeItem, CategoryProjectTreeItem or LeafProjectTreeItem
-
find_category
(self, category_name)[source]¶ Returns the index of the given category name.
Parameters: category_name (str) – Name of category item to find Returns: index of a category item or None if it was not found Return type: QModelIndex
-
find_item
(self, name)[source]¶ Returns the QModelIndex of the leaf item with the given name
Parameters: name (str) – The searched project item (long) name Returns: Index of a project item with the given name or None if not found Return type: QModelIndex
-
get_item
(self, name)[source]¶ Returns leaf item with given name or None if it doesn’t exist.
Parameters: name (str) – Project item name Returns: LeafProjectTreeItem, NoneType
-
category_of_item
(self, name)[source]¶ Returns the category item of the category that contains project item with given name
Parameters: name (str) – Project item name Returns: category item or None if the category was not found
-
insert_item
(self, item, parent=QModelIndex())[source]¶ Adds a new item to model. Fails if given parent is not a category item nor a leaf item. New item is inserted as the last item of its branch.
Parameters: - item (CategoryProjectTreeItem or LeafProjectTreeItem) – Project item to add to model
- parent (QModelIndex) – Parent project item
Returns: True if successful, False otherwise
Return type: bool
-
remove_item
(self, item, parent=QModelIndex())[source]¶ Removes item from model.
Parameters: - item (BaseProjectTreeItem) – Project item to remove
- parent (QModelIndex) – Parent of item that is to be removed
Returns: True if item removed successfully, False if item removing failed
Return type: bool
-
setData
(self, index, value, role=Qt.EditRole)[source]¶ Changes the name of the leaf item at given index to given value.
Parameters: - index (QModelIndex) – Tree item index
- value (str) – New project item name
- role (int) – Item data role to set
Returns: True or False depending on whether the new name is acceptable and renaming succeeds
Return type: bool
-
items
(self, category_name=None)[source]¶ Returns a list of leaf items in model according to category name. If no category name given, returns all leaf items in a list.
Parameters: category_name (str) – Item category. Data Connections, Data Stores, Importers, Exporters, Tools or Views permitted. Returns: obj:’list’ of :obj:’LeafProjectTreeItem’: Depending on category_name argument, returns all items or only items according to category. An empty list is returned if there are no items in the given category or if an unknown category name was given.
-
n_items
(self)[source]¶ Returns the number of all items in the model excluding category items and root.
Returns: Number of items Return type: int
-
item_names
(self)[source]¶ Returns all leaf item names in a list.
Returns: ‘list’ of obj:’str’: Item names Return type: obj