QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 "qgsmaplayerref.h"
23 #include "qgsreadwritecontext.h"
24 #include "qgslegendpatchshape.h"
25 
26 class QgsMapLayer;
27 
43 class CORE_EXPORT QgsLayerTreeLayer : public QgsLayerTreeNode
44 {
45  Q_OBJECT
46  public:
47  explicit QgsLayerTreeLayer( QgsMapLayer *layer );
48 
49 #ifndef SIP_RUN
50  QgsLayerTreeLayer( const QgsLayerTreeLayer &other );
51 #endif
52 
56  explicit QgsLayerTreeLayer( const QString &layerId, const QString &name = QString(), const QString &source = QString(), const QString &provider = QString() );
57 
58 #ifdef SIP_RUN
59  SIP_PYOBJECT __repr__();
60  % MethodCode
61  QString str = QStringLiteral( "<QgsLayerTreeLayer: %1>" ).arg( sipCpp->name() );
62  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
63  % End
64 #endif
65 
71  QString layerId() const { return mRef.layerId; }
72 
82  QgsMapLayer *layer() const { return mRef.get(); }
83 
91  QString name() const override;
92 
100  void setName( const QString &n ) override;
101 
107  void setUseLayerName( bool use = true );
108 
113  bool useLayerName() const;
114 
119  static QgsLayerTreeLayer *readXml( QDomElement &element, const QgsReadWriteContext &context ) SIP_FACTORY;
120 
126  static QgsLayerTreeLayer *readXml( QDomElement &element, const QgsProject *project, const QgsReadWriteContext &context ) SIP_FACTORY;
127 
128  void writeXml( QDomElement &parentElement, const QgsReadWriteContext &context ) override;
129 
130  QString dump() const override;
131 
132  QgsLayerTreeLayer *clone() const override SIP_FACTORY;
133 
138  void resolveReferences( const QgsProject *project, bool looseMatching = false ) override;
139 
145  void setLabelExpression( const QString &expression );
146 
152  QString labelExpression() const { return mLabelExpression; }
153 
160  QgsLegendPatchShape patchShape() const;
161 
168  void setPatchShape( const QgsLegendPatchShape &shape );
169 
179  QSizeF patchSize() const { return mPatchSize; }
180 
190  void setPatchSize( QSizeF size ) { mPatchSize = size; }
191 
198  {
202  };
203 
212  LegendNodesSplitBehavior legendSplitBehavior() const { return mSplitBehavior; }
213 
222  void setLegendSplitBehavior( LegendNodesSplitBehavior behavior ) { mSplitBehavior = behavior; }
223 
224  signals:
225 
229  void layerLoaded();
230 
235  void layerWillBeUnloaded();
236 
237  protected:
238  void attachToLayer();
239 
243  QString mLayerName;
246 
248  bool mUseLayerName = true;
249 
250  private slots:
251 
256  void layerNameChanged();
257 
262  void layerWillBeDeleted();
263 
264  private:
265 
266 #ifdef SIP_RUN
267 
271  QgsLayerTreeLayer( const QgsLayerTreeLayer &other );
272 #endif
273 
274  QgsLegendPatchShape mPatchShape;
275  QSizeF mPatchSize;
276  LegendNodesSplitBehavior mSplitBehavior = UseDefaultLegendSetting;
277 
278  QgsLayerTreeLayer &operator=( const QgsLayerTreeLayer & ) = delete;
279 };
280 
281 
282 
283 #endif // QGSLAYERTREELAYER_H
QgsLayerTreeNode
This class is a base class for nodes in a layer tree.
Definition: qgslayertreenode.h:75
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:34
QgsLayerTreeLayer::layerId
QString layerId() const
Returns the ID for the map layer associated with this node.
Definition: qgslayertreelayer.h:71
qgsreadwritecontext.h
QgsLegendPatchShape
Represents a patch shape for use in map legends.
Definition: qgslegendpatchshape.h:33
QgsProject
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:103
QgsLayerTreeLayer::mLayerName
QString mLayerName
Layer name - only used if layer does not exist or if mUseLayerName is false.
Definition: qgslayertreelayer.h:243
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsLayerTreeLayer::mRef
QgsMapLayerRef mRef
Weak reference to the layer (or just it's ID if the reference is not resolved yet)
Definition: qgslayertreelayer.h:241
QgsLayerTreeLayer::setPatchSize
void setPatchSize(QSizeF size)
Sets the user (overridden) size for the legend node.
Definition: qgslayertreelayer.h:190
QgsLayerTreeLayer::UseDefaultLegendSetting
@ UseDefaultLegendSetting
Inherit default legend column splitting setting.
Definition: qgslayertreelayer.h:199
QgsLayerTreeNode::dump
virtual QString dump() const =0
Returns string with layer tree structure. For debug purposes only.
QgsLayerTreeLayer
Layer tree node points to a map layer.
Definition: qgslayertreelayer.h:43
QgsLayerTreeNode::writeXml
virtual void writeXml(QDomElement &parentElement, const QgsReadWriteContext &context)=0
Write layer tree to XML.
qgis_sip.h
QgsLayerTreeLayer::LegendNodesSplitBehavior
LegendNodesSplitBehavior
Legend node column split behavior.
Definition: qgslayertreelayer.h:197
QgsLayerTreeLayer::AllowSplittingLegendNodesOverMultipleColumns
@ AllowSplittingLegendNodesOverMultipleColumns
Allow splitting node's legend nodes across multiple columns.
Definition: qgslayertreelayer.h:200
qgslegendpatchshape.h
QgsLayerTreeLayer::layer
QgsMapLayer * layer() const
Returns the map layer associated with this node.
Definition: qgslayertreelayer.h:82
QgsLayerTreeNode::readXml
static QgsLayerTreeNode * readXml(QDomElement &element, const QgsReadWriteContext &context)
Read layer tree from XML.
Definition: qgslayertreenode.cpp:68
QgsLayerTreeLayer::PreventSplittingLegendNodesOverMultipleColumns
@ PreventSplittingLegendNodesOverMultipleColumns
Prevent splitting node's legend nodes across multiple columns.
Definition: qgslayertreelayer.h:201
QgsLayerTreeLayer::mLabelExpression
QString mLabelExpression
Expression to evaluate in the legend.
Definition: qgslayertreelayer.h:245
str
#define str(x)
Definition: qgis.cpp:37
QgsLayerTreeNode::setName
virtual void setName(const QString &name)=0
Set name of the node.
QgsMapLayer
Base class for all map layer types. This is the base class for all map layer types (vector,...
Definition: qgsmaplayer.h:72
qgslayertreenode.h
QgsLayerTreeNode::clone
virtual QgsLayerTreeNode * clone() const =0
Create a copy of the node. Returns new instance.
QgsLayerTreeNode::name
virtual QString name() const =0
Returns name of the node.
QgsLayerTreeLayer::legendSplitBehavior
LegendNodesSplitBehavior legendSplitBehavior() const
Returns the column split behavior for the node.
Definition: qgslayertreelayer.h:212
qgsmaplayerref.h
QgsLayerTreeLayer::setLegendSplitBehavior
void setLegendSplitBehavior(LegendNodesSplitBehavior behavior)
Sets the column split behavior for the node.
Definition: qgslayertreelayer.h:222
_LayerRef< QgsMapLayer >
QgsLayerTreeLayer::patchSize
QSizeF patchSize() const
Returns the user (overridden) size for the legend node.
Definition: qgslayertreelayer.h:179