QGIS API Documentation 3.30.0-'s-Hertogenbosch (f186b8efe0)
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#include "qgsmaplayerref.h"
23#include "qgsgrouplayer.h"
24
25class QgsMapLayer;
27class QgsGroupLayer;
28
40class CORE_EXPORT QgsLayerTreeGroup : public QgsLayerTreeNode
41{
42 Q_OBJECT
43 public:
44
48 QgsLayerTreeGroup( const QString &name = QString(), bool checked = true );
49
50#ifndef SIP_RUN
52#endif
53
54#ifdef SIP_RUN
55 SIP_PYOBJECT __repr__();
56 % MethodCode
57 QString str = QStringLiteral( "<QgsLayerTreeGroup: %1>" ).arg( sipCpp->name() );
58 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
59 % End
60#endif
61
65 QString name() const override;
66
70 void setName( const QString &n ) override;
71
75 QgsLayerTreeGroup *insertGroup( int index, const QString &name );
76
80 QgsLayerTreeGroup *addGroup( const QString &name );
81
85 QgsLayerTreeLayer *insertLayer( int index, QgsMapLayer *layer );
86
90 QgsLayerTreeLayer *addLayer( QgsMapLayer *layer );
91
95 void insertChildNodes( int index, const QList<QgsLayerTreeNode *> &nodes SIP_TRANSFER );
96
100 void insertChildNode( int index, QgsLayerTreeNode *node SIP_TRANSFER );
101
105 void addChildNode( QgsLayerTreeNode *node SIP_TRANSFER );
106
110 void removeChildNode( QgsLayerTreeNode *node );
111
115 void removeLayer( QgsMapLayer *layer );
116
120 void removeChildren( int from, int count );
121
125 void removeChildrenGroupWithoutLayers();
126
130 void removeAllChildren();
131
136 QgsLayerTreeLayer *findLayer( QgsMapLayer *layer ) const;
137
141 QgsLayerTreeLayer *findLayer( const QString &layerId ) const;
142
146 QList<QgsLayerTreeLayer *> findLayers() const;
147
160 void reorderGroupLayers( const QList< QgsMapLayer * > &order );
161
169 QList<QgsMapLayer *> layerOrderRespectingGroupLayers() const SIP_SKIP;
170
174 QStringList findLayerIds() const;
175
179 QgsLayerTreeGroup *findGroup( const QString &name );
180
184 QList<QgsLayerTreeGroup *> findGroups( bool recursive = false ) const;
185
190 static QgsLayerTreeGroup *readXml( QDomElement &element, const QgsReadWriteContext &context ) SIP_FACTORY;
191
197 static QgsLayerTreeGroup *readXml( QDomElement &element, const QgsProject *project, const QgsReadWriteContext &context ) SIP_FACTORY;
198
202 void writeXml( QDomElement &parentElement, const QgsReadWriteContext &context ) override;
203
208 void readChildrenFromXml( QDomElement &element, const QgsReadWriteContext &context );
209
213 QString dump() const override;
214
218 QgsLayerTreeGroup *clone() const override SIP_FACTORY;
219
224 void resolveReferences( const QgsProject *project, bool looseMatching = false ) override;
225
229 void setItemVisibilityCheckedRecursive( bool checked ) override;
230
235 bool isMutuallyExclusive() const;
236
243 void setIsMutuallyExclusive( bool enabled, int initialChildIndex = -1 );
244
253 QgsGroupLayer *groupLayer();
254
266 void setGroupLayer( QgsGroupLayer *layer );
267
282 QgsGroupLayer *convertToGroupLayer( const QgsGroupLayer::LayerOptions &options ) SIP_FACTORY;
283
284 protected slots:
285
286 void nodeVisibilityChanged( QgsLayerTreeNode *node );
287
288 protected:
289
293 void updateChildVisibilityMutuallyExclusive();
294
295 QString mName;
296
297 bool mChangingChildVisibility = false;
298
300 bool mMutuallyExclusive = false;
301
306 int mMutuallyExclusiveChildIndex = -1;
307
309 virtual void makeOrphan() override SIP_SKIP;
310
311 private:
312
313#ifdef SIP_RUN
314
318 QgsLayerTreeGroup( const QgsLayerTreeGroup &other );
319#endif
320
321 QgsLayerTreeGroup &operator= ( const QgsLayerTreeGroup & ) = delete;
322
323 void init();
324 void updateGroupLayers();
325 void refreshParentGroupLayerMembers();
326
327 QgsMapLayerRef mGroupLayer;
328};
329
330
331#endif // QGSLAYERTREEGROUP_H
A map layer which consists of a set of child layers, where all component layers are rendered as a sin...
Definition: qgsgrouplayer.h:42
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 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 QgsLayerTreeNode * clone() const =0
Create a copy of the node. Returns new instance.
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:105
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
Setting options for loading group layers.
Definition: qgsgrouplayer.h:52