Class: QgsLayerTreeLayer¶
Layer tree node points to a map layer.
The node can exist also without a valid instance of a layer (just ID).
That means the referenced layer does not need to be loaded in order to
use it in layer tree. In such case, resolveReferences()
method
can be called once the layer is loaded.
A map layer is supposed to be present in one layer tree just once. It is however possible that temporarily a layer exists in one tree more than just once, e.g. while reordering items with drag and drop.
Class Hierarchy¶
Base classes¶
Base class for nodes in a layer tree. |
|
Abstract Methods
Returns the layer's name. |
|
Resolves reference to layer from stored layer ID (if it has not been resolved already) |
|
Sets the layer's name. |
Methods
Returns the expression member of the LayerTreeNode |
|
Returns the map layer associated with this node. |
|
Returns the ID for the map layer associated with this node. |
|
Returns the column split behavior for the node. |
|
Returns the symbol patch shape to use when rendering the legend node symbol. |
|
Returns the user (overridden) size for the legend node. |
|
set the expression to evaluate |
|
Sets the column split behavior for the node. |
|
Sets the symbol patch shape to use when rendering the legend node symbol. |
|
Sets the user (overridden) size for the legend node. |
|
Uses the layer's name if use is |
|
Returns whether the layer's name is used, or the name manually set. |
Static Methods
Read layer node from XML. |
Signals
Emitted when a previously unavailable layer got loaded. |
|
Emitted when a previously available layer got unloaded (from layer registry). |
Attributes
- class qgis.core.QgsLayerTreeLayer[source]¶
Bases:
QgsLayerTreeNode
- __init__(layer: QgsMapLayer | None)
- Parameters:
layer (Optional[QgsMapLayer])
- __init__(layerId: str | None, name: str | None = '', source: str | None = '', provider: str | None = '')
Constructor for QgsLayerTreeLayer using weak references to layer ID,
name
, publicsource
, andprovider
key.- Parameters:
layerId (Optional[str])
name (Optional[str] = '')
source (Optional[str] = '')
provider (Optional[str] = '')
- AllowSplittingLegendNodesOverMultipleColumns = 1¶
- class LegendNodesSplitBehavior¶
Bases:
int
- PreventSplittingLegendNodesOverMultipleColumns = 2¶
- UseDefaultLegendSetting = 0¶
- labelExpression(self) str [source]¶
Returns the expression member of the LayerTreeNode
Added in version 3.10.
- Return type:
str
- layer(self) QgsMapLayer | None [source]¶
Returns the map layer associated with this node.
Warning
This can be (and often is!)
None
, e.g. in the case of a layer node representing a layer which has not yet been fully loaded into a project, or a layer node representing a layer with an invalid data source. The returned pointer must ALWAYS be checked to avoid dereferencingNone
.See also
- Return type:
Optional[QgsMapLayer]
- layerId(self) str [source]¶
Returns the ID for the map layer associated with this node.
See also
- Return type:
str
- signal layerWillBeUnloaded[source]¶
Emitted when a previously available layer got unloaded (from layer registry).
- legendSplitBehavior(self) QgsLayerTreeLayer.LegendNodesSplitBehavior [source]¶
Returns the column split behavior for the node.
This value controls how legend nodes belonging the to layer may be split over multiple columns in legends.
See also
Added in version 3.14.
- Return type:
- patchShape(self) QgsLegendPatchShape [source]¶
Returns the symbol patch shape to use when rendering the legend node symbol.
See also
Added in version 3.14.
- Return type:
- patchSize(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
- static readXml(element: QDomElement, context: QgsReadWriteContext) QgsLayerTreeLayer | None [source]¶
Read layer node from XML. Returns new instance. Does not resolve textual references to layers. Call
resolveReferences()
afterwards to do it.- Parameters:
element (QDomElement)
context (
QgsReadWriteContext
)
- Return type:
Optional[QgsLayerTreeLayer]
- static readXml(element: QDomElement, project: QgsProject | None, context: QgsReadWriteContext) QgsLayerTreeLayer | None [source]
Read layer node from XML. Returns new instance. Also resolves textual references to layers from the project (calls
resolveReferences()
internally).- Parameters:
element (QDomElement)
project (Optional[QgsProject])
context (
QgsReadWriteContext
)
- Return type:
Optional[QgsLayerTreeLayer]
- abstract resolveReferences(self, project: QgsProject | None, looseMatching: bool = False)[source]¶
Resolves reference to layer from stored layer ID (if it has not been resolved already)
- Parameters:
project (Optional[QgsProject])
looseMatching (bool = False)
- setLabelExpression(self, expression: str | None)[source]¶
set the expression to evaluate
Added in version 3.10.
- Parameters:
expression (Optional[str])
- setLegendSplitBehavior(self, behavior: QgsLayerTreeLayer.LegendNodesSplitBehavior)[source]¶
Sets the column split
behavior
for the node.This value controls how legend nodes belonging the to layer may be split over multiple columns in legends.
See also
Added in version 3.14.
- Parameters:
behavior (QgsLayerTreeLayer.LegendNodesSplitBehavior)
- abstract setName(self, n: str | None)[source]¶
Sets the layer’s name.
See also
- Parameters:
n (Optional[str])
- setPatchShape(self, shape: QgsLegendPatchShape)[source]¶
Sets the symbol patch
shape
to use when rendering the legend node symbol.See also
Added in version 3.14.
- Parameters:
shape (QgsLegendPatchShape)
- setPatchSize(self, size: QSizeF)[source]¶
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
Added in version 3.14.
- Parameters:
size (QSizeF)