QgsLayerTreeUtils class
Assorted functions for dealing with layer trees.
Contents
- Reference
Public static functions
- static auto checkStateFromXml(const QString& txt) -> Qt::CheckState
- Convert QString to Qt::CheckState.
- static auto checkStateToXml(Qt::CheckState state) -> QString
- Convert Qt::CheckState to QString.
- static auto collectMapLayersRecursive(const QList<QgsLayerTreeNode*>& nodes) -> QSet<QgsMapLayer*>
- Returns map layers from the given list of layer tree nodes.
- static auto countMapLayerInTree(QgsLayerTreeNode* tree, QgsMapLayer* layer) -> int
- Returns how many occurrences of a map layer are there in a layer tree.
- static auto hasLegendFilterExpression(const QgsLayerTreeGroup& group) -> bool
- Test if one of the layers in a group has an expression filter.
- static auto insertLayerBelow(QgsLayerTreeGroup* group, const QgsMapLayer* refLayer, QgsMapLayer* layerToInsert) -> QgsLayerTreeLayer*
- Insert a QgsMapLayer just below another one.
- static auto invisibleLayerList(QgsLayerTreeNode* node) -> QStringList
- Gets invisible layers.
- static auto layersEditable(const QList<QgsLayerTreeLayer*>& layerNodes) -> bool
- Returns true if any of the layers is editable.
- static auto layersModified(const QList<QgsLayerTreeLayer*>& layerNodes) -> bool
- Returns true if any of the layers is modified.
- static auto legendFilterByExpression(const QgsLayerTreeLayer& layer, bool* enabled = nullptr) -> QString
- Returns the expression filter of a legend layer.
- static auto readOldLegend(QgsLayerTreeGroup* root, const QDomElement& legendElem) -> bool
- Try to load layer tree from.
- static auto readOldLegendLayerOrder(const QDomElement& legendElem, bool& hasCustomOrder, QStringList& order) -> bool
- Try to load custom layer order from.
- static void removeInvalidLayers(QgsLayerTreeGroup* group)
- Removes layer nodes that refer to invalid layers.
- static void replaceChildrenOfEmbeddedGroups(QgsLayerTreeGroup* group)
- Remove subtree of embedded groups and replaces it with a custom property embedded-visible-layers.
- static void setLegendFilterByExpression(QgsLayerTreeLayer& layer, const QString& expr, bool enabled = true)
- Sets the expression filter of a legend layer.
- static void storeOriginalLayersProperties(QgsLayerTreeGroup* group, const QDomDocument* doc)
- Stores in a layer's originalXmlProperties the layer properties information.
- static void updateEmbeddedGroupsProjectPath(QgsLayerTreeGroup* group, const QgsProject* project)
- Updates an embedded group from a project.
- static auto writeOldLegend(QDomDocument& doc, QgsLayerTreeGroup* root, bool hasCustomOrder, const QList<QgsMapLayer*>& order) -> QDomElement
- Returns.
Function documentation
static QSet<QgsMapLayer*> QgsLayerTreeUtils:: collectMapLayersRecursive(const QList<QgsLayerTreeNode*>& nodes)
Returns map layers from the given list of layer tree nodes.
Also recursively visits child nodes of groups.
static int QgsLayerTreeUtils:: countMapLayerInTree(QgsLayerTreeNode* tree,
QgsMapLayer* layer)
Returns how many occurrences of a map layer are there in a layer tree.
In normal situations there is at most one occurrence, but sometimes there may be temporarily more: for example, during drag&drop, upon drop a new layer node is created while the original dragged node is still in the tree, resulting in two occurrences.
This is useful when deciding whether to start or stop listening to a signal of a map layer within a layer tree and only connecting/disconnecting when there is only one occurrence of that layer.
static QgsLayerTreeLayer* QgsLayerTreeUtils:: insertLayerBelow(QgsLayerTreeGroup* group,
const QgsMapLayer* refLayer,
QgsMapLayer* layerToInsert)
Insert a QgsMapLayer just below another one.
| Parameters | |
|---|---|
| group | the tree group where layers are (can be the root group) |
| refLayer | the reference layer |
| layerToInsert | the new layer to insert just below the reference layer |
| Returns | the new tree layer |
static bool QgsLayerTreeUtils:: readOldLegend(QgsLayerTreeGroup* root,
const QDomElement& legendElem)
Try to load layer tree from.
<legend>
tag from project files from QGIS 2.2 and below
static bool QgsLayerTreeUtils:: readOldLegendLayerOrder(const QDomElement& legendElem,
bool& hasCustomOrder,
QStringList& order)
Try to load custom layer order from.
<legend>
tag from project files from QGIS 2.2 and below
static void QgsLayerTreeUtils:: storeOriginalLayersProperties(QgsLayerTreeGroup* group,
const QDomDocument* doc)
Stores in a layer's originalXmlProperties the layer properties information.
static QDomElement QgsLayerTreeUtils:: writeOldLegend(QDomDocument& doc,
QgsLayerTreeGroup* root,
bool hasCustomOrder,
const QList<QgsMapLayer*>& order)
Returns.
<legend>
tag used in QGIS 2.2 and below