Class: QgsLayerTree¶
Namespace with helper functions for layer tree operations.
Only generally useful routines should be here. Miscellaneous utility
functions for work with the layer tree are in
QgsLayerTreeUtils
class.
Class Hierarchy¶
Base classes¶
Layer tree group node serves as a container for layers and further groups. |
|
Base class for nodes in a layer tree. |
|
Methods
Clear any information from this layer tree. |
|
The order in which layers will be rendered on the canvas. |
|
Determines if the layer order should be derived from the layer tree or if a custom override order shall be used instead. |
|
The order in which layers will be rendered on the canvas. |
|
Load the layer order from an XML element. |
|
The order in which layers will be rendered on the canvas. |
|
The order in which layers will be rendered on the canvas. |
|
Determines if the layer order should be derived from the layer tree or if a custom override order shall be used instead. |
Static Methods
Check whether the node is a valid group node |
|
Check whether the node is a valid layer node |
|
Load the layer tree from an XML element. |
Signals
Emitted when the custom layer order has changed. |
|
Emitted when the hasCustomLayerOrder flag changes. |
|
Emitted when the layer order has changed. |
- class qgis.core.QgsLayerTree[source]¶
Bases:
QgsLayerTreeGroup
- __init__()
Create a new empty layer tree
- customLayerOrder(self) List[QgsMapLayer] ¶
The order in which layers will be rendered on the canvas. Will only be used if the property hasCustomLayerOrder is
True
. If you need the current layer order that is active, prefer usinglayerOrder()
.See also
See also
See also
- Return type:
List[QgsMapLayer]
- hasCustomLayerOrder(self) bool [source]¶
Determines if the layer order should be derived from the layer tree or if a custom override order shall be used instead.
See also
- Return type:
bool
- signal hasCustomLayerOrderChanged(hasCustomLayerOrder: bool)[source]¶
Emitted when the hasCustomLayerOrder flag changes.
See also
- Parameters:
hasCustomLayerOrder (bool)
- static isGroup(node: QgsLayerTreeNode | None) bool [source]¶
Check whether the node is a valid group node
- Parameters:
node (Optional[QgsLayerTreeNode])
- Return type:
bool
- static isLayer(node: QgsLayerTreeNode | None) bool [source]¶
Check whether the node is a valid layer node
- Parameters:
node (Optional[QgsLayerTreeNode])
- Return type:
bool
- layerOrder(self) List[QgsMapLayer] ¶
The order in which layers will be rendered on the canvas. Depending on hasCustomLayerOrder, this will return either the override customLayerOrder or the layer order derived from the tree. This property is read only.
See also
- Return type:
List[QgsMapLayer]
- readLayerOrderFromXml(self, doc: QDomElement)[source]¶
Load the layer order from an XML element. Make sure that this is only called after the layers are loaded.
- Parameters:
doc (QDomElement)
- static readXml(element: QDomElement, context: QgsReadWriteContext) QgsLayerTree | None [source]¶
Load the layer tree from an XML element. It is not required that layers are loaded at this point.
resolveReferences()
needs to be called after loading the layers and before using the tree.- Parameters:
element (QDomElement)
context (QgsReadWriteContext)
- Return type:
Optional[QgsLayerTree]
- setCustomLayerOrder(self, customLayerOrder: Iterable[QgsMapLayer])[source]¶
The order in which layers will be rendered on the canvas. Will only be used if the property hasCustomLayerOrder is
True
. If you need the current layer order that is active, prefer usinglayerOrder()
.See also
See also
See also
- Parameters:
customLayerOrder (Iterable[QgsMapLayer])
- setCustomLayerOrderByIds(self, customLayerOrder: Iterable[str | None])¶
The order in which layers will be rendered on the canvas. Will only be used if the property hasCustomLayerOrder is
True
. If you need the current layer order that is active, prefer usinglayerOrder()
.See also
See also
See also
- Parameters:
customLayerOrder (Iterable[Optional[str]])