QGIS API Documentation 3.30.0-'s-Hertogenbosch (f186b8efe0)
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
32class CORE_EXPORT QgsLayerTree : public QgsLayerTreeGroup
33{
34 Q_OBJECT
35
36 public:
37
43 static inline bool isGroup( QgsLayerTreeNode *node )
44 {
45 return node && node->nodeType() == QgsLayerTreeNode::NodeGroup;
46 }
47
53 static inline bool isLayer( const QgsLayerTreeNode *node )
54 {
55 return node && node->nodeType() == QgsLayerTreeNode::NodeLayer;
56 }
57
65 {
66 return static_cast<QgsLayerTreeGroup *>( node );
67 }
68
76 {
77 return static_cast<QgsLayerTreeLayer *>( node );
78 }
79
86 static inline const QgsLayerTreeLayer *toLayer( const QgsLayerTreeNode *node ) SIP_SKIP
87 {
88 return static_cast< const QgsLayerTreeLayer *>( node );
89 }
90
95
96#ifdef SIP_RUN
97 SIP_PYOBJECT __repr__();
98 % MethodCode
99 // override parent QgsLayerTreeGroup __repr__ and resort back to default repr for QgsLayerTree -- there's no extra useful context we can show
100 QString str = QStringLiteral( "<qgis._core.QgsLayerTree object at 0x%1>" ).arg( reinterpret_cast<quintptr>( sipCpp ), 2 * QT_POINTER_SIZE, 16, QLatin1Char( '0' ) );
101 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
102 % End
103#endif
104
116 QList<QgsMapLayer *> customLayerOrder() const;
117
129 void setCustomLayerOrder( const QList<QgsMapLayer *> &customLayerOrder );
130
142 void setCustomLayerOrder( const QStringList &customLayerOrder ) SIP_PYNAME( setCustomLayerOrderByIds );
143
154 QList<QgsMapLayer *> layerOrder() const;
155
164 bool hasCustomLayerOrder() const;
165
174 void setHasCustomLayerOrder( bool hasCustomLayerOrder );
175
184 static QgsLayerTree *readXml( QDomElement &element, const QgsReadWriteContext &context );
185
192 void readLayerOrderFromXml( const QDomElement &doc );
193
194 void writeXml( QDomElement &parentElement, const QgsReadWriteContext &context ) override;
195
196 QgsLayerTree *clone() const override SIP_FACTORY;
197
203 void clear();
204
205 signals:
206
212 void customLayerOrderChanged();
213
219 void layerOrderChanged();
220
228 void hasCustomLayerOrderChanged( bool hasCustomLayerOrder );
229
230 private slots:
231 void nodeAddedChildren( QgsLayerTreeNode *node, int indexFrom, int indexTo );
232 void nodeRemovedChildren();
233
234 private:
236 QgsLayerTree( const QgsLayerTree &other );
237
238 void init();
239
240 void addMissingLayers();
241 QgsWeakMapLayerPointerList mCustomLayerOrder;
242 bool mHasCustomLayerOrder = false;
243
244 QgsLayerTree &operator= ( const QgsLayerTree & ) = delete;
245};
246
247#endif // QGSLAYERTREE_H
Layer tree group node serves as a container for layers and further groups.
void writeXml(QDomElement &parentElement, const QgsReadWriteContext &context) override
Write group (tree) as XML element <layer-tree-group> and add it to the given parent element.
QgsLayerTreeGroup * clone() const override
Returns a clone of the group.
static QgsLayerTreeGroup * readXml(QDomElement &element, const QgsReadWriteContext &context)
Read group (tree) from XML element <layer-tree-group> and return the newly created group (or nullptr ...
Layer tree node points to a map layer.
This class is a base class for nodes in a layer tree.
@ NodeGroup
Container of other groups and layers.
@ NodeLayer
Leaf node pointing to a layer.
NodeType nodeType() const
Find out about type of the node. It is usually shorter to use convenience functions from QgsLayerTree...
Namespace with helper functions for layer tree operations.
Definition: qgslayertree.h:33
static QgsLayerTreeLayer * toLayer(QgsLayerTreeNode *node)
Cast node to a layer.
Definition: qgslayertree.h:75
static bool isLayer(const QgsLayerTreeNode *node)
Check whether the node is a valid layer node.
Definition: qgslayertree.h:53
static const QgsLayerTreeLayer * toLayer(const QgsLayerTreeNode *node)
Cast node to a layer.
Definition: qgslayertree.h:86
static bool isGroup(QgsLayerTreeNode *node)
Check whether the node is a valid group node.
Definition: qgslayertree.h:43
static QgsLayerTreeGroup * toGroup(QgsLayerTreeNode *node)
Cast node to a group.
Definition: qgslayertree.h:64
The class is used as a container of context for various read/write operations on other objects.
#define str(x)
Definition: qgis.cpp:37
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_PYNAME(name)
Definition: qgis_sip.h:81
#define SIP_FACTORY
Definition: qgis_sip.h:76
QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList
A list of weak pointers to QgsMapLayers.
Definition: qgsmaplayer.h:2213