spinetoolbox.mvcmodels.minimal_tree_model

Models to represent items in a tree.

authors:
  1. Vennström (VTT), M. Marin (KTH)
date:

11.3.2019

Module Contents

class spinetoolbox.mvcmodels.minimal_tree_model.TreeItem(model=None)[source]

A tree item that can fetch its children.

Initializes item.

Parameters:model (MinimalTreeModel, NoneType) – The model where the item belongs.
model[source]
child_item_type[source]

Returns the type of child items. Reimplement in subclasses to return something more meaningfull.

children[source]
parent_item[source]
display_name[source]
child(self, row)[source]

Returns the child at given row or None if out of bounds.

last_child(self)[source]

Returns the last child.

child_count(self)[source]

Returns the number of children.

child_number(self)[source]

Returns the rank of this item within its parent or 0 if it’s an orphan.

find_children(self, cond=lambda child: True)[source]

Returns children that meet condition expressed as a lambda function.

find_child(self, cond=lambda child: True)[source]

Returns first child that meet condition expressed as a lambda function or None.

next_sibling(self)[source]

Returns the next sibling or None if it’s the last.

previous_sibling(self)[source]

Returns the previous sibling or None if it’s the first.

index(self)[source]
insert_children(self, 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 (iter) – insert items from this iterable
append_children(self, *children)[source]

Append children at the end.

remove_children(self, position, count)[source]

Removes count children starting from the given position.

clear_children(self)[source]

Clear children list.

flags(self, column)[source]

Enables the item and makes it selectable.

data(self, column, role=Qt.DisplayRole)[source]

Returns data for given column and role.

has_children(self)[source]

Returns whether or not this item has or could have children.

can_fetch_more(self)[source]

Returns whether or not this item can fetch more.

fetch_more(self)[source]

Fetches more children.

class spinetoolbox.mvcmodels.minimal_tree_model.MinimalTreeModel(parent=None)[source]

Bases: PySide2.QtCore.QAbstractItemModel

Base class for all tree models.

Init class.

Parameters:parent (DataStoreForm) –
visit_all(self, index=QModelIndex())[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.

item_from_index(self, index)[source]

Return the item corresponding to the given index.

index_from_item(self, item)[source]

Return a model index corresponding to the given item.

index(self, row, column, parent=QModelIndex())[source]

Returns the index of the item in the model specified by the given row, column and parent index.

parent(self, index)[source]

Returns the parent of the model item with the given index.

columnCount(self, parent=QModelIndex())[source]
rowCount(self, parent=QModelIndex())[source]
data(self, index, role=Qt.DisplayRole)[source]

Returns the data stored under the given role for the index.

setData(self, index, value, role=Qt.EditRole)[source]

Sets data for given index and role. Returns True if successful; otherwise returns False.

flags(self, index)[source]

Returns the item flags for the given index.

hasChildren(self, parent)[source]
canFetchMore(self, parent)[source]
fetchMore(self, parent)[source]