QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
Loading...
Searching...
No Matches
qgslayertreelayer.h
Go to the documentation of this file.
1/***************************************************************************
2 qgslayertreelayer.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 QGSLAYERTREELAYER_H
17#define QGSLAYERTREELAYER_H
18
19#include "qgis_core.h"
20#include "qgis_sip.h"
21#include "qgslayertreenode.h"
22#include "qgslegendpatchshape.h"
23#include "qgsmaplayerref.h"
24#include "qgsreadwritecontext.h"
25
26#include <QString>
27
28using namespace Qt::StringLiterals;
29
30class QgsMapLayer;
31
46class CORE_EXPORT QgsLayerTreeLayer : public QgsLayerTreeNode
47{
48 Q_OBJECT
49 public:
51
52#ifndef SIP_RUN
54#endif
55
59 explicit QgsLayerTreeLayer( const QString &layerId, const QString &name = QString(), const QString &source = QString(), const QString &provider = QString() );
60
61#ifdef SIP_RUN
62 // clang-format off
63 SIP_PYOBJECT __repr__();
64 % MethodCode
65 QString str = u"<QgsLayerTreeLayer: %1>"_s.arg( sipCpp->name() );
66 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
67 % End
68// clang-format on
69#endif
70
76 QString layerId() const
77 {
78 return mRef.layerId;
79 }
80
90 QgsMapLayer *layer() const { return mRef.get(); }
91
98 QString name() const override;
99
106 void setName( const QString &n ) override;
107
113 void setUseLayerName( bool use = true );
114
119 bool useLayerName() const;
120
125 static QgsLayerTreeLayer *readXml( QDomElement &element, const QgsReadWriteContext &context ) SIP_FACTORY; // cppcheck-suppress duplInheritedMember
126
131 static QgsLayerTreeLayer *readXml( QDomElement &element, const QgsProject *project, const QgsReadWriteContext &context ) SIP_FACTORY;
132
133 void writeXml( QDomElement &parentElement, const QgsReadWriteContext &context ) override;
134
135 QString dump() const override;
136
137 QgsLayerTreeLayer *clone() const override SIP_FACTORY;
138
142 void resolveReferences( const QgsProject *project, bool looseMatching = false ) override;
143
149 void setLabelExpression( const QString &expression );
150
156 QString labelExpression() const { return mLabelExpression; }
157
164 QgsLegendPatchShape patchShape() const;
165
172 void setPatchShape( const QgsLegendPatchShape &shape );
173
183 QSizeF patchSize() const { return mPatchSize; }
184
194 void setPatchSize( QSizeF size ) { mPatchSize = size; }
195
207
216 LegendNodesSplitBehavior legendSplitBehavior() const { return mSplitBehavior; }
217
226 void setLegendSplitBehavior( LegendNodesSplitBehavior behavior ) { mSplitBehavior = behavior; }
227
228 signals:
229
234
239
240 protected:
241 void attachToLayer();
242
246 QString mLayerName;
249
251 bool mUseLayerName = true;
252
253 private slots:
254
258 void layerNameChanged();
259
263 void layerWillBeDeleted();
264
265 private:
266#ifdef SIP_RUN
267
271 QgsLayerTreeLayer( const QgsLayerTreeLayer &other );
272#endif
273
274 QgsLegendPatchShape mPatchShape;
275 QSizeF mPatchSize;
277
278 QgsLayerTreeLayer &operator=( const QgsLayerTreeLayer & ) = delete;
279};
280
281
282#endif // QGSLAYERTREELAYER_H
Layer tree node points to a map layer.
QString layerId() const
Returns the ID for the map layer associated with this node.
QString mLabelExpression
Expression to evaluate in the legend.
void setPatchSize(QSizeF size)
Sets the user (overridden) size for the legend node.
QgsMapLayerRef mRef
Weak reference to the layer (or just it's ID if the reference is not resolved yet).
void layerWillBeUnloaded()
Emitted when a previously available layer got unloaded (from layer registry).
QString labelExpression() const
Returns the expression member of the LayerTreeNode.
LegendNodesSplitBehavior
Legend node column split behavior.
@ AllowSplittingLegendNodesOverMultipleColumns
Allow splitting node's legend nodes across multiple columns.
@ PreventSplittingLegendNodesOverMultipleColumns
Prevent splitting node's legend nodes across multiple columns.
@ UseDefaultLegendSetting
Inherit default legend column splitting setting.
QgsLayerTreeLayer(QgsMapLayer *layer)
QString name() const override
Returns the layer's name.
void layerLoaded()
Emitted when a previously unavailable layer got loaded.
void setLegendSplitBehavior(LegendNodesSplitBehavior behavior)
Sets the column split behavior for the node.
LegendNodesSplitBehavior legendSplitBehavior() const
Returns the column split behavior for the node.
QgsMapLayer * layer() const
Returns the map layer associated with this node.
QString mLayerName
Layer name - only used if layer does not exist or if mUseLayerName is false.
QSizeF patchSize() const
Returns the user (overridden) size for the legend node.
virtual void setName(const QString &name)=0
Set name of the node.
virtual QString dump() const =0
Returns string with layer tree structure. For debug purposes only.
virtual void writeXml(QDomElement &parentElement, const QgsReadWriteContext &context)=0
Write layer tree to XML.
static QgsLayerTreeNode * readXml(QDomElement &element, const QgsReadWriteContext &context)
Read layer tree from XML.
virtual QString name() const =0
Returns name of the node.
QgsLayerTreeNode(NodeType t, bool checked=true)
Constructor.
virtual QgsLayerTreeNode * clone() const =0
Create a copy of the node. Returns new instance.
Represents a patch shape for use in map legends.
Base class for all map layer types.
Definition qgsmaplayer.h:83
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:113
A container for the context for various read/write operations on objects.
#define SIP_FACTORY
Definition qgis_sip.h:83
_LayerRef< QgsMapLayer > QgsMapLayerRef