QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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 removeAllChildren();
67 
69  QgsLayerTreeLayer* findLayer( const QString& layerId );
71  QList<QgsLayerTreeLayer*> findLayers() const;
73  QStringList findLayerIds() const;
75  QgsLayerTreeGroup* findGroup( const QString& name );
76 
78  static QgsLayerTreeGroup* readXML( QDomElement& element );
80  virtual void writeXML( QDomElement& parentElement );
82  void readChildrenFromXML( QDomElement& element );
83 
85  virtual QString dump() const;
86 
88  virtual QgsLayerTreeNode* clone() const;
89 
91  Qt::CheckState isVisible() const { return mChecked; }
93  void setVisible( Qt::CheckState state );
94 
95  protected slots:
96  void layerDestroyed();
97  void nodeVisibilityChanged( QgsLayerTreeNode* node );
98 
99  protected:
100  void updateVisibilityFromChildren();
101 
102  protected:
103  QString mName;
104  Qt::CheckState mChecked;
105 
107 };
108 
109 
110 #endif // QGSLAYERTREEGROUP_H
Layer tree group node serves as a container for layers and further groups.
Definition: qgslayertreegroup.h:31
static unsigned index
Definition: mersenne-twister.cpp:36
Base class for all map layer types.
Definition: qgsmaplayer.h:48
virtual QgsLayerTreeNode * clone() const =0
Create a copy of the node. Returns new instance.
QString mName
Definition: qgslayertreegroup.h:103
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.
bool mChangingChildVisibility
Definition: qgslayertreegroup.h:106
void setName(const QString &n)
Set group's name.
Definition: qgslayertreegroup.h:41
This class is a base class for nodes in a layer tree.
Definition: qgslayertreenode.h:63
static QgsLayerTreeNode * readXML(QDomElement &element)
Read layer tree from XML. Returns new instance.
Definition: qgslayertreenode.cpp:50
QString name() const
Get group's name.
Definition: qgslayertreegroup.h:39
Qt::CheckState isVisible() const
Return the check state of the group node.
Definition: qgslayertreegroup.h:91
Qt::CheckState mChecked
Definition: qgslayertreegroup.h:104
Layer tree node points to a map layer.
Definition: qgslayertreelayer.h:41