QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgslayertreeutils.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgslayertreeutils.h
3  --------------------------------------
4  Date : May 2014
5  Copyright : (C) 2014 by Martin Dobias
6  Email : wonder dot sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSLAYERTREEUTILS_H
17 #define QGSLAYERTREEUTILS_H
18 
19 #include <qnamespace.h>
20 #include <QList>
21 #include <QPair>
22 #include <QDomNodeList>
23 #include "qgis_core.h"
24 
25 class QDomElement;
26 class QDomDocument;
27 class QStringList;
28 
29 class QgsLayerTreeNode;
30 class QgsLayerTreeGroup;
31 class QgsLayerTreeLayer;
32 class QgsMapLayer;
33 class QgsProject;
34 
41 class CORE_EXPORT QgsLayerTreeUtils
42 {
43  public:
44 
46  static bool readOldLegend( QgsLayerTreeGroup *root, const QDomElement &legendElem );
48  static bool readOldLegendLayerOrder( const QDomElement &legendElem, bool &hasCustomOrder, QStringList &order );
50  static QDomElement writeOldLegend( QDomDocument &doc, QgsLayerTreeGroup *root, bool hasCustomOrder, const QList<QgsMapLayer *> &order );
51 
53  static QString checkStateToXml( Qt::CheckState state );
55  static Qt::CheckState checkStateFromXml( const QString &txt );
56 
58  static bool layersEditable( const QList<QgsLayerTreeLayer *> &layerNodes );
60  static bool layersModified( const QList<QgsLayerTreeLayer *> &layerNodes );
61 
63  static void removeInvalidLayers( QgsLayerTreeGroup *group );
64 
69  static void storeOriginalLayersProperties( QgsLayerTreeGroup *group, const QDomDocument *doc );
70 
72  static void replaceChildrenOfEmbeddedGroups( QgsLayerTreeGroup *group );
73 
77  static void updateEmbeddedGroupsProjectPath( QgsLayerTreeGroup *group, const QgsProject *project );
78 
80  static QStringList invisibleLayerList( QgsLayerTreeNode *node );
81 
83  static void setLegendFilterByExpression( QgsLayerTreeLayer &layer, const QString &expr, bool enabled = true );
85  static QString legendFilterByExpression( const QgsLayerTreeLayer &layer, bool *enabled = nullptr );
87  static bool hasLegendFilterExpression( const QgsLayerTreeGroup &group );
88 
96  static QgsLayerTreeLayer *insertLayerBelow( QgsLayerTreeGroup *group, const QgsMapLayer *refLayer, QgsMapLayer *layerToInsert );
97 
103  static QSet<QgsMapLayer *> collectMapLayersRecursive( const QList<QgsLayerTreeNode *> &nodes );
104 
117  static int countMapLayerInTree( QgsLayerTreeNode *tree, QgsMapLayer *layer );
118 
126  static QgsLayerTreeGroup *firstGroupWithoutCustomProperty( QgsLayerTreeGroup *group, const QString &property );
127 };
128 
129 #endif // QGSLAYERTREEUTILS_H
QgsLayerTreeUtils
Assorted functions for dealing with layer trees.
Definition: qgslayertreeutils.h:42
QgsLayerTreeNode
This class is a base class for nodes in a layer tree.
Definition: qgslayertreenode.h:75
QgsProject
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:95
QgsLayerTreeLayer
Layer tree node points to a map layer.
Definition: qgslayertreelayer.h:44
QgsLayerTreeGroup
Layer tree group node serves as a container for layers and further groups.
Definition: qgslayertreegroup.h:35
QgsMapLayer
Base class for all map layer types.
Definition: qgsmaplayer.h:83