QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 "qgslayertreenode.h"
20 
21 class QgsMapLayer;
22 class QgsLayerTreeLayer;
23 
31 class CORE_EXPORT QgsLayerTreeGroup : public QgsLayerTreeNode
32 {
33  Q_OBJECT
34  public:
35  QgsLayerTreeGroup( const QString& name = QString(), Qt::CheckState checked = Qt::Checked );
36  QgsLayerTreeGroup( const QgsLayerTreeGroup& other );
37 
39  QString name() const override;
41  void setName( const QString& n ) override;
42 
44  QgsLayerTreeGroup* insertGroup( int index, const QString& name );
46  QgsLayerTreeGroup* addGroup( const QString& name );
48  QgsLayerTreeLayer* insertLayer( int index, QgsMapLayer* layer );
50  QgsLayerTreeLayer* addLayer( QgsMapLayer* layer );
51 
53  void insertChildNodes( int index, const QList<QgsLayerTreeNode*>& nodes );
55  void insertChildNode( int index, QgsLayerTreeNode* node );
57  void addChildNode( QgsLayerTreeNode* node );
58 
60  void removeChildNode( QgsLayerTreeNode* node );
62  void removeLayer( QgsMapLayer* layer );
64  void removeChildren( int from, int count );
66  void removeChildrenGroupWithoutLayers();
68  void removeAllChildren();
69 
71  QgsLayerTreeLayer* findLayer( const QString& layerId ) const;
73  QList<QgsLayerTreeLayer*> findLayers() const;
75  QStringList findLayerIds() const;
77  QgsLayerTreeGroup* findGroup( const QString& name );
78 
85  static QgsLayerTreeGroup* readXML( QDomElement& element, bool looseMatch = false );
86 
88  virtual void writeXML( QDomElement& parentElement ) override;
94  void readChildrenFromXML( QDomElement& element, bool looseMatch = false );
95 
97  virtual QString dump() const override;
98 
100  virtual QgsLayerTreeGroup* clone() const override;
101 
103  Qt::CheckState isVisible() const { return mChecked; }
105  void setVisible( Qt::CheckState state );
106 
109  bool isMutuallyExclusive() const;
114  void setIsMutuallyExclusive( bool enabled, int initialChildIndex = -1 );
115 
116  protected slots:
117  void layerDestroyed();
118  void nodeVisibilityChanged( QgsLayerTreeNode* node );
119 
120  protected:
122  void updateVisibilityFromChildren();
124  void updateChildVisibility();
126  void updateChildVisibilityMutuallyExclusive();
127 
128  protected:
130  Qt::CheckState mChecked;
131 
133 
139 };
140 
141 
142 #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:49
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 writeXML(QDomElement &parentElement)=0
Write layer tree to XML.
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...
Qt::CheckState mChecked
static QgsLayerTreeNode * readXML(QDomElement &element, bool looseMatch=false)
Read layer tree from XML.
bool mMutuallyExclusive
Whether the group is mutually exclusive (i.e. only one child can be checked at a time) ...
Qt::CheckState isVisible() const
Return the check state of the group node.
Layer tree node points to a map layer.