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()

Class Hierarchy

Inheritance diagram of qgis.gui.QgsModelComponentGraphicItem

Base classes

QGraphicsObject

QObject

QGraphicsItem

Subclasses

QgsModelChildAlgorithmGraphicItem

A graphic item representing a child algorithm in the model designer.

QgsModelCommentGraphicItem

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

QgsModelGroupBoxGraphicItem

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

QgsModelOutputGraphicItem

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

QgsModelParameterGraphicItem

A graphic item representing a model parameter (input) in the model designer.

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

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.

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.

previewItemMove

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

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.

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.

Attributes

Hover

Normal

Selected

Unused

class qgis.gui.QgsModelComponentGraphicItem[source]

Bases: QGraphicsObject

__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

Bases: int

class Flags
class Flags(f: QgsModelComponentGraphicItem.Flags | QgsModelComponentGraphicItem.Flag)
class Flags(a0: QgsModelComponentGraphicItem.Flags)

Bases: object

Hover = 2
Normal = 0
Selected = 1
class State

Bases: int

Unused = 1
signal aboutToChange(text: str, id: int = 0)[source]

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:
  • text (str)

  • id (int = 0)

calculateAutomaticLinkPoint(self, other: QgsModelComponentGraphicItem | None)[source]

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

Parameters:

other (Optional[QgsModelComponentGraphicItem]) -> (QPointF) – 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 | QPoint)[source]

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)

  • point (Union[QPointF, QPoint]) -> (QPointF)

Returns:

  • calculated link point in item coordinates.

  • edge: item edge for calculated best link point

virtual canDeleteComponent(self) bool[source]

Returns True if the component can be deleted.

Return type:

bool

signal changed[source]

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

component(self) QgsProcessingModelComponent | None[source]

Returns the model component associated with this item.

Return type:

Optional[QgsProcessingModelComponent]

virtual deleteComponent(self)[source]

Called when the component should be deleted.

The default implementation does nothing.

virtual editComment(self)[source]

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

The default implementation does nothing.

virtual editComponent(self)[source]

Called when the component should be edited.

The default implementation does nothing.

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

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

Parameters:

state (QgsModelComponentGraphicItem.State)

Return type:

QColor

virtual flags(self) QgsModelComponentGraphicItem.Flags[source]

Returns item flags.

Return type:

QgsModelComponentGraphicItem.Flags

font(self) QFont[source]

Returns the font used to render text in the item.

See also

setFont()

Return type:

QFont

virtual iconPicture(self) QPicture[source]

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

Return type:

QPicture

virtual iconPixmap(self) QPixmap[source]

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

Return type:

QPixmap

itemRect(self, storedRect: bool = False) QRectF[source]

Returns the rectangle representing the body of the item.

Parameters:

storedRect (bool = False)

Return type:

QRectF

label(self) str[source]

Returns the item’s label text.

See also

setLabel()

Return type:

str

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

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[source]

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[source]

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[source]

Returns the model associated with this item.

Return type:

Optional[QgsProcessingModelAlgorithm]

moveComponentBy(self, dx: float, dy: float)[source]

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[source]

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]

previewItemMove(self, dx: float, dy: float)[source]

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

Parameters:
  • dx (float)

  • dy (float)

signal repaintArrows[source]

Emitted when item requests that all connected arrows are repainted.

signal requestModelRepaint[source]

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

setFont(self, font: QFont)[source]

Sets the font used to render text in the item.

See also

font()

Parameters:

font (QFont)

setItemRect(self, rect: QRectF)[source]

Sets a new scene rect for the item.

Parameters:

rect (QRectF)

setLabel(self, label: str | None)[source]

Returns the item’s label text.

See also

label()

Parameters:

label (Optional[str])

signal sizePositionChanged[source]

Emitted when the item’s size or position changes.

state(self) QgsModelComponentGraphicItem.State[source]

Returns the item’s current state.

Return type:

QgsModelComponentGraphicItem.State

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

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[source]

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[source]

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

Parameters:

state (QgsModelComponentGraphicItem.State)

Return type:

QColor

virtual titleAlignment(self) Qt.Alignment[source]

Returns the title alignment

Return type:

Qt.Alignment

truncatedTextForItem(self, text: str | None) str[source]

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[source]

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

updateButtonPositions(self)[source]

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

abstract updateStoredComponentPosition(self, pos: QPointF | QPoint, size: QSizeF)[source]

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

Parameters:
  • pos (Union[QPointF, QPoint])

  • size (QSizeF)

view(self) QgsModelGraphicsView | None[source]

Returns the associated view.

Return type:

Optional[QgsModelGraphicsView]