spinetoolbox.widgets.graph_view_graphics_items

Classes for drawing graphics items on graph view’s QGraphicsScene.

authors:
  1. Marin (KTH), P. Savolainen (VTT)
date:

4.4.2018

Module Contents

class spinetoolbox.widgets.graph_view_graphics_items.EntityItem(graph_view_form, x, y, extent, entity_id=None, entity_class_id=None)[source]

Bases: PySide2.QtWidgets.QGraphicsPixmapItem

Initializes item

Parameters:
  • graph_view_form (GraphViewForm) – ‘owner’
  • x (float) – x-coordinate of central point
  • y (float) – y-coordinate of central point
  • extent (int) – Preferred extent
  • entity_id (int, optional) – The entity id in case of a non-wip item
  • entity_class_id (int, optional) – The entity class id in case of a wip item
entity_type[source]
entity_name[source]
entity_class_type[source]
entity_class_id[source]
entity_class_name[source]
boundingRect(self)[source]
_init_bg(self)[source]
refresh_icon(self)[source]

Refreshes the icon.

shape(self)[source]

Returns a shape containing the entire bounding rect, to work better with icon transparency.

paint(self, painter, option, widget=None)[source]

Shows or hides the selection halo.

_paint_as_selected(self)[source]
_paint_as_deselected(self)[source]
add_arc_item(self, arc_item)[source]

Adds an item to the list of arcs.

Parameters:arc_item (ArcItem) –
become_wip(self)[source]

Turns this item into a work-in-progress.

_make_wip_tool_tip(self)[source]
become_whole(self)[source]

Removes the wip status from this item.

adjust_to_zoom(self, transform)[source]

Saves the view’s transform to determine collisions later on.

Parameters:transform (QTransform) – The view’s transformation matrix after the zoom.
device_rect(self)[source]

Returns the item’s rect in devices’s coordinates. Used to accurately determine collisions.

_find_merge_target(self)[source]

Returns a suitable merge target if any.

Returns:spinetoolbox.widgets.graph_view_graphics_items.EntityItem, NoneType
_is_target_valid(self)[source]

Whether or not the registered merge target is valid.

Returns:bool
merge_into_target(self, force=False)[source]

Merges this item into the registered target if valid.

Returns:True if merged, False if not.
Return type:bool
mousePressEvent(self, event)[source]

Saves original position for bouncing purposes.

Parameters:event (QGraphicsSceneMouseEvent) –
mouseMoveEvent(self, event)[source]

Moves the item and all connected arcs. Also checks for a merge target and sets an appropriate mouse cursor.

Parameters:event (QGraphicsSceneMouseEvent) –
move_arc_items(self, pos_diff)[source]

Moves arc items.

Parameters:pos_diff (QPoint) –
mouseReleaseEvent(self, event)[source]

Merges the item into the registered target if any. Bounces it if not possible. Shrinks the scene if needed.

Parameters:event (QGraphicsSceneMouseEvent) –
_bounce_back(self, current_pos)[source]

Bounces the item back from given position to its original position.

Parameters:current_pos (QPoint) –
itemChange(self, change, value)[source]

Keeps track of item’s movements on the scene.

Parameters:
  • change (GraphicsItemChange) – a flag signalling the type of the change
  • value – a value related to the change
Returns:

the same value given as input

set_all_visible(self, on)[source]

Sets visibility status for this item and all arc items.

Parameters:on (bool) –
wipe_out(self)[source]

Removes this item and all its arc items from the scene.

contextMenuEvent(self, e)[source]

Shows context menu.

Parameters:e (QGraphicsSceneMouseEvent) – Mouse event
_show_item_context_menu_in_parent(self, pos)[source]
class spinetoolbox.widgets.graph_view_graphics_items.RelationshipItem[source]

Bases: spinetoolbox.widgets.graph_view_graphics_items.EntityItem

Relationship item to use with GraphViewForm.

entity_type[source]
object_class_id_list[source]
object_name_list[source]
object_id_list[source]
db_representation[source]
_init_bg(self)[source]
validate_member_objects(self)[source]

Goes through connected object items and tries to complete the relationship.

move_arc_items(self, pos_diff)[source]

Moves arc items.

Parameters:pos_diff (QPoint) –
_make_wip_tool_tip(self)[source]
become_whole(self)[source]
_show_item_context_menu_in_parent(self, pos)[source]
class spinetoolbox.widgets.graph_view_graphics_items.ObjectItem(graph_view_form, x, y, extent, entity_id=None, entity_class_id=None)[source]

Bases: spinetoolbox.widgets.graph_view_graphics_items.EntityItem

Initializes the item.

Parameters:
  • graph_view_form (GraphViewForm) – ‘owner’
  • x (float) – x-coordinate of central point
  • y (float) – y-coordinate of central point
  • extent (int) – preferred extent
  • entity_id (int, optional) – object id, if not given the item becomes a template
  • entity_class_id (int, optional) – object class id, for template items
Raises:

ValueError – in case object_id and object_class_id are both not provided

entity_type[source]
db_representation[source]
refresh_name(self)[source]

Refreshes the name.

_paint_as_selected(self)[source]
_make_wip_tool_tip(self)[source]
become_whole(self)[source]
refresh_description(self)[source]
edit_name(self)[source]

Starts editing the object name.

finish_name_editing(self, text)[source]

Runs when the user finishes editing the name. Adds or updates the object in the database.

Parameters:text (str) – The new name.
move_arc_items(self, pos_diff)[source]

Moves arc items.

Parameters:pos_diff (QPoint) –
keyPressEvent(self, event)[source]

Starts editing the name if F2 is pressed.

Parameters:event (QKeyEvent) –
mouseDoubleClickEvent(self, event)[source]

Starts editing the name.

Parameters:event (QGraphicsSceneMouseEvent) –
_is_in_wip_relationship(self)[source]
_is_target_valid(self)[source]

Whether or not the registered merge target is valid.

Returns:bool
merge_into_target(self, force=False)[source]

Merges this item into the registered target if valid.

Parameters:force (bool) –
Returns:True if merged, False if not.
Return type:bool
_show_item_context_menu_in_parent(self, pos)[source]
class spinetoolbox.widgets.graph_view_graphics_items.EntityLabelItem(entity_item)[source]

Bases: PySide2.QtWidgets.QGraphicsTextItem

Label item for items in GraphViewForm.

Initializes item.

Parameters:entity_item (spinetoolbox.widgets.graph_view_graphics_items.EntityItem) – The parent item.
entity_name_edited[source]
setPlainText(self, text)[source]

Set texts and resets position.

Parameters:text (str) –
reset_position(self)[source]

Adapts item geometry so text is always centered.

set_bg_color(self, bg_color)[source]

Sets background color.

Parameters:bg_color (QColor) –
start_editing(self)[source]

Starts editing.

keyPressEvent(self, event)[source]

Keeps text centered as the user types. Gives up focus when the user presses Enter or Return.

Parameters:event (QKeyEvent) –
focusOutEvent(self, event)[source]

Ends editing and sends entity_name_edited signal.

mouseDoubleClickEvent(self, event)[source]

Starts editing the name.

Parameters:event (QGraphicsSceneMouseEvent) –
class spinetoolbox.widgets.graph_view_graphics_items.ArcItem(rel_item, obj_item, width, is_wip=False)[source]

Bases: PySide2.QtWidgets.QGraphicsLineItem

Arc item to use with GraphViewForm. Connects a RelationshipItem to an ObjectItem.

Initializes item.

Parameters:
mousePressEvent(self, event)[source]

Accepts the event so it’s not propagated.

other_item(self, item)[source]
become_wip(self)[source]

Turns this arc into a work-in-progress.

become_whole(self)[source]

Removes the wip status from this arc.

move_rel_item_by(self, pos_diff)[source]

Moves source point.

Parameters:pos_diff (QPoint) –
move_obj_item_by(self, pos_diff)[source]

Moves destination point.

Parameters:pos_diff (QPoint) –
adjust_to_zoom(self, transform)[source]

Adjusts the item’s geometry so it stays the same size after performing a zoom.

Parameters:transform (QTransform) – The view’s transformation matrix after the zoom.
wipe_out(self)[source]
class spinetoolbox.widgets.graph_view_graphics_items.OutlinedTextItem(text, parent, font=QFont(), brush=QBrush(Qt.white), outline_pen=QPen(Qt.black, 3, Qt.SolidLine))[source]

Bases: PySide2.QtWidgets.QGraphicsSimpleTextItem

Outlined text item.

Initializes item.

Parameters:
  • text (str) – text to show
  • font (QFont, optional) – font to display the text
  • brush (QBrush, optional) –
  • outline_pen (QPen, optional) –