QGIS API Documentation  2.99.0-Master (5b186ae)
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 
64  {
65  return static_cast<QgsLayerTreeGroup *>( node );
66  }
67 
75  {
76  return static_cast<QgsLayerTreeLayer *>( node );
77  }
78 
85  static inline const QgsLayerTreeLayer *toLayer( const QgsLayerTreeNode *node ) SIP_SKIP
86  {
87  return static_cast< const QgsLayerTreeLayer *>( node );
88  }
89 
93  QgsLayerTree();
94 
106  QList<QgsMapLayer *> customLayerOrder() const;
107 
119  void setCustomLayerOrder( const QList<QgsMapLayer *> &customLayerOrder );
120 
132  void setCustomLayerOrder( const QStringList &customLayerOrder ) SIP_PYNAME( setCustomLayerOrderByIds );
133 
144  QList<QgsMapLayer *> layerOrder() const;
145 
154  bool hasCustomLayerOrder() const;
155 
164  void setHasCustomLayerOrder( bool hasCustomLayerOrder );
165 
174  static QgsLayerTree *readXml( QDomElement &element );
175 
182  void readLayerOrderFromXml( const QDomElement &doc );
183 
184  virtual void writeXml( QDomElement &parentElement ) override;
185 
186  virtual QgsLayerTree *clone() const override SIP_FACTORY;
187 
193  void clear();
194 
195  signals:
196 
202  void customLayerOrderChanged();
203 
209  void layerOrderChanged();
210 
218  void hasCustomLayerOrderChanged( bool hasCustomLayerOrder );
219 
220  private slots:
221  void nodeAddedChildren( QgsLayerTreeNode *node, int indexFrom, int indexTo );
222  void nodeRemovedChildren();
223 
224  private:
226  QgsLayerTree( const QgsLayerTree &other );
227  void addMissingLayers();
228  QgsWeakMapLayerPointerList mCustomLayerOrder;
229  bool mHasCustomLayerOrder = false;
230 };
231 
232 #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
#define SIP_SKIP
Definition: qgis_sip.h:119
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.
#define SIP_FACTORY
Definition: qgis_sip.h:69
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.
QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList
A list of weak pointers to QgsMapLayers.
Definition: qgsmaplayer.h:1105
Container of other groups and layers.
Layer tree node points to a map layer.
#define SIP_PYNAME(name)
Definition: qgis_sip.h:74