QGIS API Documentation  2.99.0-Master (314842d)
qgslayertree.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgslayertree.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 QGSLAYERTREE_H
17 #define QGSLAYERTREE_H
18 
19 #include "qgslayertreenode.h"
20 #include "qgslayertreegroup.h"
21 #include "qgslayertreelayer.h"
22 
31 class CORE_EXPORT QgsLayerTree : public QgsLayerTreeGroup
32 {
33  Q_OBJECT
34 
35  public:
36 
42  static inline bool isGroup( QgsLayerTreeNode *node )
43  {
44  return node && node->nodeType() == QgsLayerTreeNode::NodeGroup;
45  }
46 
52  static inline bool isLayer( const QgsLayerTreeNode *node )
53  {
54  return node && node->nodeType() == QgsLayerTreeNode::NodeLayer;
55  }
56 
63  static inline QgsLayerTreeGroup *toGroup( QgsLayerTreeNode *node )
64  {
65  return static_cast<QgsLayerTreeGroup *>( node );
66  }
67 
74  static inline QgsLayerTreeLayer *toLayer( QgsLayerTreeNode *node )
75  {
76  return static_cast<QgsLayerTreeLayer *>( node );
77  }
78 
85  static inline const QgsLayerTreeLayer *toLayer( const QgsLayerTreeNode *node )
86  {
87  return static_cast< const QgsLayerTreeLayer *>( node );
88  }
89 
93  QgsLayerTree();
94 
98  QgsLayerTree( const QgsLayerTree &other );
99 
111  QList<QgsMapLayer *> customLayerOrder() const;
112 
124  void setCustomLayerOrder( const QList<QgsMapLayer *> &customLayerOrder );
125 
137  void setCustomLayerOrder( const QStringList &customLayerOrder );
138 
149  QList<QgsMapLayer *> layerOrder() const;
150 
159  bool hasCustomLayerOrder() const;
160 
169  void setHasCustomLayerOrder( bool hasCustomLayerOrder );
170 
179  static QgsLayerTree *readXml( QDomElement &element );
180 
187  void readLayerOrderFromXml( const QDomElement &doc );
188 
189  virtual void writeXml( QDomElement &parentElement ) override;
190 
191  virtual QgsLayerTree *clone() const override;
192 
198  void clear();
199 
200  signals:
201 
207  void customLayerOrderChanged();
208 
214  void layerOrderChanged();
215 
223  void hasCustomLayerOrderChanged( bool hasCustomLayerOrder );
224 
225  private slots:
226  void nodeAddedChildren( QgsLayerTreeNode *node, int indexFrom, int indexTo );
227  void nodeRemovedChildren();
228 
229  private:
230  void addMissingLayers();
231  QgsWeakMapLayerPointerList mCustomLayerOrder;
232  bool mHasCustomLayerOrder = false;
233 };
234 
235 #endif // QGSLAYERTREE_H
Layer tree group node serves as a container for layers and further groups.
static QgsLayerTreeLayer * toLayer(QgsLayerTreeNode *node)
Cast node to a layer.
Definition: qgslayertree.h:74
static bool isGroup(QgsLayerTreeNode *node)
Check whether the node is a valid group node.
Definition: qgslayertree.h:42
static QgsLayerTreeGroup * toGroup(QgsLayerTreeNode *node)
Cast node to a group.
Definition: qgslayertree.h:63
virtual void writeXml(QDomElement &parentElement) override
Write group (tree) as XML element <layer-tree-group> and add it to the given parent element...
static QgsLayerTreeGroup * readXml(QDomElement &element)
Read group (tree) from XML element <layer-tree-group> and return the newly created group (or null on ...
Namespace with helper functions for layer tree operations.
Definition: qgslayertree.h:31
static bool isLayer(const QgsLayerTreeNode *node)
Check whether the node is a valid layer node.
Definition: qgslayertree.h:52
This class is a base class for nodes in a layer tree.
static const QgsLayerTreeLayer * toLayer(const QgsLayerTreeNode *node)
Cast node to a layer.
Definition: qgslayertree.h:85
NodeType nodeType() const
Find out about type of the node. It is usually shorter to use convenience functions from QgsLayerTree...
Leaf node pointing to a layer.
virtual QgsLayerTreeGroup * clone() const override
Return a clone of the group. The children are cloned too.
QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList
A list of weak pointers to QgsMapLayers.
Definition: qgsmaplayer.h:983
Container of other groups and layers.
Layer tree node points to a map layer.