Class: QgsLayerTreeModelLegendNode¶
An abstract interface for legend items returned from
QgsMapLayerLegend implementation.
The objects are used in QgsLayerTreeModel. Custom
implementations may offer additional interactivity and customized look.
Note
This is an abstract class, with methods which must be implemented by a subclass.
The following methods must be implemented: data()
Class Hierarchy¶
Base classes¶
Subclasses¶
A legend node which renders a color ramp. |
|
A legend node with a marker symbol. |
|
Implementation of legend node interface for displaying arbitrary raster images. |
|
Implementation of legend node interface for displaying raster legend entries. |
|
Implementation of legend node interface for displaying arbitrary labels with icons. |
|
Implementation of legend node interface for displaying preview of vector symbols and their labels and allowing interaction with the symbol / renderer. |
|
A legend node for a labeling text symbol. |
|
Implementation of legend node interface for displaying WMS legend entries. |
- class qgis.core.QgsLayerTreeModelLegendNode[source]¶
Bases:
QObject- __init__(nodeL: QgsLayerTreeLayer | None, parent: QObject | None = None)
Construct the node with pointer to its parent layer node
- Parameters:
nodeL (Optional[QgsLayerTreeLayer])
parent (Optional[QObject] = None)
- ColorRampLegend = 7¶
- class CustomRole(*values)¶
Bases:
IntEnumLegend node data roles
Note
Prior to QGIS 3.36 this was available as QgsLayerTreeModelLegendNode.LegendNodeRoles
Added in version 3.36.
RuleKey: Rule key of the node (QString)Available as
QgsLayerTreeModelLegendNode.RuleKeyRolein older QGIS releases.ParentRuleKey: Rule key of the parent legend node - for legends with tree hierarchy (QString). Added in 2.8Available as
QgsLayerTreeModelLegendNode.ParentRuleKeyRolein older QGIS releases.NodeType: Type of node. Added in 3.16Available as
QgsLayerTreeModelLegendNode.NodeTypeRolein older QGIS releases.IsDataDefinedSize: Set when a node is related to data defined size (title or separated legend items). Added in 3.38Available as
QgsLayerTreeModelLegendNode.IsDataDefinedSizeRolein older QGIS releases.
- DataDefinedSizeLegend = 5¶
- EmbeddedWidget = 6¶
- ImageLegend = 3¶
- class ItemContext¶
- class ItemContext(a0: QgsLayerTreeModelLegendNode.ItemContext)
Bases:
object- columnLeft: float¶
- columnRight: float¶
- context: QgsRenderContext¶
- labelXOffset: float¶
- maxSiblingSymbolWidth: float¶
- painter: QPainter¶
- patchShape: QgsLegendPatchShape¶
- patchSize: QSizeF¶
- point: QPointF¶
- screenProperties: QgsScreenProperties¶
- textDocument: QgsTextDocument¶
- textDocumentMetrics: QgsTextDocumentMetrics¶
- top: float¶
- class ItemMetrics¶
- class ItemMetrics(a0: QgsLayerTreeModelLegendNode.ItemMetrics)
Bases:
object- labelSize¶
- symbolSize¶
- LegendNodeRoles¶
alias of
CustomRole
- class NodeTypes¶
Bases:
int
- RasterSymbolLegend = 2¶
- SimpleLegend = 0¶
- SymbolLegend = 1¶
- WmsLegend = 4¶
- checkAllItems(self)[source]¶
Checks all checkable items belonging to the same layer as this node.
See also
See also
Added in version 3.18.
- virtual columnBreak(self) bool[source]¶
Returns whether a forced column break should occur before the node.
See also
Added in version 3.14.
- Return type:
bool
- createTemporaryRenderContext(self) QgsRenderContext | None[source]¶
Returns a temporary context or
Noneif legendMapViewData are not valid- Return type:
Optional[QgsRenderContext]
- abstract data(self, role: int) Any[source]¶
Returns data associated with the item. Must be implemented in derived class.
- Parameters:
role (int)
- Return type:
- signal dataChanged[source]¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- virtual draw(self, settings: QgsLegendSettings, ctx: QgsLayerTreeModelLegendNode.ItemContext) QgsLayerTreeModelLegendNode.ItemMetrics[source]¶
Entry point called from
QgsLegendRendererto do the rendering. Default implementation callsdrawSymbol()anddrawSymbolText()methods.- Parameters:
settings (QgsLegendSettings)
- Return type:
- virtual drawSymbol(self, settings: QgsLegendSettings, ctx: QgsLayerTreeModelLegendNode.ItemContext | None, itemHeight: float) QSizeF[source]¶
Draws symbol on the left side of the item
- Parameters:
settings (QgsLegendSettings) – Legend layout configuration
ctx (Optional[QgsLayerTreeModelLegendNode.ItemContext]) – Context for rendering - may be
Noneif 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)
- virtual drawSymbolText(self, settings: QgsLegendSettings, ctx: QgsLayerTreeModelLegendNode.ItemContext | None, symbolSize: QSizeF) QSizeF[source]¶
Draws label on the right side of the item
- Parameters:
settings (QgsLegendSettings) – Legend layout configuration
ctx (Optional[QgsLayerTreeModelLegendNode.ItemContext]) – Context for rendering - may be
Noneif 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)
- virtual exportSymbolToJson(self, settings: QgsLegendSettings, context: QgsRenderContext) Dict[str, QJsonValue][source]¶
Adds a symbol in base64 string within a JSON object with the key “icon”.
- Parameters:
settings (QgsLegendSettings) – Legend layout configuration
context (QgsRenderContext) – Rendering context
Added in version 3.8.
- Return type:
Dict[str, QJsonValue]
- exportToJson(self, settings: QgsLegendSettings, context: QgsRenderContext) Dict[str, QJsonValue][source]¶
Entry point called from
QgsLegendRendererto do the rendering in a JSON object.- Parameters:
settings (QgsLegendSettings) – Legend layout configuration
context (QgsRenderContext) – Rendering context
Added in version 3.8.
- Return type:
Dict[str, QJsonValue]
- virtual flags(self) Qt.ItemFlags[source]¶
Returns item flags associated with the item. Default implementation returns Qt.ItemIsEnabled.
- Return type:
Qt.ItemFlags
- virtual invalidateMapBasedData(self)[source]¶
Notification from model that information from associated map view has changed. Default implementation does nothing.
- layerNode(self) QgsLayerTreeLayer | None[source]¶
Returns pointer to the parent layer node
- Return type:
Optional[QgsLayerTreeLayer]
- model(self) QgsLayerTreeModel | None[source]¶
Returns pointer to model owning this legend node
- Return type:
Optional[QgsLayerTreeModel]
- virtual setColumnBreak(self, breakBeforeNode: bool)[source]¶
Sets whether a forced column break should occur before the node.
See also
Added in version 3.14.
- Parameters:
breakBeforeNode (bool)
- virtual setData(self, value: Any, role: int) bool[source]¶
Sets some data associated with the item. Default implementation does nothing and returns
False.- Parameters:
value (Any)
role (int)
- Return type:
bool
- virtual setUserPatchSize(self, size: QSizeF)[source]¶
Sets the user (overridden)
sizefor 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
Added in version 3.14.
- Parameters:
size (QSizeF)
- signal sizeChanged[source]¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- toggleAllItems(self)[source]¶
Toggle all checkable items belonging to the same layer as this node.
See also
See also
Added in version 3.18.
- uncheckAllItems(self)[source]¶
Unchecks all checkable items belonging to the same layer as this node.
See also
See also
Added in version 3.18.
- virtual userPatchSize(self) QSizeF[source]¶
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
Added in version 3.14.
- Return type:
QSizeF