Class: QgsLayoutNodesItem¶
- class qgis.core.QgsLayoutNodesItem¶
Bases:
QgsLayoutItem
An abstract layout item that provides generic methods for node based shapes such as polygon or polylines.
New in version 3.0.
QgsLayoutNodesItem(layout:
QgsLayout
) Constructor forQgsLayoutNodesItem
, attached to the specifiedlayout
.QgsLayoutNodesItem(polygon: QPolygonF, layout:
QgsLayout
) Constructor for aQgsLayoutNodesItem
with the givenpolygon
nodes, attached to the specifiedlayout
.Methods
Add a node in current shape.
Adjusts the specified
point
at which areference
position of the item sits and returns the top left corner of the item, if reference point were placed at the specified position.Applies any present data defined size overrides to the specified layout
size
.Applies any item-specific size constraint handling to a given
targetSize
in layout units.- rtype:
QRectF
Compute an euclidean distance between 2 nodes.
Deselects any selected nodes.
- param context:
Draws the background for the item.
Draws a debugging rectangle of the item's current bounds within the specified painter.
Draws the frame around the item.
Draws a "refreshing" overlay icon on the item.
- rtype:
float
Returns the path to use when drawing the item's frame or background.
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.
Returns the current position (in layout units) of a
reference
point for the item.Sets object properties from a DOM element
- param element:
Refresh item's background color, considering data defined colors.
Refresh item's blend mode, considering data defined blend mode.
Refresh item's frame, considering data defined colors and frame size.
Refreshes an item's position by rechecking it against any possible overrides such as data defined positioning.
Refreshes an item's rotation by rechecking it against any possible overrides such as data defined rotation.
Refreshes an item's size by rechecking it against any possible item fixed or minimum sizes.
Refresh item's opacity, considering data defined opacity.
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 a fixed
size
for the layout item, which prevents it from being freely resized.Sets the minimum allowed
size
for the layout item.Sets the
nodes
the shape consists of.Selects a node by
index
.Returns the position for the reference point of the item, if the top-left of the item was placed at the specified
point
.Called when the bounding rect of the item should recalculated.
Update the current scene rectangle for this item.
Stores object properties within an XML DOM element.
- param element:
- addNode(self, point: QPointF | QPoint, checkArea: bool = True, radius: float = 10) bool ¶
Add a node in current shape.
- Parameters:
point (Union[QPointF) – 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 contraint 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
- adjustPointForReferencePosition(self, point: QPointF | QPoint, size: QSizeF, reference: QgsLayoutItem.ReferencePoint) QPointF ¶
Adjusts the specified
point
at which areference
position of the item sits and returns the top left corner of the item, if reference point were placed at the specified position.
- applyDataDefinedSize(self, size: QgsLayoutSize) QgsLayoutSize ¶
Applies any present data defined size overrides to the specified layout
size
.
- applyItemSizeConstraint(self, targetSize: QSizeF) QSizeF ¶
Applies any item-specific size constraint handling to a given
targetSize
in layout units. Subclasses can override this method if they need to apply advanced logic regarding item sizes, which cannot be covered bysetFixedSize()
orsetMinimumSize()
. Item size constraints are applied after fixed, minimum and data defined size constraints.See also
See also
- boundingRect(self) QRectF ¶
- Return type:
QRectF
- childEvent(self, QChildEvent)¶
- computeDistance(self, pt1: QPointF | QPoint, pt2: QPointF | QPoint) float ¶
Compute an euclidean distance between 2 nodes.
- Parameters:
pt1 (Union[QPointF) –
pt2 (Union[QPointF) –
- Return type:
float
- connectNotify(self, QMetaMethod)¶
- contextMenuEvent(self, QGraphicsSceneContextMenuEvent)¶
- customEvent(self, QEvent)¶
- deselectNode(self)¶
Deselects any selected nodes.
- disconnectNotify(self, QMetaMethod)¶
- dragEnterEvent(self, QGraphicsSceneDragDropEvent)¶
- dragLeaveEvent(self, QGraphicsSceneDragDropEvent)¶
- dragMoveEvent(self, QGraphicsSceneDragDropEvent)¶
- draw(self, context: QgsLayoutItemRenderContext)¶
- Parameters:
context (QgsLayoutItemRenderContext) –
- drawBackground(self, context: QgsRenderContext)¶
Draws the background for the item.
See also
- drawDebugRect(self, painter: QPainter)¶
Draws a debugging rectangle of the item’s current bounds within the specified painter.
- Parameters:
painter – destination QPainter
- drawFrame(self, context: QgsRenderContext)¶
Draws the frame around the item.
See also
- drawRefreshingOverlay(self, painter: QPainter, itemStyle: QStyleOptionGraphicsItem)¶
Draws a “refreshing” overlay icon on the item.
New in version 3.32.
- dropEvent(self, QGraphicsSceneDragDropEvent)¶
- estimatedFrameBleed(self) float ¶
- Return type:
float
- focusInEvent(self, QFocusEvent)¶
- focusOutEvent(self, QFocusEvent)¶
- framePath(self) QPainterPath ¶
Returns the path to use when drawing the item’s frame or background.
See also
See also
New in version 3.16.
- hoverEnterEvent(self, QGraphicsSceneHoverEvent)¶
- hoverLeaveEvent(self, QGraphicsSceneHoverEvent)¶
- hoverMoveEvent(self, QGraphicsSceneHoverEvent)¶
- inputMethodEvent(self, QInputMethodEvent)¶
- inputMethodQuery(self, Qt.InputMethodQuery) Any ¶
- isSignalConnected(self, QMetaMethod) bool ¶
- itemChange(self, QGraphicsItem.GraphicsItemChange, Any) Any ¶
- keyPressEvent(self, QKeyEvent)¶
- keyReleaseEvent(self, QKeyEvent)¶
- mouseDoubleClickEvent(self, QGraphicsSceneMouseEvent)¶
- mouseMoveEvent(self, QGraphicsSceneMouseEvent)¶
- mousePressEvent(self, QGraphicsSceneMouseEvent)¶
- mouseReleaseEvent(self, QGraphicsSceneMouseEvent)¶
- moveNode(self, index: int, node: QPointF | QPoint) bool ¶
Moves a node to a new position.
- Parameters:
index (int) – the index of the node to move
node (Union[QPointF) – is the new position in scene coordinate
- Return type:
bool
- nodeAtPosition(self, point: QPointF | QPoint, searchInRadius: bool = True, radius: float = 10) int ¶
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) – 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 ¶
Gets the position of a node in scene coordinates.
- Parameters:
index (int) – of the node
position (Union[QPointF) – 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 ¶
Returns the nodes the shape consists of.
See also
- Return type:
QPolygonF
- nodesSize(self) int ¶
Returns the number of nodes in the shape.
- Return type:
int
- positionAtReferencePoint(self, reference: QgsLayoutItem.ReferencePoint) QPointF ¶
Returns the current position (in layout units) of a
reference
point for the item.
- prepareGeometryChange(self)¶
- readObjectPropertiesFromElement(self, parentElement: QDomElement, document: QDomDocument, context: QgsReadWriteContext) bool ¶
Sets object properties from a DOM element
- Parameters:
parentElement – is the parent DOM element for the object
document – DOM document
context – read write context
- Returns:
True
if read was successful
See also
- readPropertiesFromElement(self, element: QDomElement, document: QDomDocument, context: QgsReadWriteContext) bool ¶
- Parameters:
element (QDomElement) –
document (QDomDocument) –
context (QgsReadWriteContext) –
- Return type:
bool
- receivers(self, PYQT_SIGNAL) int ¶
- refreshBackgroundColor(self, updateItem: bool = True)¶
Refresh item’s background color, considering data defined colors. If
updateItem
is set toFalse
, the item will not be automatically updated after the frame color is set and a later call toupdate()
must be made.
- refreshBlendMode(self)¶
Refresh item’s blend mode, considering data defined blend mode.
- refreshFrame(self, updateItem: bool = True)¶
Refresh item’s frame, considering data defined colors and frame size. If
updateItem
is set toFalse
, the item will not be automatically updated after the frame is set and a later call toupdate()
must be made.
- refreshItemPosition(self)¶
Refreshes an item’s position by rechecking it against any possible overrides such as data defined positioning.
See also
- refreshItemRotation(self, origin: QPointF | QPoint = None)¶
Refreshes an item’s rotation by rechecking it against any possible overrides such as data defined rotation.
The optional
origin
point specifies the origin (in item coordinates) around which the rotation should be applied.See also
See also
- refreshItemSize(self)¶
Refreshes an item’s size by rechecking it against any possible item fixed or minimum sizes.
See also
See also
See also
- refreshOpacity(self, updateItem: bool = True)¶
Refresh item’s opacity, considering data defined opacity. If
updateItem
is set toFalse
the item will not be automatically updated after the opacity is set and a later call toupdate()
must be made.
- removeNode(self, index: int) bool ¶
Remove a node with specified
index
from the shape.- Parameters:
index (int) –
- Return type:
bool
- rescaleToFitBoundingBox(self)¶
Rescale the current shape according to the item’s bounding box. Useful when the shape is resized thanks to the rubber band.
- sceneEvent(self, QEvent) bool ¶
- sceneEventFilter(self, QGraphicsItem, QEvent) bool ¶
- selectedNode(self) int ¶
Returns the currently selected node, or -1 if no node is selected.
- Return type:
int
- sender(self) QObject ¶
- senderSignalIndex(self) int ¶
- setDisplayNodes(self, display: bool = True)¶
Set whether the item’s nodes should be displayed.
- Parameters:
display (bool = True) –
- setFixedSize(self, size: QgsLayoutSize)¶
Sets a fixed
size
for the layout item, which prevents it from being freely resized. Set an empty size if item can be freely resized.See also
fixedSize()
See also
- setMinimumSize(self, size: QgsLayoutSize)¶
Sets the minimum allowed
size
for the layout item. Set an empty size if item can be freely resized.See also
minimumSize()
See also
- setNodes(self, nodes: QPolygonF)¶
Sets the
nodes
the shape consists of.See also
- Parameters:
nodes (QPolygonF) –
- setSelectedNode(self, index: int) bool ¶
Selects a node by
index
.- Parameters:
index (int) –
- Return type:
bool
- timerEvent(self, QTimerEvent)¶
- topLeftToReferencePoint(self, point: QgsLayoutPoint) QgsLayoutPoint ¶
Returns the position for the reference point of the item, if the top-left of the item was placed at the specified
point
.
- updateBoundingRect(self)¶
Called when the bounding rect of the item should recalculated. Subclasses should update currentRectangle in their implementations.
- updateMicroFocus(self)¶
- updateSceneRect(self)¶
Update the current scene rectangle for this item.
- wheelEvent(self, QGraphicsSceneWheelEvent)¶
- writeObjectPropertiesToElement(self, parentElement: QDomElement, document: QDomDocument, context: QgsReadWriteContext) bool ¶
Stores object properties within an XML DOM element.
- Parameters:
parentElement – is the parent DOM element to store the object’s properties in
document – DOM document
context – read write context
- Returns:
True
if write was successful
See also
- writePropertiesToElement(self, element: QDomElement, document: QDomDocument, context: QgsReadWriteContext) bool ¶
- Parameters:
element (QDomElement) –
document (QDomDocument) –
context (QgsReadWriteContext) –
- Return type:
bool