QGIS API Documentation  2.99.0-Master (7d4f81d)
qgslayertreegroup.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgslayertreegroup.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 QGSLAYERTREEGROUP_H
17 #define QGSLAYERTREEGROUP_H
18 
19 #include "qgis_core.h"
20 #include "qgis.h"
21 #include "qgslayertreenode.h"
22 
23 class QgsMapLayer;
24 class QgsLayerTreeLayer;
25 
33 class CORE_EXPORT QgsLayerTreeGroup : public QgsLayerTreeNode
34 {
35  Q_OBJECT
36  public:
37 
41  QgsLayerTreeGroup( const QString &name = QString(), bool checked = true );
42 
43 #ifndef SIP_RUN
44  QgsLayerTreeGroup( const QgsLayerTreeGroup &other );
45 #endif
46 
50  QString name() const override;
51 
55  void setName( const QString &n ) override;
56 
60  QgsLayerTreeGroup *insertGroup( int index, const QString &name );
61 
65  QgsLayerTreeGroup *addGroup( const QString &name );
66 
70  QgsLayerTreeLayer *insertLayer( int index, QgsMapLayer *layer );
71 
75  QgsLayerTreeLayer *addLayer( QgsMapLayer *layer );
76 
80  void insertChildNodes( int index, const QList<QgsLayerTreeNode *> &nodes SIP_TRANSFER );
81 
85  void insertChildNode( int index, QgsLayerTreeNode *node SIP_TRANSFER );
86 
90  void addChildNode( QgsLayerTreeNode *node SIP_TRANSFER );
91 
95  void removeChildNode( QgsLayerTreeNode *node );
96 
100  void removeLayer( QgsMapLayer *layer );
101 
105  void removeChildren( int from, int count );
106 
110  void removeChildrenGroupWithoutLayers();
111 
115  void removeAllChildren();
116 
121  QgsLayerTreeLayer *findLayer( QgsMapLayer *layer ) const;
122 
126  QgsLayerTreeLayer *findLayer( const QString &layerId ) const;
127 
131  QList<QgsLayerTreeLayer *> findLayers() const;
132 
136  QStringList findLayerIds() const;
137 
141  QgsLayerTreeGroup *findGroup( const QString &name );
142 
147  static QgsLayerTreeGroup *readXml( QDomElement &element ) SIP_FACTORY;
148 
154  static QgsLayerTreeGroup *readXml( QDomElement &element, const QgsProject *project ) SIP_FACTORY;
155 
159  virtual void writeXml( QDomElement &parentElement ) override;
160 
165  void readChildrenFromXml( QDomElement &element );
166 
170  virtual QString dump() const override;
171 
175  virtual QgsLayerTreeGroup *clone() const override SIP_FACTORY;
176 
181  virtual void resolveReferences( const QgsProject *project, bool looseMatching = false ) override;
182 
186  virtual void setItemVisibilityCheckedRecursive( bool checked ) override;
187 
192  bool isMutuallyExclusive() const;
193 
200  void setIsMutuallyExclusive( bool enabled, int initialChildIndex = -1 );
201 
202  protected slots:
203  void nodeVisibilityChanged( QgsLayerTreeNode *node );
204 
205  protected:
206 
210  void updateChildVisibilityMutuallyExclusive();
211 
212  QString mName;
213 
215 
218 
224 
225  private:
226 
227 #ifdef SIP_RUN
228 
232  QgsLayerTreeGroup( const QgsLayerTreeGroup &other );
233 #endif
234 
235 };
236 
237 
238 #endif // QGSLAYERTREEGROUP_H
Layer tree group node serves as a container for layers and further groups.
Base class for all map layer types.
Definition: qgsmaplayer.h:54
virtual QString name() const =0
Return name of the node.
virtual void setName(const QString &name)=0
Set name of the node.
virtual QgsLayerTreeNode * clone() const =0
Create a copy of the node. Returns new instance.
virtual QString dump() const =0
Return string with layer tree structure. For debug purposes only.
virtual void setItemVisibilityCheckedRecursive(bool checked)
Check or uncheck a node and all its children (taking into account exclusion rules) ...
#define SIP_TRANSFER
Definition: qgis_sip.h:36
virtual void writeXml(QDomElement &parentElement)=0
Write layer tree to XML.
static QgsLayerTreeNode * readXml(QDomElement &element)
Read layer tree from XML.
This class is a base class for nodes in a layer tree.
Reads and writes project states.
Definition: qgsproject.h:79
int mMutuallyExclusiveChildIndex
Keeps track which child has been most recently selected (so if the whole group is unchecked and check...
#define SIP_FACTORY
Definition: qgis_sip.h:69
bool mMutuallyExclusive
Whether the group is mutually exclusive (i.e. only one child can be checked at a time) ...
virtual void resolveReferences(const QgsProject *project, bool looseMatching=false)=0
Turn textual references to layers into map layer object from project.
Layer tree node points to a map layer.