QGIS API Documentation  2.99.0-Master (0a63d1f)
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 "qgslayertreenode.h"
21 
22 class QgsMapLayer;
23 class QgsLayerTreeLayer;
24 
32 class CORE_EXPORT QgsLayerTreeGroup : public QgsLayerTreeNode
33 {
34  Q_OBJECT
35  public:
37  QgsLayerTreeGroup( const QString& name = QString(), bool checked = true );
38  QgsLayerTreeGroup( const QgsLayerTreeGroup& other );
39 
41  QString name() const override;
43  void setName( const QString& n ) override;
44 
46  QgsLayerTreeGroup* insertGroup( int index, const QString& name );
48  QgsLayerTreeGroup* addGroup( const QString& name );
50  QgsLayerTreeLayer* insertLayer( int index, QgsMapLayer* layer );
52  QgsLayerTreeLayer* addLayer( QgsMapLayer* layer );
53 
55  void insertChildNodes( int index, const QList<QgsLayerTreeNode*>& nodes );
57  void insertChildNode( int index, QgsLayerTreeNode* node );
59  void addChildNode( QgsLayerTreeNode* node );
60 
62  void removeChildNode( QgsLayerTreeNode* node );
64  void removeLayer( QgsMapLayer* layer );
66  void removeChildren( int from, int count );
68  void removeChildrenGroupWithoutLayers();
70  void removeAllChildren();
71 
74  QgsLayerTreeLayer* findLayer( QgsMapLayer* layer ) const;
76  QgsLayerTreeLayer* findLayer( const QString& layerId ) const;
78  QList<QgsLayerTreeLayer*> findLayers() const;
80  QStringList findLayerIds() const;
82  QgsLayerTreeGroup* findGroup( const QString& name );
83 
85  static QgsLayerTreeGroup* readXml( QDomElement& element );
87  virtual void writeXml( QDomElement& parentElement ) override;
89  void readChildrenFromXml( QDomElement& element );
90 
92  virtual QString dump() const override;
93 
95  virtual QgsLayerTreeGroup* clone() const override;
96 
98  virtual void setItemVisibilityCheckedRecursive( bool checked ) override;
99 
102  bool isMutuallyExclusive() const;
107  void setIsMutuallyExclusive( bool enabled, int initialChildIndex = -1 );
108 
109  protected slots:
110  void nodeVisibilityChanged( QgsLayerTreeNode* node );
111 
112  protected:
113 
115  void updateChildVisibilityMutuallyExclusive();
116 
117  protected:
118  QString mName;
119 
121 
127 };
128 
129 
130 #endif // QGSLAYERTREEGROUP_H
Layer tree group node serves as a container for layers and further groups.
static unsigned index
Base class for all map layer types.
Definition: qgsmaplayer.h:50
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) ...
virtual void writeXml(QDomElement &parentElement)=0
Write layer tree to XML.
static QgsLayerTreeNode * readXml(QDomElement &element)
Read layer tree from XML. Returns new instance.
This class is a base class for nodes in a layer tree.
int mMutuallyExclusiveChildIndex
Keeps track which child has been most recently selected (so if the whole group is unchecked and check...
bool mMutuallyExclusive
Whether the group is mutually exclusive (i.e. only one child can be checked at a time) ...
Layer tree node points to a map layer.