QgsLayerTree class
Namespace with helper functions for layer tree operations.
Contents
Only generally useful routines should be here. Miscellaneous utility functions for work with the layer tree are in QgsLayerTreeUtils class.
Base classes
- class QgsLayerTreeGroup
- Layer tree group node serves as a container for layers and further groups.
Public static functions
- static auto isGroup(QgsLayerTreeNode* node) -> bool
- Check whether the node is a valid group node.
- static auto isLayer(const QgsLayerTreeNode* node) -> bool
- Check whether the node is a valid layer node.
- static auto readXml(QDomElement& element, const QgsReadWriteContext& context) -> QgsLayerTree*
- Load the layer tree from an XML element.
- static auto toGroup(QgsLayerTreeNode* node) -> QgsLayerTreeGroup*
- Cast node to a group.
- static auto toLayer(QgsLayerTreeNode* node) -> QgsLayerTreeLayer*
- Cast node to a layer.
- static auto toLayer(const QgsLayerTreeNode* node) -> const QgsLayerTreeLayer*
- Cast node to a layer.
Constructors, destructors, conversion operators
- QgsLayerTree()
- Create a new empty layer tree.
Public functions
- void clear()
- Clear any information from this layer tree.
- auto clone() const -> QgsLayerTree* override
- Create a copy of the node. Returns new instance.
- auto customLayerOrder() const -> QList<QgsMapLayer*>
- The order in which layers will be rendered on the canvas.
- auto hasCustomLayerOrder() const -> bool
- Determines if the layer order should be derived from the layer tree or if a custom override order shall be used instead.
- auto layerOrder() const -> QList<QgsMapLayer*>
- The order in which layers will be rendered on the canvas.
- void readLayerOrderFromXml(const QDomElement& doc)
- Load the layer order from an XML element.
- void setCustomLayerOrder(const QList<QgsMapLayer*>& customLayerOrder)
- The order in which layers will be rendered on the canvas.
- void setCustomLayerOrder(const QStringList& customLayerOrder)
- The order in which layers will be rendered on the canvas.
- void setHasCustomLayerOrder(bool hasCustomLayerOrder)
- Determines if the layer order should be derived from the layer tree or if a custom override order shall be used instead.
- void writeXml(QDomElement& parentElement, const QgsReadWriteContext& context) override
- Write layer tree to XML.
Signals
- void customLayerOrderChanged()
- Emitted when the custom layer order has changed.
- void hasCustomLayerOrderChanged(bool hasCustomLayerOrder)
- Emitted when the hasCustomLayerOrder flag changes.
- void layerOrderChanged()
- Emitted when the layer order has changed.
Function documentation
static bool QgsLayerTree:: isGroup(QgsLayerTreeNode* node)
Check whether the node is a valid group node.
static bool QgsLayerTree:: isLayer(const QgsLayerTreeNode* node)
Check whether the node is a valid layer node.
static QgsLayerTree* QgsLayerTree:: readXml(QDomElement& element,
const QgsReadWriteContext& context)
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.
static QgsLayerTreeGroup* QgsLayerTree:: toGroup(QgsLayerTreeNode* node)
Cast node to a group.
No type checking is done - use isGroup() to find out whether this operation is legal.
static QgsLayerTreeLayer* QgsLayerTree:: toLayer(QgsLayerTreeNode* node)
Cast node to a layer.
No type checking is done - use isLayer() to find out whether this operation is legal.
static const QgsLayerTreeLayer* QgsLayerTree:: toLayer(const QgsLayerTreeNode* node)
Cast node to a layer.
No type checking is done - use isLayer() to find out whether this operation is legal.
void QgsLayerTree:: clear()
Clear any information from this layer tree.
QList<QgsMapLayer*> QgsLayerTree:: customLayerOrder() const
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 using layerOrder().
bool QgsLayerTree:: hasCustomLayerOrder() const
Determines if the layer order should be derived from the layer tree or if a custom override order shall be used instead.
QList<QgsMapLayer*> QgsLayerTree:: layerOrder() const
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.
void QgsLayerTree:: readLayerOrderFromXml(const QDomElement& doc)
Load the layer order from an XML element.
Make sure that this is only called after the layers are loaded.
void QgsLayerTree:: setCustomLayerOrder(const QList<QgsMapLayer*>& customLayerOrder)
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 using layerOrder().
void QgsLayerTree:: setCustomLayerOrder(const QStringList& customLayerOrder)
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 using layerOrder().
void QgsLayerTree:: setHasCustomLayerOrder(bool hasCustomLayerOrder)
Determines if the layer order should be derived from the layer tree or if a custom override order shall be used instead.
void QgsLayerTree:: customLayerOrderChanged() signal
Emitted when the custom layer order has changed.
void QgsLayerTree:: hasCustomLayerOrderChanged(bool hasCustomLayerOrder) signal
Emitted when the hasCustomLayerOrder flag changes.
void QgsLayerTree:: layerOrderChanged() signal
Emitted when the layer order has changed.