spinetoolbox.mvcmodels.minimal_tree_model
Models to represent items in a tree.
Module Contents
Classes
A tree item that can fetch its children. |
|
Base class for all tree models. |
- class spinetoolbox.mvcmodels.minimal_tree_model.TreeItem(model)[source]
A tree item that can fetch its children.
- Parameters
model (MinimalTreeModel) – The model where the item belongs.
- is_valid()[source]
Tests if item is valid.
- Returns
True if item is valid, False otherwise
- Return type
bool
- row_count()[source]
Returns the number of rows, which may be different from the number of children. This allows subclasses to hide children.
- find_children(cond=lambda child: ...)[source]
Returns children that meet condition expressed as a lambda function.
- find_child(cond=lambda child: ...)[source]
Returns first child that meet condition expressed as a lambda function or None.
- insert_children(position, children)[source]
Insert new children at given position. Returns a boolean depending on how it went.
- Parameters
position (int) – insert new items here
children (list of TreeItem) – insert items from this iterable
- Returns
True if the children were inserted successfully, False otherwise
- Return type
bool
- class spinetoolbox.mvcmodels.minimal_tree_model.MinimalTreeModel(parent)[source]
Bases:
PySide6.QtCore.QAbstractItemModel
Base class for all tree models.
Init class.
- Parameters
parent (SpineDBEditor) –
- visit_all(index=QModelIndex(), view=None)[source]
Iterates all items in the model including and below the given index. Iterative implementation so we don’t need to worry about Python recursion limits.
- Parameters
index (QModelIndex) – an index to start. If not given, we start at the root
view (QTreeView) – a tree view. If given, we only yield items that are visible to that view. So for example, if a tree item is not expanded then we don’t yield its children.
- Yields
TreeItem
- item_from_index(index)[source]
Return the item corresponding to the given index.
- Parameters
index (QModelIndex) – model index
- Returns
item at index
- Return type
- index_from_item(item)[source]
Return a model index corresponding to the given item.
- Parameters
item (StandardTreeItem) – item
- Returns
item’s index
- Return type
QModelIndex
- index(row, column, parent=QModelIndex())[source]
Returns the index of the item in the model specified by the given row, column and parent index.
- data(index, role=Qt.ItemDataRole.DisplayRole)[source]
Returns the data stored under the given role for the index.