Class: QgsLayoutNodesItem

An abstract layout item that provides generic methods for node based shapes such as polygon or polylines.

Note

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

The following methods must be implemented: _addNode(), _draw(), _readXmlStyle(), _removeNode(), _writeXmlStyle(), isValid()

Class Hierarchy

Inheritance diagram of qgis.core.QgsLayoutNodesItem

Base classes

QgsLayoutItem

Base class for graphical items within a QgsLayout.

QgsLayoutObject

A base class for objects which belong to a layout.

QObject

QgsExpressionContextGenerator

Abstract interface for generating an expression context.

QGraphicsRectItem

QAbstractGraphicsShapeItem

QGraphicsItem

QgsLayoutUndoObjectInterface

Interface for layout objects which support undo/redo commands.

Subclasses

QgsLayoutItemPolygon

Layout item for node based polygon shapes.

QgsLayoutItemPolyline

Layout item for node based polyline shapes.

Abstract Methods

isValid

Must be reimplemented in subclasses.

Methods

addNode

Add a node in current shape.

computeDistance

Compute an euclidean distance between 2 nodes.

deselectNode

Deselects any selected nodes.

moveNode

Moves a node to a new position.

nodeAtPosition

Search for the nearest node in the shape within a maximal area.

nodePosition

Gets the position of a node in scene coordinates.

nodes

Returns the nodes the shape consists of.

nodesSize

Returns the number of nodes in the shape.

removeNode

Remove a node with specified index from the shape.

rescaleToFitBoundingBox

Rescale the current shape according to the item's bounding box.

selectedNode

Returns the currently selected node, or -1 if no node is selected.

setDisplayNodes

Set whether the item's nodes should be displayed.

setNodes

Sets the nodes the shape consists of.

setSelectedNode

Selects a node by index.

updateSceneRect

Update the current scene rectangle for this item.

Virtual Methods

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

updateBoundingRect

Called when the bounding rect of the item should recalculated.

class qgis.core.QgsLayoutNodesItem[source]

Bases: QgsLayoutItem

__init__(layout: QgsLayout | None)

Constructor for QgsLayoutNodesItem, attached to the specified layout.

Parameters:

layout (Optional[QgsLayout])

__init__(polygon: QPolygonF, layout: QgsLayout | None)

Constructor for a QgsLayoutNodesItem with the given polygon nodes, attached to the specified layout.

Parameters:
  • polygon (QPolygonF)

  • layout (Optional[QgsLayout])

addNode(self, point: QPointF | QPoint, checkArea: bool = True, radius: float = 10) bool[source]

Add a node in current shape.

Parameters:
  • point (Union[QPointF, QPoint]) – is the location of the new node (in scene coordinates)

  • checkArea (bool = True) – is a flag to indicate if there’s a space constraint.

  • radius (float = 10) – is the space constraint and is used only if checkArea is True. Typically, if this flag is True, the new node has to be nearer than radius to the shape to be added.

Return type:

bool

computeDistance(self, pt1: QPointF | QPoint, pt2: QPointF | QPoint) float[source]

Compute an euclidean distance between 2 nodes.

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

  • pt2 (Union[QPointF, QPoint])

Return type:

float

deselectNode(self)[source]

Deselects any selected nodes.

abstract isValid(self) bool[source]

Must be reimplemented in subclasses. Typically a polyline is valid if it has at least 2 distinct nodes, while a polygon is valid if it has at least 3 distinct nodes.

Added in version 3.40.

Return type:

bool

moveNode(self, index: int, node: QPointF | QPoint) bool[source]

Moves a node to a new position.

Parameters:
  • index (int) – the index of the node to move

  • node (Union[QPointF, QPoint]) – is the new position in scene coordinate

Return type:

bool

nodeAtPosition(self, point: QPointF | QPoint, searchInRadius: bool = True, radius: float = 10) int[source]

Search for the nearest node in the shape within a maximal area. Returns the index of the nearest node or -1 if no node was found.

Parameters:
  • point (Union[QPointF, QPoint]) – is the location to search for nodes from (in scene coordinates)

  • searchInRadius (bool = True) – is a flag to indicate if the area of research is limited in space.

  • radius (float = 10) – is only used if searchInRadius is True

Return type:

int

nodePosition(self, index: int, position: QPointF | QPoint) bool[source]

Gets the position of a node in scene coordinates.

Parameters:
  • index (int) – of the node

  • position (Union[QPointF, QPoint]) – the position of the node

Return type:

bool

Returns:

True if the index is valid and the position is set, False otherwise

nodes(self) QPolygonF[source]

Returns the nodes the shape consists of.

See also

setNodes()

Return type:

QPolygonF

nodesSize(self) int[source]

Returns the number of nodes in the shape.

Return type:

int

removeNode(self, index: int) bool[source]

Remove a node with specified index from the shape.

Parameters:

index (int)

Return type:

bool

rescaleToFitBoundingBox(self)[source]

Rescale the current shape according to the item’s bounding box. Useful when the shape is resized thanks to the rubber band.

selectedNode(self) int[source]

Returns the currently selected node, or -1 if no node is selected.

Return type:

int

setDisplayNodes(self, display: bool = True)[source]

Set whether the item’s nodes should be displayed.

Parameters:

display (bool = True)

setNodes(self, nodes: QPolygonF)[source]

Sets the nodes the shape consists of.

See also

nodes()

Parameters:

nodes (QPolygonF)

setSelectedNode(self, index: int) bool[source]

Selects a node by index.

Parameters:

index (int)

Return type:

bool

virtual updateBoundingRect(self)[source]

Called when the bounding rect of the item should recalculated. Subclasses should update currentRectangle in their implementations.

updateSceneRect(self)[source]

Update the current scene rectangle for this item.