QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
Loading...
Searching...
No Matches
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
31class CORE_EXPORT QgsLayerTree : public QgsLayerTreeGroup
32{
33 Q_OBJECT
34
35 public:
36
41 static inline bool isGroup( QgsLayerTreeNode *node )
42 {
43 return node && node->nodeType() == QgsLayerTreeNode::NodeGroup;
44 }
45
50 static inline bool isLayer( const QgsLayerTreeNode *node )
51 {
52 return node && node->nodeType() == QgsLayerTreeNode::NodeLayer;
53 }
54
61 {
62 return qobject_cast<QgsLayerTreeGroup *>( node );
63 }
64
71 {
72 return qobject_cast<QgsLayerTreeLayer *>( node );
73 }
74
80 static inline const QgsLayerTreeLayer *toLayer( const QgsLayerTreeNode *node ) SIP_SKIP
81 {
82 return qobject_cast< const QgsLayerTreeLayer *>( node );
83 }
84
89
90#ifdef SIP_RUN
91 SIP_PYOBJECT __repr__();
92 % MethodCode
93 // override parent QgsLayerTreeGroup __repr__ and resort back to default repr for QgsLayerTree -- there's no extra useful context we can show
94 QString str = QStringLiteral( "<qgis._core.QgsLayerTree object at 0x%1>" ).arg( reinterpret_cast<quintptr>( sipCpp ), 2 * QT_POINTER_SIZE, 16, QLatin1Char( '0' ) );
95 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
96 % End
97#endif
98
109 QList<QgsMapLayer *> customLayerOrder() const;
110
121 void setCustomLayerOrder( const QList<QgsMapLayer *> &customLayerOrder );
122
133 void setCustomLayerOrder( const QStringList &customLayerOrder ) SIP_PYNAME( setCustomLayerOrderByIds );
134
144 QList<QgsMapLayer *> layerOrder() const;
145
153 bool hasCustomLayerOrder() const;
154
162 void setHasCustomLayerOrder( bool hasCustomLayerOrder );
163
171 static QgsLayerTree *readXml( QDomElement &element, const QgsReadWriteContext &context ); // cppcheck-suppress duplInheritedMember
172
178 void readLayerOrderFromXml( const QDomElement &doc );
179
180 void writeXml( QDomElement &parentElement, const QgsReadWriteContext &context ) override;
181
182 QgsLayerTree *clone() const override SIP_FACTORY;
183
188 void clear();
189
190 signals:
191
196 void customLayerOrderChanged();
197
202 void layerOrderChanged();
203
210 void hasCustomLayerOrderChanged( bool hasCustomLayerOrder );
211
212 private slots:
213 void nodeAddedChildren( QgsLayerTreeNode *node, int indexFrom, int indexTo );
214 void nodeRemovedChildren();
215
216 private:
217 QgsLayerTree( const QgsLayerTree &other );
218
219 void init();
220
221 void addMissingLayers();
222 QgsWeakMapLayerPointerList mCustomLayerOrder;
223 bool mHasCustomLayerOrder = false;
224
225 QgsLayerTree &operator= ( const QgsLayerTree & ) = delete;
226};
227
228#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.
static QgsLayerTreeLayer * toLayer(QgsLayerTreeNode *node)
Cast node to a layer.
static bool isLayer(const QgsLayerTreeNode *node)
Check whether the node is a valid layer node.
static const QgsLayerTreeLayer * toLayer(const QgsLayerTreeNode *node)
Cast node to a layer.
static bool isGroup(QgsLayerTreeNode *node)
Check whether the node is a valid group node.
static QgsLayerTreeGroup * toGroup(QgsLayerTreeNode *node)
Cast node to a group.
The class is used as a container of context for various read/write operations on other objects.
#define str(x)
Definition qgis.cpp:39
#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.