QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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, 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 QgsLayerTreeNode* clone() const override;
91 
93  Qt::CheckState isVisible() const { return mChecked; }
95  void setVisible( Qt::CheckState state );
96 
97  protected slots:
98  void layerDestroyed();
99  void nodeVisibilityChanged( QgsLayerTreeNode* node );
100 
101  protected:
102  void updateVisibilityFromChildren();
103 
104  protected:
105  QString mName;
106  Qt::CheckState mChecked;
107 
109 };
110 
111 
112 #endif // QGSLAYERTREEGROUP_H