spinetoolbox.spine_db_editor.mvcmodels.multi_db_tree_item¶
Base classes to represent items from multiple databases in a tree.
| authors: |
|
|---|---|
| date: | 17.6.2020 |
Module Contents¶
Classes¶
MultiDBTreeItem |
A tree item that may belong in multiple databases. |
-
class
spinetoolbox.spine_db_editor.mvcmodels.multi_db_tree_item.MultiDBTreeItem(model=None, db_map_id=None)[source]¶ Bases:
spinetoolbox.mvcmodels.minimal_tree_model.TreeItemA 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
-
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_icon[source]¶ Returns an icon to display next to the name. Reimplement in subclasses to return something nice.
-
_deep_refresh_children(self)[source]¶ Refreshes children after taking db_maps from them. Called after removing and updating children for this item.
-
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]¶ Removes given db_map from this item and all its descendants, and returns a new item from the db_map’s data.
Returns: MultiDBTreeItem, NoneType
-
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.
-
_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.
-
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.