spinetoolbox.widgets.graph_view_mixin
¶
Contains the GraphViewMixin class.
author: |
|
---|---|
date: | 26.11.2018 |
Module Contents¶
-
class
spinetoolbox.widgets.graph_view_mixin.
GraphViewMixin
(*args, **kwargs)[source]¶ Provides the graph view for the DS form.
Adds toggle view actions to View menu.
-
receive_objects_added
(self, db_map_data)[source]¶ Runs when objects are added to the db. Builds a lookup dictionary consumed by
add_object
. Also, adds the new objects to the graph if needed.Parameters: db_map_data (dict) – list of dictionary-items keyed by DiffDatabaseMapping instance.
-
_ensure_objects_in_graph
(self)[source]¶ Makes sure all objects in
self._added_objects
are materialized in the graph if corresponds. It is assumed thatself._added_objects
doesn’t contain information regarding objects added from the graph itself (through Item Palette etc.). These are materialized inadd_object()
.
-
receive_objects_updated
(self, db_map_data)[source]¶ Runs when objects are updated in the db. Refreshes names of objects in graph.
Parameters: db_map_data (dict) – list of dictionary-items keyed by DiffDatabaseMapping instance.
-
receive_objects_removed
(self, db_map_data)[source]¶ Runs when objects are removed from the db. Rebuilds graph if needed.
Parameters: db_map_data (dict) – list of dictionary-items keyed by DiffDatabaseMapping instance.
-
receive_relationships_added
(self, db_map_data)[source]¶ Runs when relationships are added to the db. Builds a lookup dictionary consumed by
add_relationship
. Also, adds the new relationships to the graph if needed.Parameters: db_map_data (dict) – list of dictionary-items keyed by DiffDatabaseMapping instance.
-
_ensure_relationships_in_graph
(self)[source]¶ Makes sure all relationships in
self._added_relationships
are materialized in the graph if corresponds. It is assumed thatself._added_relationships
doesn’t contain information regarding relationships added from the graph itself (through Item Palette etc.). These are materialized inadd_relationship()
.
-
receive_relationships_removed
(self, db_map_data)[source]¶ Runs when relationships are removed from the db. Rebuilds graph if needed.
Parameters: db_map_data (dict) – list of dictionary-items keyed by DiffDatabaseMapping instance.
-
restore_removed_entities
(self, added_ids)[source]¶ Restores any entities that have been previously removed and returns their ids. This happens in the context of undo/redo.
Parameters: added_ids (set(int)) – Set of newly added ids. Returns: set(int)
-
hide_removed_entities
(self, db_map_data)[source]¶ Hides removed entities while saving them into a list attribute. This allows entities to be restored in case the user undoes the operation.
-
refresh_icons
(self, db_map_data)[source]¶ Runs when entity classes are updated in the db. Refreshes icons of entities in graph.
Parameters: db_map_data (dict) – list of dictionary-items keyed by DiffDatabaseMapping instance.
-
_add_more_object_classes
(self, index)[source]¶ Runs when the user clicks on the Item palette Object class view. Opens the form to add more object classes if the index is the one that sayes ‘New…’.
Parameters: index (QModelIndex) – The clicked index.
-
_add_more_relationship_classes
(self, index)[source]¶ Runs when the user clicks on the Item palette Relationship class view. Opens the form to add more relationship classes if the index is the one that sayes ‘New…’.
Parameters: index (QModelIndex) – The clicked index.
Enables or disables actions according to current selection in the graph.
-
_handle_item_palette_dock_location_changed
(self, area)[source]¶ Runs when the item palette dock widget location changes. Adjusts splitter orientation accordingly.
-
_get_selected_object_ids
(self)[source]¶ Returns a set of ids corresponding to selected objects in the object tree.
Returns: set
-
_get_graph_data
(self)[source]¶ Returns data for making graph according to selection in Object tree.
Returns: integer object ids list: integer relationship ids list: arc source indices list: arc destination indices Return type: list
-
_get_new_items
(self)[source]¶ Returns new items for the graph.
Returns: ObjectItem instances list: RelationshipItem instances list: ArcItem instances Return type: list
-
_get_wip_items
(self)[source]¶ Removes wip items from the current scene and returns them.
Returns: ObjectItem instances list: RelationshipItem instances list: ArcItem instances Return type: list
-
static
_add_wip_items
(scene, new_object_items, wip_object_items, wip_relationship_items, wip_arc_items)[source]¶ Adds wip items to the given scene, merging wip object items with existing ones by entity id.
Parameters: - scene (QGraphicsScene) –
- new_object_items (list) –
- wip_object_items (list) –
- wip_relationship_items (list) –
- wip_arc_items (list) –
-
static
shortest_path_matrix
(N, src_inds, dst_inds, spread)[source]¶ Returns the shortest-path matrix.
Parameters: - N (int) – The number of nodes in the graph.
- src_inds (list) – Source indices
- dst_inds (list) – Destination indices
- spread (int) – The desired ‘distance’ between neighbours
-
static
vertex_coordinates
(matrix, heavy_positions=None, iterations=10, weight_exp=-2, initial_diameter=1000)[source]¶ Returns x and y coordinates for each vertex in the graph, computed using VSGD-MS.
-
tear_down_scene
(self)[source]¶ Removes all references to this form in graphics items and schedules the scene for deletion.
-
_handle_item_dropped
(self, pos, text)[source]¶ Runs when an item is dropped from Item palette onto the view. Creates the object or relationship template.
Parameters: - pos (QPoint) –
- text (str) –
-
add_wip_relationship
(self, scene, pos, relationship_class_id, center_item=None, center_dimension=None)[source]¶ Makes items for a wip relationship and adds them to the scene at the given coordinates.
Parameters: - scene (QGraphicsScene) –
- pos (QPointF) –
- relationship_class_id (int) –
- center_item_dimension (tuple, optional) – A tuple of (ObjectItem, dimension) to put at the center of the wip item.
-
add_object
(self, object_class_id, name)[source]¶ Adds object to the database.
Parameters: - object_class_id (int) –
- name (str) –
Returns: The id of the added object if successful, None otherwise.
Return type: int, NoneType
-
update_object
(self, object_id, name)[source]¶ Updates object in the db.
Parameters: - object_id (int) –
- name (str) –
-
add_relationship
(self, class_id, object_id_list, object_name_list)[source]¶ Adds relationship to the db.
Parameters: - class_id (int) –
- object_id_list (list) –
Shows context menu for graphics view.
Parameters: global_pos (QPoint) –
Shows hidden items.
Shows context menu for entity item.
Parameters: - global_pos (QPoint) –
- main_item (spinetoolbox.widgets.graph_view_graphics_items.ObjectItem) –
Shows context menu for entity item.
Parameters: global_pos (QPoint) –