Class: QgsLayerTreeModelLegendNode¶
- class qgis.core.QgsLayerTreeModelLegendNode(nodeL: QgsLayerTreeLayer, parent: QObject = None)¶
Bases:
PyQt5.QtCore.QObject
Construct the node with pointer to its parent layer node
The
QgsLegendRendererItem
class is abstract interface for legend items returned fromQgsMapLayerLegend
implementation.The objects are used in
QgsLayerTreeModel
. Custom implementations may offer additional interactivity and customized look.New in version 2.6:
Methods
Returns whether a forced column break should occur before the node.
Returns a temporary context or
None
if legendMapViewData are not validReturns data associated with the item.
Entry point called from
QgsLegendRenderer
to do the rendering.Draws symbol on the left side of the item
Draws label on the right side of the item
Adds a symbol in base64 string within a JSON object with the key "icon".
Entry point called from
QgsLegendRenderer
to do the rendering in a JSON object.Returns item flags associated with the item.
Notification from model that information from associated map view has changed.
- rtype
bool
- param scale
Returns pointer to the parent layer node
Returns pointer to model owning this legend node
Sets whether a forced column break should occur before the node.
Sets some data associated with the item.
- param embedded
- param userLabel
Sets the user (overridden)
size
for the legend node.- rtype
str
Returns the user (overridden) size for the legend node.
Signals
Emitted on internal data change so the layer tree model can forward the signal to views [signal]
Emitted when the size of this node changes.
Attributes
- DataDefinedSizeLegend = 5¶
- EmbeddedWidget = 6¶
- ImageLegend = 3¶
- class ItemContext¶
- class ItemContext(QgsLayerTreeModelLegendNode.ItemContext) None
Bases:
sip.wrapper
- columnLeft¶
- columnRight¶
- context¶
- labelXOffset¶
- maxSiblingSymbolWidth¶
- painter¶
- patchShape¶
- patchSize¶
- point¶
- top¶
- class ItemMetrics¶
- class ItemMetrics(QgsLayerTreeModelLegendNode.ItemMetrics) None
Bases:
sip.wrapper
- labelSize¶
- symbolSize¶
- class LegendNodeRoles¶
Bases:
int
- NodeTypeRole = 258¶
- class NodeTypes¶
Bases:
int
- ParentRuleKeyRole = 257¶
- RasterSymbolLegend = 2¶
- RuleKeyRole = 256¶
- SimpleLegend = 0¶
- SymbolLegend = 1¶
- WmsLegend = 4¶
- childEvent(self, QChildEvent)¶
- columnBreak(self) bool ¶
Returns whether a forced column break should occur before the node.
See also
New in version 3.14.
- Return type
bool
- connectNotify(self, QMetaMethod)¶
- createTemporaryRenderContext(self) QgsRenderContext ¶
Returns a temporary context or
None
if legendMapViewData are not valid- Return type
- customEvent(self, QEvent)¶
- data(self, role: int) Any ¶
Returns data associated with the item. Must be implemented in derived class.
- Parameters
role (int) –
- Return type
Any
- dataChanged¶
Emitted on internal data change so the layer tree model can forward the signal to views [signal]
- disconnectNotify(self, QMetaMethod)¶
- draw(self, settings: QgsLegendSettings, ctx: QgsLayerTreeModelLegendNode.ItemContext) QgsLayerTreeModelLegendNode.ItemMetrics ¶
Entry point called from
QgsLegendRenderer
to do the rendering. Default implementation callsdrawSymbol()
anddrawSymbolText()
methods.If ctx is
None
, this is just first stage when preparing layout - without actual rendering.- Parameters
settings (QgsLegendSettings) –
- Return type
- drawSymbol(self, settings: QgsLegendSettings, ctx: QgsLayerTreeModelLegendNode.ItemContext, itemHeight: float) QSizeF ¶
Draws symbol on the left side of the item
- Parameters
settings (QgsLegendSettings) – Legend layout configuration
ctx (QgsLayerTreeModelLegendNode.ItemContext) – Context for rendering - may be
None
if only doing layout without actual renderingitemHeight (float) – Minimal height of the legend item - used for correct positioning when rendering
- Return type
QSizeF
- Returns
Real size of the symbol (may be bigger than “normal” symbol size from settings)
- drawSymbolText(self, settings: QgsLegendSettings, ctx: QgsLayerTreeModelLegendNode.ItemContext, symbolSize: QSizeF) QSizeF ¶
Draws label on the right side of the item
- Parameters
settings (QgsLegendSettings) – Legend layout configuration
ctx (QgsLayerTreeModelLegendNode.ItemContext) – Context for rendering - may be
None
if only doing layout without actual renderingsymbolSize (QSizeF) – Real size of the associated symbol - used for correct positioning when rendering
- Return type
QSizeF
- Returns
Size of the label (may span multiple lines)
- exportSymbolToJson(self, settings: QgsLegendSettings, context: QgsRenderContext) Dict[str, QJsonValue] ¶
Adds a symbol in base64 string within a JSON object with the key “icon”.
- Parameters
settings (QgsLegendSettings) – Legend layout configuration
context (QgsRenderContext) – Rendering context
New in version 3.8.
- Return type
Dict[str, QJsonValue]
- exportToJson(self, settings: QgsLegendSettings, context: QgsRenderContext) Dict[str, QJsonValue] ¶
Entry point called from
QgsLegendRenderer
to do the rendering in a JSON object.- Parameters
settings (QgsLegendSettings) – Legend layout configuration
context (QgsRenderContext) – Rendering context
New in version 3.8.
- Return type
Dict[str, QJsonValue]
- flags(self) Qt.ItemFlags ¶
Returns item flags associated with the item. Default implementation returns Qt.ItemIsEnabled.
- Return type
Qt.ItemFlags
- invalidateMapBasedData(self)¶
Notification from model that information from associated map view has changed. Default implementation does nothing.
- isEmbeddedInParent(self) bool ¶
- Return type
bool
- isScaleOK(self, scale: float) bool ¶
- Parameters
scale (float) –
- Return type
bool
- isSignalConnected(self, QMetaMethod) bool ¶
- layerNode(self) QgsLayerTreeLayer ¶
Returns pointer to the parent layer node
- Return type
- model(self) QgsLayerTreeModel ¶
Returns pointer to model owning this legend node
- Return type
- receivers(self, PYQT_SIGNAL) int ¶
- sender(self) QObject ¶
- senderSignalIndex(self) int ¶
- setColumnBreak(self, breakBeforeNode: bool)¶
Sets whether a forced column break should occur before the node.
See also
New in version 3.14.
- Parameters
breakBeforeNode (bool) –
- setData(self, value: Any, role: int) bool ¶
Sets some data associated with the item. Default implementation does nothing and returns
False
.- Parameters
value (Any) –
role (int) –
- Return type
bool
- setEmbeddedInParent(self, embedded: bool)¶
- Parameters
embedded (bool) –
- setUserLabel(self, userLabel: str)¶
- Parameters
userLabel (str) –
- setUserPatchSize(self, size: QSizeF)¶
Sets the user (overridden)
size
for the legend node.If either the width or height are non-zero, they will be used when rendering the legend node instead of the default symbol width or height from
QgsLegendSettings
.See also
New in version 3.14.
- Parameters
size (QSizeF) –
- sizeChanged¶
Emitted when the size of this node changes.
New in version 3.16: [signal]
- timerEvent(self, QTimerEvent)¶
- userLabel(self) str ¶
- Return type
str
- userPatchSize(self) QSizeF ¶
Returns the user (overridden) size for the legend node.
If either the width or height are non-zero, they will be used when rendering the legend node instead of the default symbol width or height from
QgsLegendSettings
.See also
New in version 3.14.
- Return type
QSizeF