QGIS API Documentation  3.22.4-Białowieża (ce8e65e95e)
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 
48 #ifdef SIP_RUN
49  SIP_PYOBJECT __repr__();
50  % MethodCode
51  QString str = QStringLiteral( "<QgsLayerTreeGroup: %1>" ).arg( sipCpp->name() );
52  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
53  % End
54 #endif
55 
59  QString name() const override;
60 
64  void setName( const QString &n ) override;
65 
69  QgsLayerTreeGroup *insertGroup( int index, const QString &name );
70 
74  QgsLayerTreeGroup *addGroup( const QString &name );
75 
79  QgsLayerTreeLayer *insertLayer( int index, QgsMapLayer *layer );
80 
84  QgsLayerTreeLayer *addLayer( QgsMapLayer *layer );
85 
89  void insertChildNodes( int index, const QList<QgsLayerTreeNode *> &nodes SIP_TRANSFER );
90 
94  void insertChildNode( int index, QgsLayerTreeNode *node SIP_TRANSFER );
95 
99  void addChildNode( QgsLayerTreeNode *node SIP_TRANSFER );
100 
104  void removeChildNode( QgsLayerTreeNode *node );
105 
109  void removeLayer( QgsMapLayer *layer );
110 
114  void removeChildren( int from, int count );
115 
119  void removeChildrenGroupWithoutLayers();
120 
124  void removeAllChildren();
125 
130  QgsLayerTreeLayer *findLayer( QgsMapLayer *layer ) const;
131 
135  QgsLayerTreeLayer *findLayer( const QString &layerId ) const;
136 
140  QList<QgsLayerTreeLayer *> findLayers() const;
141 
145  QStringList findLayerIds() const;
146 
150  QgsLayerTreeGroup *findGroup( const QString &name );
151 
155  QList<QgsLayerTreeGroup *> findGroups( bool recursive = false ) const;
156 
161  static QgsLayerTreeGroup *readXml( QDomElement &element, const QgsReadWriteContext &context ) SIP_FACTORY;
162 
168  static QgsLayerTreeGroup *readXml( QDomElement &element, const QgsProject *project, const QgsReadWriteContext &context ) SIP_FACTORY;
169 
173  void writeXml( QDomElement &parentElement, const QgsReadWriteContext &context ) override;
174 
179  void readChildrenFromXml( QDomElement &element, const QgsReadWriteContext &context );
180 
184  QString dump() const override;
185 
189  QgsLayerTreeGroup *clone() const override SIP_FACTORY;
190 
195  void resolveReferences( const QgsProject *project, bool looseMatching = false ) override;
196 
200  void setItemVisibilityCheckedRecursive( bool checked ) override;
201 
206  bool isMutuallyExclusive() const;
207 
214  void setIsMutuallyExclusive( bool enabled, int initialChildIndex = -1 );
215 
216  protected slots:
217 
218  void nodeVisibilityChanged( QgsLayerTreeNode *node );
219 
220  protected:
221 
225  void updateChildVisibilityMutuallyExclusive();
226 
227  QString mName;
228 
229  bool mChangingChildVisibility = false;
230 
232  bool mMutuallyExclusive = false;
233 
238  int mMutuallyExclusiveChildIndex = -1;
239 
241  virtual void makeOrphan() override SIP_SKIP;
242 
243  private:
244 
245 #ifdef SIP_RUN
246 
250  QgsLayerTreeGroup( const QgsLayerTreeGroup &other );
251 #endif
252 
253  QgsLayerTreeGroup &operator= ( const QgsLayerTreeGroup & ) = delete;
254 
255 
256 };
257 
258 
259 #endif // QGSLAYERTREEGROUP_H
Layer tree group node serves as a container for layers and further groups.
Layer tree node points to a map layer.
This class is a base class for nodes in a layer tree.
virtual void setName(const QString &name)=0
Set name of the node.
virtual void makeOrphan()
Sets parent to nullptr and disconnects all external and forwarded signals.
virtual QString dump() const =0
Returns string with layer tree structure. For debug purposes only.
virtual void writeXml(QDomElement &parentElement, const QgsReadWriteContext &context)=0
Write layer tree to XML.
static QgsLayerTreeNode * readXml(QDomElement &element, const QgsReadWriteContext &context)
Read layer tree from XML.
virtual QgsLayerTreeNode * clone() const =0
Create a copy of the node. Returns new instance.
virtual QString name() const =0
Returns name of the node.
virtual void setItemVisibilityCheckedRecursive(bool checked)
Check or uncheck a node and all its children (taking into account exclusion rules)
virtual void resolveReferences(const QgsProject *project, bool looseMatching=false)=0
Turn textual references to layers into map layer object from project.
Base class for all map layer types.
Definition: qgsmaplayer.h:73
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:101
The class is used as a container of context for various read/write operations on other objects.
#define str(x)
Definition: qgis.cpp:37
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_FACTORY
Definition: qgis_sip.h:76