spinetoolbox.widgets.graph_view_graphics_items
¶
Classes for drawing graphics items on graph view’s QGraphicsScene.
authors: |
|
---|---|
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
-
shape
(self)[source]¶ Returns a shape containing the entire bounding rect, to work better with icon transparency.
-
add_arc_item
(self, arc_item)[source]¶ Adds an item to the list of arcs.
Parameters: arc_item (ArcItem) –
-
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
-
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) –
-
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) –
-
contextMenuEvent
(self, e)[source]¶ Shows context menu.
Parameters: e (QGraphicsSceneMouseEvent) – Mouse event
-
class
spinetoolbox.widgets.graph_view_graphics_items.
RelationshipItem
[source]¶ Bases:
spinetoolbox.widgets.graph_view_graphics_items.EntityItem
Relationship item to use with GraphViewForm.
-
validate_member_objects
(self)[source]¶ Goes through connected object items and tries to complete the relationship.
-
-
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-
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.
-
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) –
-
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
-
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.
-
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: - rel_item (spinetoolbox.widgets.graph_view_graphics_items.RelationshipItem) – relationship item
- obj_item (spinetoolbox.widgets.graph_view_graphics_items.ObjectItem) – object item
- width (float) – Preferred line width
-
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) –