spinetoolbox.mvcmodels.project_item_model

Contains a class for storing project items.

authors
  1. Savolainen (VTT)

date

23.1.2018

Module Contents

Classes

ProjectItemModel

Class to store project tree items and ultimately project items in a tree structure.

class spinetoolbox.mvcmodels.project_item_model.ProjectItemModel(root, parent=None)[source]

Bases: PySide2.QtCore.QAbstractItemModel

Class to store project tree items and ultimately project items in a tree structure.

Parameters
  • root (RootProjectTreeItem) – Root item for the project item tree

  • parent (QObject) – parent object

root(self)[source]

Returns the root item.

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

columnCount(self, parent=QModelIndex())[source]

Returns model column count which is always 1.

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
Returns

True if successful, False otherwise

Return type

bool

remove_item(self, item, parent=QModelIndex())[source]

Removes item from project.

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

set_leaf_item_name(self, index, name)[source]

Changes the name of the leaf item at given index.

Parameters
  • index (QModelIndex) – Tree item index

  • name (str) – New project item name

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

items_per_category(self)[source]

Returns a dict mapping category indexes to a list of items in that category.

Returns

dict(QModelIndex,list(LeafProjectTreeItem))

short_name_reserved(self, short_name)[source]

Checks if the directory name derived from the name of the given item is in use.

Parameters

short_name (str) – Item short name

Returns

True if short name is taken, False if it is available.

Return type

bool

leaf_indexes(self)[source]

Yields leaf indexes.

remove_leaves(self)[source]