spinetoolbox.widgets.graph_view_mixin

Contains the GraphViewMixin class.

author:
  1. Marin (KTH)
date:

26.11.2018

Module Contents

class spinetoolbox.widgets.graph_view_mixin.GraphViewMixin(*args, **kwargs)[source]

Provides the graph view for the DS form.

graph_created[source]
_node_extent = 64[source]
_arc_width[source]
_arc_length_hint[source]
add_menu_actions(self)[source]

Adds toggle view actions to View menu.

connect_signals(self)[source]

Connects signals.

setup_zoom_widget_action(self)[source]

Setups zoom widget action in view menu.

init_models(self)[source]

Initializes models.

receive_object_classes_added(self, db_map_data)[source]
receive_object_classes_updated(self, db_map_data)[source]
receive_object_classes_removed(self, db_map_data)[source]
receive_relationship_classes_added(self, db_map_data)[source]
receive_relationship_classes_updated(self, db_map_data)[source]
receive_relationship_classes_removed(self, db_map_data)[source]
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 that self._added_objects doesn’t contain information regarding objects added from the graph itself (through Item Palette etc.). These are materialized in add_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 that self._added_relationships doesn’t contain information regarding relationships added from the graph itself (through Item Palette etc.). These are materialized in add_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.
_handle_zoom_minus_pressed(self)[source]

Performs a zoom out on the view.

_handle_zoom_plus_pressed(self)[source]

Performs a zoom in on the view.

_handle_zoom_reset_pressed(self)[source]

Resets the zoom on the view.

_handle_menu_graph_about_to_show(self)[source]

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.

_handle_entity_graph_visibility_changed(self, visible)[source]
_handle_item_palette_visibility_changed(self, visible)[source]
_handle_object_tree_selection_changed(self, selected, deselected)[source]

Builds graph.

build_graph(self, timeit=False)[source]

Builds the graph.

_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_new_items(scene, object_items, relationship_items, arc_items)[source]
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 sets(N)[source]

Returns sets of vertex pairs indices.

Parameters:N (int) –
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.

new_scene(self)[source]

Replaces the current scene with a new one.

tear_down_scene(self)[source]

Removes all references to this form in graphics items and schedules the scene for deletion.

extend_scene(self)[source]

Extends the scene to show all items.

_handle_scene_selection_changed(self)[source]

Filters parameters by selected objects in the graph.

_handle_scene_changed(self, region)[source]

Enlarges the scene rect if needed.

_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) –
show_graph_view_context_menu(self, global_pos)[source]

Shows context menu for graphics view.

Parameters:global_pos (QPoint) –
hide_selected_items(self, checked=False)[source]

Hides selected items.

show_hidden_items(self, checked=False)[source]

Shows hidden items.

prune_selected_items(self, checked=False)[source]

Prunes selected items.

restore_pruned_items(self, checked=False)[source]

Reinstates pruned items.

show_demo(self, checked=False)[source]
_enable_live_graph_demo_action(self, obj=None)[source]
show_object_item_context_menu(self, global_pos, main_item)[source]

Shows context menu for entity item.

Parameters:
show_relationship_item_context_menu(self, global_pos)[source]

Shows context menu for entity item.

Parameters:global_pos (QPoint) –
_apply_entity_context_menu_option(self, option)[source]
remove_graph_items(self, checked=False)[source]

Removes all selected items in the graph.

closeEvent(self, event=None)[source]

Handles close window event.

Parameters:event (QEvent) – Closing event if ‘X’ is clicked.