graphics_items

Classes for drawing graphics items on QGraphicsScene.

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

4.4.2018

Module Contents

class graphics_items.ConnectorButton(parent, toolbox, position='left')[source]

Bases: PySide2.QtWidgets.QGraphicsRectItem

Connector button graphics item. Used for Link drawing between project items.

parent

Project item bg rectangle

Type:QGraphicsItem
toolbox

QMainWindow instance

Type:ToolBoxUI
position

Either “top”, “left”, “bottom”, or “right”

Type:str
parent_name(self)[source]

Returns project item name owning this connector button.

mousePressEvent(self, event)[source]

Connector button mouse press event. Starts drawing a link.

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

Connector button mouse double click event. Makes sure the LinkDrawer is hidden.

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

Sets a darker shade to connector button when mouse enters its boundaries.

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

Restore original brush when mouse leaves connector button boundaries.

Parameters:event (QGraphicsSceneMouseEvent) – Event
class graphics_items.ProjectItemIcon(toolbox, x, y, w, h, name)[source]

Bases: PySide2.QtWidgets.QGraphicsRectItem

Base class for Tool and View project item icons drawn in Design View.

toolbox

QMainWindow instance

Type:ToolBoxUI
x

Icon x coordinate

Type:int
y

Icon y coordinate

Type:int
w

Icon width

Type:int
h

Icon height

Type:int
name[source]

Item name

Type:str
setup(self, pen, brush, svg, svg_color)[source]

Setup item’s attributes according to project item type. Intended to be called in the constructor’s of classes that inherit from ItemImage class.

Parameters:
  • pen (QPen) – Used in drawing the background rectangle outline
  • brush (QBrush) – Used in filling the background rectangle
  • svg (str) – Path to SVG icon file
  • svg_color (QColor) – Color of SVG icon
name(self)[source]

Returns name of the item that is represented by this icon.

update_name_item(self, new_name)[source]

Set a new text to name item. Used when a project item is renamed.

set_name_attributes(self)[source]

Set name QGraphicsSimpleTextItem attributes (font, size, position, etc.)

conn_button(self, position='left')[source]

Returns items connector button (QWidget).

hoverEnterEvent(self, event)[source]

Sets a drop shadow effect to icon when mouse enters its boundaries.

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

Disables the drop shadow when mouse leaves icon boundaries.

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

Moves icon(s) while the mouse button is pressed. Update links that are connected to selected icons.

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

Show item context menu.

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

Handles deleting and rotating the selected item when dedicated keys are pressed.

Parameters:event (QKeyEvent) – Key event
itemChange(self, change, value)[source]

Destroys the drop shadow effect when the items is removed from a scene.

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

Whatever super() does with the value parameter

show_item_info(self)[source]

Update GUI to show the details of the selected item.

class graphics_items.DataConnectionIcon(toolbox, x, y, w, h, name)[source]

Bases: graphics_items.ProjectItemIcon

Data Connection icon for the Design View.

toolbox

QMainWindow instance

Type:ToolBoxUI
x

Icon x coordinate

Type:int
y

Icon y coordinate

Type:int
w

Width of master icon

Type:int
h

Height of master icon

Type:int
name

Item name

Type:str
dragEnterEvent(self, event)[source]

Drag and drop action enters. Accept file drops from the filesystem.

Parameters:event (QGraphicsSceneDragDropEvent) – Event
dragLeaveEvent(self, event)[source]

Drag and drop action leaves.

Parameters:event (QGraphicsSceneDragDropEvent) – Event
dragMoveEvent(self, event)[source]

Accept event.

dropEvent(self, event)[source]

Emit files_dropped_on_dc signal from scene, with this instance, and a list of files for each dropped url.

select_on_drag_over(self)[source]

Called when the timer started in drag_enter_event is elapsed. Select this item if the drag action is still over it.

class graphics_items.ToolIcon(toolbox, x, y, w, h, name)[source]

Bases: graphics_items.ProjectItemIcon

Tool image with a rectangular background, an SVG icon, a name label, and a connector button.

toolbox

QMainWindow instance

Type:ToolBoxUI
x

Icon x coordinate

Type:int
y

Icon y coordinate

Type:int
w

Width of master icon

Type:int
h

Height of master icon

Type:int
name

Item name

Type:str
value_for_time(self, msecs)[source]
start_animation(self)[source]

Start the animation that plays when the Tool associated to this GraphicsItem is running.

stop_animation(self)[source]

Stop animation

class graphics_items.DataStoreIcon(toolbox, x, y, w, h, name)[source]

Bases: graphics_items.ProjectItemIcon

Data Store item that is drawn into QGraphicsScene. NOTE: Make sure to set self._master as the parent of all drawn items. This groups the individual QGraphicsItems together.

toolbox

QMainWindow instance

Type:ToolBoxUI
x

Icon x coordinate

Type:int
y

Icon y coordinate

Type:int
w

Width of master icon

Type:int
h

Height of master icon

Type:int
name

Item name

Type:str
class graphics_items.ViewIcon(toolbox, x, y, w, h, name)[source]

Bases: graphics_items.ProjectItemIcon

View icon for the Design View

toolbox

QMainWindow instance

Type:ToolBoxUI
x

Icon x coordinate

Type:int
y

Icon y coordinate

Type:int
w

Width of background rectangle

Type:int
h

Height of background rectangle

Type:int
name

Item name

Type:str
class graphics_items.DataInterfaceIcon(toolbox, x, y, w, h, name)[source]

Bases: graphics_items.ProjectItemIcon

Data Interface item that is drawn into QGraphicsScene. NOTE: Make sure to set self._master as the parent of all drawn items. This groups the individual QGraphicsItems together.

toolbox

QMainWindow instance

Type:ToolBoxUI
x

Icon x coordinate

Type:int
y

Icon y coordinate

Type:int
w

Width of master icon

Type:int
h

Height of master icon

Type:int
name

Item name

Type:str

Bases: PySide2.QtWidgets.QGraphicsPathItem

An item that represents a connection between project items.

toolbox

main UI class instance

Type:ToolboxUI
src_connector

Source connector button

Type:ConnectorButton
dst_connector

Destination connector button

Type:ConnectorButton
find_model_index(self)[source]

Find model index from connection model.

Find parallel link.

send_to_bottom(self)[source]

Send link behind other links.

mousePressEvent(self, e)[source]

Trigger slot button if it is underneath.

Parameters:e (QGraphicsSceneMouseEvent) – Mouse event
mouseDoubleClickEvent(self, e)[source]

Accept event to prevent unwanted feedback links to be created when propagating this event to connector buttons underneath.

contextMenuEvent(self, e)[source]

Show context menu unless mouse is over one of the slot buttons.

Parameters:e (QGraphicsSceneMouseEvent) – Mouse event
keyPressEvent(self, event)[source]

Remove associated connection if this is selected and delete is pressed.

update_geometry(self)[source]

Update path.

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

Set pen according to selection state.

itemChange(self, change, value)[source]

Bring selected link to top.

class graphics_items.LinkDrawer[source]

Bases: PySide2.QtWidgets.QGraphicsPathItem

An item that allows one to draw links between slot buttons in QGraphicsView.

start_drawing_at(self, src_rect)[source]

Start drawing from the center point of the clicked button.

Parameters:src_rect (QRecF) – Rectangle of the clicked button
update_geometry(self)[source]

Update path.

class graphics_items.ObjectItem(graph_view_form, object_name, object_class_id, object_class_name, x, y, extent, object_id=0, label_color=Qt.transparent)[source]

Bases: PySide2.QtWidgets.QGraphicsPixmapItem

Object item to use with GraphViewForm.

graph_view_form

‘owner’

Type:GraphViewForm
object_name

object name

Type:str
object_class_id

object class id

Type:int
object_class_name

object class name

Type:str
x

x-coordinate of central point

Type:float
y

y-coordinate of central point

Type:float
extent

preferred extent

Type:int
object_id

object id (for filtering parameters)

Type:int
label_font

label font

Type:QFont
label_color

label bg color

Type:QColor
shape(self)[source]

Make the entire bounding rect to be the shape.

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

Try and make it more clear when an item is selected.

make_template(self)[source]

Make this object par of a template for a relationship.

remove_template(self)[source]

Make this arc no longer a template.

edit_name(self)[source]

Start editing object name.

finish_name_editing(self)[source]

Called by the label item when editing finishes.

add_incoming_arc_item(self, arc_item)[source]

Add an ArcItem to the list of incoming arcs.

add_outgoing_arc_item(self, arc_item)[source]

Add an ArcItem to the list of outgoing arcs.

keyPressEvent(self, event)[source]

Triggers name editing.

mouseDoubleClickEvent(self, event)[source]

Triggers name editing.

mousePressEvent(self, event)[source]

Saves original position.

mouseMoveEvent(self, event)[source]

Calls move related items and checks for a merge target.

mouseReleaseEvent(self, event)[source]

Merge, bounce, or just do nothing.

check_for_merge_target(self, scene_pos)[source]

Checks if this item is touching another item so they can merge (this happens when building a relationship).

merge_item(self, other)[source]

Merges this item with another. Tries to create a relationship if needed.

add_into_relationship(self)[source]

Try and add this item into a relationship between the buddies.

Moves related items.

contextMenuEvent(self, e)[source]

Shows context menu.

Parameters:e (QGraphicsSceneMouseEvent) – Mouse event
set_all_visible(self, on)[source]

Sets visibility status for this item and all related items.

wipe_out(self)[source]

Removes this item and all related items from the scene.

class graphics_items.ArcItem(graph_view_form, relationship_class_id, src_item, dst_item, width, arc_color, object_id_list='', token_color=QColor(), token_object_extent=0, token_object_label_color=QColor(), token_object_name_tuple_list=())[source]

Bases: PySide2.QtWidgets.QGraphicsLineItem

Arc item to use with GraphViewForm.

graph_view_form

‘owner’

Type:GraphViewForm
relationship_class_id

relationship class id

Type:int
src_item

source item

Type:ObjectItem
dst_item

destination item

Type:ObjectItem
width

Preferred line width

Type:int
arc_color

arc color

Type:QColor
object_id_list

object id comma separated list

Type:str
token_object_extent

token preferred extent

Type:int
token_color

token bg color

Type:QColor
token_object_name_tuple_list

token (object class name, object name) tuple list

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

Try and make it more clear when an item is selected.

make_template(self)[source]

Make this arc part of a template for a relationship.

remove_template(self)[source]

Make this arc no longer part of a template for a relationship.

move_src_by(self, pos_diff)[source]

Move source point by pos_diff. Used when moving ObjectItems around.

move_dst_by(self, pos_diff)[source]

Move destination point by pos_diff. Used when moving ObjectItems around.

hoverEnterEvent(self, event)[source]

Set viewport’s cursor to arrow.

hoverLeaveEvent(self, event)[source]

Restore viewport’s cursor.

class graphics_items.ObjectLabelItem(object_item, text, width, bg_color)[source]

Bases: PySide2.QtWidgets.QGraphicsTextItem

Object label item to use with GraphViewForm.

object_item

the ObjectItem instance

Type:ObjectItem
text

text

Type:str
width

maximum width

Type:int
bg_color

color to paint the label

Type:QColor
set_bg_color(self, bg_color)[source]

Set background color.

set_full_text(self)[source]
set_text(self, text)[source]

Store real text, and then try and fit it as best as possible in the width (reduce font point size, elide text…)

keyPressEvent(self, event)[source]

Give up focus when the user presses Enter or Return. In the meantime, adapt item geometry so text is always centered.

focusOutEvent(self, event)[source]

Call method to finish name editing in object item.

class graphics_items.ArcTokenItem(arc_item, color, object_extent, object_label_color, *object_name_tuples)[source]

Bases: PySide2.QtWidgets.QGraphicsEllipseItem

Arc token item to use with GraphViewForm.

arc_item

the ArcItem instance

Type:ArcItem
color

color to paint the token

Type:QColor
object_extent

Preferred extent

Type:int
object_label_color

Preferred extent

Type:QColor
object_name_tuples

one or more (object class name, object name) tuples

Type:Iterable
update_pos(self)[source]

Put token item in position.

class graphics_items.SimpleObjectItem(parent, extent, label_color, object_class_name, object_name)[source]

Bases: PySide2.QtWidgets.QGraphicsPixmapItem

Object item to use with GraphViewForm.

parent

arc token item

Type:ArcTokenItem
extent

preferred extent

Type:int
label_color

label bg color

Type:QColor
object_class_name

object class name

Type:str
object_name

object name

Type:str
setOffset(self, offset)[source]
class graphics_items.OutlinedTextItem(text, font, brush=QBrush(Qt.black), outline_pen=QPen(Qt.white, 3, Qt.SolidLine))[source]

Bases: PySide2.QtWidgets.QGraphicsSimpleTextItem

Outlined text item to use with GraphViewForm.

text

text to show

Type:str
font

font to display the text

Type:QFont
brush
Type:QBrus
outline_pen
Type:QPen
class graphics_items.CustomTextItem(html, font)[source]

Bases: PySide2.QtWidgets.QGraphicsTextItem

Custom text item to use with GraphViewForm.

html

text to show

Type:str
font

font to display the text

Type:QFont