spinetoolbox.mvcmodels.entity_tree_item

Classes to represent entities in a tree.

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

11.3.2019

Module Contents

class spinetoolbox.mvcmodels.entity_tree_item.MultiDBTreeItem(model=None, db_map_id=None)[source]

Bases: spinetoolbox.mvcmodels.minimal_tree_model.TreeItem

A tree item that may belong in multiple databases.

Init class.

Parameters:
  • db_mngr (SpineDBManager) – a database manager
  • db_map_data (dict) – maps instances of DiffDatabaseMapping to the id of the item in that db
item_type[source]

Item type identifier string. Should be set to a meaningful value by subclasses.

visual_key = ['name'][source]
db_mngr[source]
child_item_type[source]

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

display_id[source]

“Returns an id for display based on the display key. This id must be the same across all db_maps. If it’s not, this property becomes None and measures need to be taken (see update_children_by_id).

display_name[source]

“Returns the name for display.

display_database[source]

“Returns the database for display.

display_icon[source]

Returns an icon to display next to the name. Reimplement in subclasses to return something nice.

first_db_map[source]

Returns the first associated db_map.

last_db_map[source]

Returns the last associated db_map.

db_maps[source]

Returns a list of all associated db_maps.

add_db_map_id(self, db_map, id_)[source]

Adds id for this item in the given db_map.

take_db_map(self, db_map)[source]

Removes the mapping for given db_map and returns it.

deep_remove_db_map(self, db_map)[source]

Removes given db_map from this item and all its descendants.

deep_take_db_map(self, db_map)[source]

Takes given db_map from this item and all its descendants. Returns a new item from taken data or None if db_map is not present in the first place.

deep_merge(self, other)[source]

Merges another item and all its descendants into this one.

db_map_id(self, db_map)[source]

Returns the id for this item in given db_map or None if not present.

db_map_data(self, db_map)[source]

Returns data for this item in given db_map or None if not present.

db_map_data_field(self, db_map, field, default=None)[source]

Returns field from data for this item in given db_map or None if not found.

_create_new_children(self, db_map, children_ids)[source]

Creates new items from ids associated to a db map.

Parameters:
  • db_map (DiffDatabaseMapping) – create children for this db_map
  • children_data (iter) – create childs from these dictionaries
_merge_children(self, new_children)[source]

Merges new children into this item. Ensures that each children has a valid display id afterwards.

has_children(self)[source]

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

fetch_more(self)[source]

Fetches children from all associated databases.

_get_children_ids(self, db_map)[source]

Returns a list of children ids. Must be reimplemented in subclasses.

append_children_by_id(self, db_map_ids)[source]

Appends children by id.

Parameters:db_map_ids (dict) – maps DiffDatabaseMapping instances to list of ids
remove_children_by_id(self, db_map_ids)[source]

Removes children by id.

Parameters:db_map_ids (dict) – maps DiffDatabaseMapping instances to list of ids
update_children_by_id(self, db_map_ids)[source]

Updates children by id. Essentially makes sure all children have a valid display id after updating the underlying data. These may require ‘splitting’ a child into several for different dbs or merging two or more children from different dbs.

Examples of problems:

  • The user renames an object class in one db but not in the others –> we need to split
  • The user renames an object class and the new name is already ‘taken’ by another object class in another db_map –> we need to merge
Parameters:db_map_ids (dict) – maps DiffDatabaseMapping instances to list of ids
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
remove_children(self, position, count)[source]

Removes count children starting from the given position.

clear_children(self)[source]

Clear children list.

_refresh_child_map(self)[source]

Recomputes the child map.

find_children_by_id(self, db_map, *ids, reverse=True)[source]

Generates children with the given ids in the given db_map. If the first id is True, then generates all children with the given db_map.

find_rows_by_id(self, db_map, *ids, reverse=True)[source]
_find_unsorted_rows_by_id(self, db_map, *ids)[source]

Generates rows corresponding to children with the given ids in the given db_map. If the first id is True, then generates rows corresponding to all children with the given db_map.

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

Returns data for given column and role.

default_parameter_data(self)[source]

Returns data to set as default in a parameter table when this item is selected.

class spinetoolbox.mvcmodels.entity_tree_item.TreeRootItem[source]

Bases: spinetoolbox.mvcmodels.entity_tree_item.MultiDBTreeItem

item_type = root[source]
display_id[source]

“See super class.

display_name[source]

“See super class.

class spinetoolbox.mvcmodels.entity_tree_item.ObjectTreeRootItem(*args, **kwargs)[source]

Bases: spinetoolbox.mvcmodels.entity_tree_item.TreeRootItem

An object tree root item.

child_item_type[source]

Returns an ObjectClassItem.

_get_children_ids(self, db_map)[source]

Returns a list of object class ids.

class spinetoolbox.mvcmodels.entity_tree_item.RelationshipTreeRootItem(*args, **kwargs)[source]

Bases: spinetoolbox.mvcmodels.entity_tree_item.TreeRootItem

A relationship tree root item.

child_item_type[source]

Returns a RelationshipClassItem.

_get_children_ids(self, db_map)[source]

Returns a list of relationship class ids.

class spinetoolbox.mvcmodels.entity_tree_item.EntityClassItem[source]

Bases: spinetoolbox.mvcmodels.entity_tree_item.MultiDBTreeItem

An entity class item.

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

Returns data for given column and role.

class spinetoolbox.mvcmodels.entity_tree_item.ObjectClassItem(*args, **kwargs)[source]

Bases: spinetoolbox.mvcmodels.entity_tree_item.EntityClassItem

An object class item.

item_type = object class[source]
display_icon[source]

Returns the object class icon.

child_item_type[source]

Returns an ObjectItem.

_get_children_ids(self, db_map)[source]

Returns a list of object ids in this class.

default_parameter_data(self)[source]

Return data to put as default in a parameter table when this item is selected.

class spinetoolbox.mvcmodels.entity_tree_item.RelationshipClassItem(*args, **kwargs)[source]

Bases: spinetoolbox.mvcmodels.entity_tree_item.EntityClassItem

A relationship class item.

visual_key = ['name', 'object_class_name_list'][source]
item_type = relationship class[source]
display_icon[source]

Returns relationship class icon.

child_item_type[source]

Returns a RelationshipItem.

_get_children_ids(self, db_map)[source]

Returns a list of relationship ids in this class. If the parent is an ObjectItem, then only returns ids of relationships involving that object.

default_parameter_data(self)[source]

Return data to put as default in a parameter table when this item is selected.

class spinetoolbox.mvcmodels.entity_tree_item.EntityItem[source]

Bases: spinetoolbox.mvcmodels.entity_tree_item.MultiDBTreeItem

An entity item.

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

Returns data for given column and role.

class spinetoolbox.mvcmodels.entity_tree_item.ObjectItem(*args, **kwargs)[source]

Bases: spinetoolbox.mvcmodels.entity_tree_item.EntityItem

An object item.

item_type = object[source]
child_item_type[source]

Returns a RelationshipClassItem.

display_icon[source]

Returns the object class icon.

_get_children_ids(self, db_map)[source]

Returns a list of relationship class ids involving this item’s class.

default_parameter_data(self)[source]

Return data to put as default in a parameter table when this item is selected.

class spinetoolbox.mvcmodels.entity_tree_item.RelationshipItem(*args, **kwargs)[source]

Bases: spinetoolbox.mvcmodels.entity_tree_item.EntityItem

An object item.

Overridden method to parse some data for convenience later. Also make sure we never try to fetch this item.

visual_key = ['name', 'object_name_list'][source]
item_type = relationship[source]
object_name_list[source]
display_name[source]

“Returns the name for display.

display_icon[source]

Returns relationship class icon.

has_children(self)[source]

Returns false, this item never has children.

default_parameter_data(self)[source]

Return data to put as default in a parameter table when this item is selected.

_get_children_ids(self, db_map)[source]

See base class.