QGIS API Documentation  2.15.0-Master (02a0ebe)
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 { return mName; }
41  void setName( const QString& n ) { mName = n; }
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 
80  static QgsLayerTreeGroup* readXML( QDomElement& element );
82  virtual void writeXML( QDomElement& parentElement ) override;
84  void readChildrenFromXML( QDomElement& element );
85 
87  virtual QString dump() const override;
88 
90  virtual QgsLayerTreeGroup* clone() const override;
91 
93  Qt::CheckState isVisible() const { return mChecked; }
95  void setVisible( Qt::CheckState state );
96 
99  bool isMutuallyExclusive() const;
104  void setIsMutuallyExclusive( bool enabled, int initialChildIndex = -1 );
105 
106  protected slots:
107  void layerDestroyed();
108  void nodeVisibilityChanged( QgsLayerTreeNode* node );
109 
110  protected:
112  void updateVisibilityFromChildren();
114  void updateChildVisibility();
116  void updateChildVisibilityMutuallyExclusive();
117 
118  protected:
120  Qt::CheckState mChecked;
121 
123 
129 };
130 
131 
132 #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 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.
void setName(const QString &n)
Set group&#39;s name.
This class is a base class for nodes in a layer tree.
static QgsLayerTreeNode * readXML(QDomElement &element)
Read layer tree from XML. Returns new instance.
int mMutuallyExclusiveChildIndex
Keeps track which child has been most recently selected (so if the whole group is unchecked and check...
QString name() const
Get group&#39;s name.
Qt::CheckState isVisible() const
Return the check state of the group node.
Qt::CheckState mChecked
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.