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¶
Base classes¶
Base class for graphical items within a |
|
A base class for objects which belong to a layout. |
|
Abstract interface for generating an expression context. |
|
Interface for layout objects which support undo/redo commands. |
Subclasses¶
Layout item for node based polygon shapes. |
|
Layout item for node based polyline shapes. |
Abstract Methods
Must be reimplemented in subclasses. |
Methods
Add a node in current shape. |
|
Compute an euclidean distance between 2 nodes. |
|
Deselects any selected nodes. |
|
Moves a node to a new position. |
|
Search for the nearest node in the shape within a maximal area. |
|
Gets the position of a node in scene coordinates. |
|
Returns the nodes the shape consists of. |
|
Returns the number of nodes in the shape. |
|
Remove a node with specified index from the shape. |
|
Rescale the current shape according to the item's bounding box. |
|
Returns the currently selected node, or -1 if no node is selected. |
|
Set whether the item's nodes should be displayed. |
|
Sets the nodes the shape consists of. |
|
Selects a node by index. |
|
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.
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 specifiedlayout
.- 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 isTrue
, 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
- 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
- Return type:
QPolygonF
- 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
- Parameters:
nodes (QPolygonF)
- setSelectedNode(self, index: int) bool [source]¶
Selects a node by
index
.- Parameters:
index (int)
- Return type:
bool