QGIS API Documentation  2.99.0-Master (b8fd1fd)
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 
86  static QgsLayerTreeGroup *readXml( QDomElement &element );
90  static QgsLayerTreeGroup *readXml( QDomElement &element, const QgsProject *project );
91 
93  virtual void writeXml( QDomElement &parentElement ) override;
96  void readChildrenFromXml( QDomElement &element );
97 
99  virtual QString dump() const override;
100 
102  virtual QgsLayerTreeGroup *clone() const override;
103 
106  virtual void resolveReferences( const QgsProject *project ) override;
107 
109  virtual void setItemVisibilityCheckedRecursive( bool checked ) override;
110 
113  bool isMutuallyExclusive() const;
118  void setIsMutuallyExclusive( bool enabled, int initialChildIndex = -1 );
119 
120  protected slots:
121  void nodeVisibilityChanged( QgsLayerTreeNode *node );
122 
123  protected:
124 
126  void updateChildVisibilityMutuallyExclusive();
127 
128  protected:
129  QString mName;
130 
132 
138 };
139 
140 
141 #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:52
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 resolveReferences(const QgsProject *project)=0
Turn textual references to layers into map layer object from project.
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.
This class is a base class for nodes in a layer tree.
Reads and writes project states.
Definition: qgsproject.h:75
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.