QGIS API Documentation  3.6.0-Noosa (5873452)
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_sip.h"
21 #include "qgslayertreenode.h"
22 
23 class QgsMapLayer;
24 class QgsLayerTreeLayer;
25 
34 class CORE_EXPORT QgsLayerTreeGroup : public QgsLayerTreeNode
35 {
36  Q_OBJECT
37  public:
38 
42  QgsLayerTreeGroup( const QString &name = QString(), bool checked = true );
43 
44 #ifndef SIP_RUN
45  QgsLayerTreeGroup( const QgsLayerTreeGroup &other );
46 #endif
47 
51  QString name() const override;
52 
56  void setName( const QString &n ) override;
57 
61  QgsLayerTreeGroup *insertGroup( int index, const QString &name );
62 
66  QgsLayerTreeGroup *addGroup( const QString &name );
67 
71  QgsLayerTreeLayer *insertLayer( int index, QgsMapLayer *layer );
72 
76  QgsLayerTreeLayer *addLayer( QgsMapLayer *layer );
77 
81  void insertChildNodes( int index, const QList<QgsLayerTreeNode *> &nodes SIP_TRANSFER );
82 
86  void insertChildNode( int index, QgsLayerTreeNode *node SIP_TRANSFER );
87 
91  void addChildNode( QgsLayerTreeNode *node SIP_TRANSFER );
92 
96  void removeChildNode( QgsLayerTreeNode *node );
97 
101  void removeLayer( QgsMapLayer *layer );
102 
106  void removeChildren( int from, int count );
107 
111  void removeChildrenGroupWithoutLayers();
112 
116  void removeAllChildren();
117 
122  QgsLayerTreeLayer *findLayer( QgsMapLayer *layer ) const;
123 
127  QgsLayerTreeLayer *findLayer( const QString &layerId ) const;
128 
132  QList<QgsLayerTreeLayer *> findLayers() const;
133 
137  QStringList findLayerIds() const;
138 
142  QgsLayerTreeGroup *findGroup( const QString &name );
143 
147  QList<QgsLayerTreeGroup *> findGroups() const;
148 
153  static QgsLayerTreeGroup *readXml( QDomElement &element, const QgsReadWriteContext &context ) SIP_FACTORY;
154 
160  static QgsLayerTreeGroup *readXml( QDomElement &element, const QgsProject *project, const QgsReadWriteContext &context ) SIP_FACTORY;
161 
165  void writeXml( QDomElement &parentElement, const QgsReadWriteContext &context ) override;
166 
171  void readChildrenFromXml( QDomElement &element, const QgsReadWriteContext &context );
172 
176  QString dump() const override;
177 
181  QgsLayerTreeGroup *clone() const override SIP_FACTORY;
182 
187  void resolveReferences( const QgsProject *project, bool looseMatching = false ) override;
188 
192  void setItemVisibilityCheckedRecursive( bool checked ) override;
193 
198  bool isMutuallyExclusive() const;
199 
206  void setIsMutuallyExclusive( bool enabled, int initialChildIndex = -1 );
207 
208  protected slots:
209  void nodeVisibilityChanged( QgsLayerTreeNode *node );
210 
211  protected:
212 
216  void updateChildVisibilityMutuallyExclusive();
217 
218  QString mName;
219 
220  bool mChangingChildVisibility = false;
221 
223  bool mMutuallyExclusive = false;
224 
229  int mMutuallyExclusiveChildIndex = -1;
230 
231  private:
232 
233 #ifdef SIP_RUN
234 
238  QgsLayerTreeGroup( const QgsLayerTreeGroup &other );
239 #endif
240 
241 };
242 
243 
244 #endif // QGSLAYERTREEGROUP_H
Layer tree group node serves as a container for layers and further groups.
The class is used as a container of context for various read/write operations on other objects...
Base class for all map layer types.
Definition: qgsmaplayer.h:64
virtual QString name() const =0
Returns name of the node.
virtual void setName(const QString &name)=0
Set name of the node.
virtual void writeXml(QDomElement &parentElement, const QgsReadWriteContext &context)=0
Write layer tree to XML.
virtual QgsLayerTreeNode * clone() const =0
Create a copy of the node. Returns new instance.
virtual QString dump() const =0
Returns string with layer tree structure. For debug purposes only.
static QgsLayerTreeNode * readXml(QDomElement &element, const QgsReadWriteContext &context)
Read layer tree from XML.
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
This class is a base class for nodes in a layer tree.
Reads and writes project states.
Definition: qgsproject.h:89
#define SIP_FACTORY
Definition: qgis_sip.h:69
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.