Class: QgsModelComponentGraphicItem

Base class for graphic items representing model components in the model designer.

Warning

Not stable API

Added in version 3.14.

Note

This is an abstract class, with methods which must be implemented by a subclass.

The following methods must be implemented: fillColor(), strokeColor(), textColor(), updateStoredComponentPosition()

List of all members, including inherited members

Class Hierarchy

Inheritance diagram of qgis.gui.QgsModelComponentGraphicItem

Base classes

QGraphicsObject

QObject

QGraphicsItem

QgsProcessingWidgetContextGenerator

An interface for objects which can create Processing widget contexts.

Subclasses

QgsModelGroupBoxGraphicItem

A graphic item representing a group box in the model designer.

QgsModelOutputGraphicItem

A graphic item representing a model output in the model designer.

Constructor

__init__

Enums

Flag

State

Abstract Methods

fillColor

Returns the fill color for the item for the specified state.

strokeColor

Returns the stroke color for the item for the specified state.

textColor

Returns the label text color for the item for the specified state.

updateStoredComponentPosition

Updates the position and size stored in the model for the associated comment

Methods

Flags

calculateAutomaticLinkPoint

Returns the best link point to use for a link originating at a specified other item.

component

Returns the model component associated with this item.

font

Returns the font used to render text in the item.

incomingArrows

Returns the list of incoming arrow items terminating at this item.

itemRect

Returns the rectangle representing the body of the item.

label

Returns the item's label text.

linkPoint

Returns the location of the link point with the specified index on the specified edge.

model

Returns the model associated with this item.

moveComponentBy

Moves the component by the specified dx and dy.

outSocketAt

Returns the output socket graphics items at the specified index.

outgoingArrows

Returns the list of outgoing arrow items originating at this item.

paintOutline

Paints the outline part of the graphic item.

previewItemMove

Shows a preview of moving the item from its stored position by dx, dy.

registerWidgetContextGenerator

Register a Processing widget context generator class that will be used to retrieve a widget context for the item when required.

setFont

Sets the font used to render text in the item.

setItemRect

Sets a new scene rect for the item.

setLabel

Returns the item's label text.

state

Returns the item's current state.

truncatedTextForItem

Truncates a text string so that it fits nicely within the item's width, accounting for margins and interactive buttons.

updateButtonPositions

Updates the item's button positions, based on the current item rect.

view

Returns the associated view.

Virtual Methods

In PyQGIS, only methods marked as virtual can be safely overridden in a Python subclass of QgsModelComponentGraphicItem. See the FAQ for more details.

canDeleteComponent

Returns True if the component can be deleted.

deleteComponent

Called when the component should be deleted.

editComment

Called when the comment attached to the item should be edited.

editComponent

Called when the component should be edited.

flags

Returns item flags.

iconPicture

Returns a QPicture version of the item's icon, if available.

iconPixmap

Returns a QPixmap version of the item's icon, if available.

linkPointCount

Returns the number of link points associated with the component on the specified edge.

linkPointText

Returns the text to use for the link point with the specified index on the specified edge.

outlineColor

Returns the optional color for an outline effect around the item.

paintBackground

Paints the background part of the graphic item.

strokeStyle

Returns the stroke style to use while rendering the outline of the item.

titleAlignment

Returns the title alignment

Signals

aboutToChange

Emitted when the definition of the associated component is about to be changed by the item.

changed

Emitted when the definition of the associated component is changed by the item.

repaintArrows

Emitted when item requests that all connected arrows are repainted.

requestModelRepaint

Emitted by the item to request a repaint of the parent model scene.

sizePositionChanged

Emitted when the item's size or position changes.

updateArrowPaths

Emitted when item requires that all connected arrow paths are recalculated.

class qgis.gui.QgsModelComponentGraphicItem

Bases: QGraphicsObject, QgsProcessingWidgetContextGenerator

__init__(component: QgsProcessingModelComponent | None, model: QgsProcessingModelAlgorithm | None, parent: QGraphicsItem | None)

Constructor for QgsModelComponentGraphicItem for the specified component, with the specified parent item.

The model argument specifies the associated processing model. Ownership of model is not transferred, and it must exist for the lifetime of this object.

Ownership of component is transferred to the item.

Parameters:
class Flag(*values)

Bases: IntEnum

Unused = 1
Flags()
Hover = 2
Normal = 0
Selected = 1
class State(*values)

Bases: IntEnum

Hover = 2
Normal = 0
Selected = 1
Unused = 1
signal aboutToChange(text: str, id: str | None = None)

Emitted when the definition of the associated component is about to be changed by the item.

The text argument gives the translated text describing the change about to occur, and the optional id can be used to group the associated undo commands.

Parameters:
calculateAutomaticLinkPoint(self, other: QgsModelComponentGraphicItem | None)

Returns the best link point to use for a link originating at a specified other item.

Parameters:

other (Optional[QgsModelComponentGraphicItem]) – item at other end of link

Returns:

  • calculated link point in item coordinates.

  • edge: item edge for calculated best link point

calculateAutomaticLinkPoint(self, point: QPointF) -> (QPointF, Qt.Edge) Returns the best link point to use for a link originating at a specified other point.

Parameters:

other – point for other end of link (in scene coordinates)

Return type:

(QPointF, Qt.Edge)

Returns:

  • calculated link point in item coordinates.

  • edge: item edge for calculated best link point

virtual canDeleteComponent(self) bool

Returns True if the component can be deleted.

Return type:

bool

signal changed

Emitted when the definition of the associated component is changed by the item.

component(self) QgsProcessingModelComponent | None

Returns the model component associated with this item.

Return type:

Optional[QgsProcessingModelComponent]

virtual deleteComponent(self)

Called when the component should be deleted.

The default implementation does nothing.

virtual editComment(self)

Called when the comment attached to the item should be edited.

The default implementation does nothing.

virtual editComponent(self)

Called when the component should be edited.

The default implementation does nothing.

abstract fillColor(self, state: QgsModelComponentGraphicItem.State) QColor

Returns the fill color for the item for the specified state.

Parameters:

state (QgsModelComponentGraphicItem.State)

Return type:

QColor

virtual flags(self) QgsModelComponentGraphicItem.Flag

Returns item flags.

Return type:

QgsModelComponentGraphicItem.Flag

font(self) QFont

Returns the font used to render text in the item.

See also

setFont()

Return type:

QFont

virtual iconPicture(self) QPicture

Returns a QPicture version of the item’s icon, if available.

Return type:

QPicture

virtual iconPixmap(self) QPixmap

Returns a QPixmap version of the item’s icon, if available.

Return type:

QPixmap

incomingArrows(self) list[QgsModelArrowItem]

Returns the list of incoming arrow items terminating at this item.

See also

outgoingArrows()

Added in version 4.2.

Return type:

list[QgsModelArrowItem]

itemRect(self, storedRect: bool = False) QRectF

Returns the rectangle representing the body of the item.

Parameters:

storedRect (bool = False)

Return type:

QRectF

label(self) str

Returns the item’s label text.

See also

setLabel()

Return type:

str

linkPoint(self, edge: Qt.Edge, index: int, incoming: bool) QPointF

Returns the location of the link point with the specified index on the specified edge.

Parameters:
  • edge (Qt.Edge)

  • index (int)

  • incoming (bool)

Return type:

QPointF

virtual linkPointCount(self, edge: Qt.Edge) int

Returns the number of link points associated with the component on the specified edge.

Parameters:

edge (Qt.Edge)

Return type:

int

virtual linkPointText(self, edge: Qt.Edge, index: int) str

Returns the text to use for the link point with the specified index on the specified edge.

Parameters:
  • edge (Qt.Edge)

  • index (int)

Return type:

str

model(self) QgsProcessingModelAlgorithm | None

Returns the model associated with this item.

Return type:

Optional[QgsProcessingModelAlgorithm]

moveComponentBy(self, dx: float, dy: float)

Moves the component by the specified dx and dy.

Warning

Call this method, not QGraphicsItem.moveBy!

Parameters:
  • dx (float)

  • dy (float)

outSocketAt(self, index: int) QgsModelDesignerSocketGraphicItem | None

Returns the output socket graphics items at the specified index.

May return None if no corresponding output socket exists.

Added in version 3.44.

Parameters:

index (int)

Return type:

Optional[QgsModelDesignerSocketGraphicItem]

outgoingArrows(self) list[QgsModelArrowItem]

Returns the list of outgoing arrow items originating at this item.

See also

incomingArrows()

Added in version 4.2.

Return type:

list[QgsModelArrowItem]

virtual outlineColor(self) QColor

Returns the optional color for an outline effect around the item.

Returns an invalid color if the outline effect is not required.

Return type:

QColor

virtual paintBackground(self, painter: QPainter | None, option: QStyleOptionGraphicsItem | None, widget: QWidget | None = None)

Paints the background part of the graphic item.

Subclasses may override this to customize the background appearance.

Parameters:
paintOutline(self, painter: QPainter | None, option: QStyleOptionGraphicsItem | None, widget: QWidget | None = None)

Paints the outline part of the graphic item.

Parameters:
previewItemMove(self, dx: float, dy: float)

Shows a preview of moving the item from its stored position by dx, dy.

Parameters:
  • dx (float)

  • dy (float)

registerWidgetContextGenerator(self, generator: QgsProcessingWidgetContextGenerator | None)

Register a Processing widget context generator class that will be used to retrieve a widget context for the item when required.

Added in version 4.4.

Parameters:

generator (Optional[QgsProcessingWidgetContextGenerator])

signal repaintArrows

Emitted when item requests that all connected arrows are repainted.

signal requestModelRepaint

Emitted by the item to request a repaint of the parent model scene.

setFont(self, font: QFont)

Sets the font used to render text in the item.

See also

font()

Parameters:

font (QFont)

setItemRect(self, rect: QRectF)

Sets a new scene rect for the item.

Parameters:

rect (QRectF)

setLabel(self, label: str | None)

Returns the item’s label text.

See also

label()

Parameters:

label (Optional[str])

signal sizePositionChanged

Emitted when the item’s size or position changes.

state(self) QgsModelComponentGraphicItem.State

Returns the item’s current state.

Return type:

QgsModelComponentGraphicItem.State

abstract strokeColor(self, state: QgsModelComponentGraphicItem.State) QColor

Returns the stroke color for the item for the specified state.

Parameters:

state (QgsModelComponentGraphicItem.State)

Return type:

QColor

virtual strokeStyle(self, state: QgsModelComponentGraphicItem.State) Qt.PenStyle

Returns the stroke style to use while rendering the outline of the item.

Parameters:

state (QgsModelComponentGraphicItem.State)

Return type:

Qt.PenStyle

abstract textColor(self, state: QgsModelComponentGraphicItem.State) QColor

Returns the label text color for the item for the specified state.

Parameters:

state (QgsModelComponentGraphicItem.State)

Return type:

QColor

virtual titleAlignment(self) Qt.AlignmentFlag

Returns the title alignment

Return type:

Qt.AlignmentFlag

truncatedTextForItem(self, text: str | None) str

Truncates a text string so that it fits nicely within the item’s width, accounting for margins and interactive buttons.

Parameters:

text (Optional[str])

Return type:

str

signal updateArrowPaths

Emitted when item requires that all connected arrow paths are recalculated.

updateButtonPositions(self)

Updates the item’s button positions, based on the current item rect.

abstract updateStoredComponentPosition(self, pos: QPointF, size: QSizeF)

Updates the position and size stored in the model for the associated comment

Parameters:
  • pos (QPointF)

  • size (QSizeF)

view(self) QgsModelGraphicsView | None

Returns the associated view.

Return type:

Optional[QgsModelGraphicsView]