QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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 
25 class QgsMapLayer;
26 
42 class CORE_EXPORT QgsLayerTreeLayer : public QgsLayerTreeNode
43 {
44  Q_OBJECT
45  public:
46  explicit QgsLayerTreeLayer( QgsMapLayer *layer );
47 
48 #ifndef SIP_RUN
49  QgsLayerTreeLayer( const QgsLayerTreeLayer &other );
50 #endif
51 
55  explicit QgsLayerTreeLayer( const QString &layerId, const QString &name = QString(), const QString &source = QString(), const QString &provider = QString() );
56 
62  QString layerId() const { return mRef.layerId; }
63 
73  QgsMapLayer *layer() const { return mRef.get(); }
74 
82  QString name() const override;
83 
91  void setName( const QString &n ) override;
92 
98  void setUseLayerName( bool use = true );
99 
104  bool useLayerName() const;
105 
110  static QgsLayerTreeLayer *readXml( QDomElement &element, const QgsReadWriteContext &context ) SIP_FACTORY;
111 
117  static QgsLayerTreeLayer *readXml( QDomElement &element, const QgsProject *project, const QgsReadWriteContext &context ) SIP_FACTORY;
118 
119  void writeXml( QDomElement &parentElement, const QgsReadWriteContext &context ) override;
120 
121  QString dump() const override;
122 
123  QgsLayerTreeLayer *clone() const override SIP_FACTORY;
124 
129  void resolveReferences( const QgsProject *project, bool looseMatching = false ) override;
130 
136  void setLabelExpression( const QString &expression );
137 
143  QString labelExpression() const { return mLabelExpression; }
144 
145  signals:
146 
150  void layerLoaded();
151 
156  void layerWillBeUnloaded();
157 
158  protected:
159  void attachToLayer();
160 
164  QString mLayerName;
167 
169  bool mUseLayerName = true;
170 
171  private slots:
172 
177  void layerNameChanged();
178 
183  void layerWillBeDeleted();
184 
185  private:
186 
187 #ifdef SIP_RUN
188 
192  QgsLayerTreeLayer( const QgsLayerTreeLayer &other );
193 #endif
194 };
195 
196 
197 
198 #endif // QGSLAYERTREELAYER_H
The class is used as a container of context for various read/write operations on other objects...
Base class for all map layer types.
Definition: qgsmaplayer.h:79
virtual QString name() const =0
Returns name of the node.
QString labelExpression() const
Returns the expression member of the LayerTreeNode.
virtual void setName(const QString &name)=0
Set name of the node.
virtual void writeXml(QDomElement &parentElement, const QgsReadWriteContext &context)=0
Write layer tree to XML.
virtual QgsLayerTreeNode * clone() const =0
Create a copy of the node. Returns new instance.
virtual QString dump() const =0
Returns string with layer tree structure. For debug purposes only.
static QgsLayerTreeNode * readXml(QDomElement &element, const QgsReadWriteContext &context)
Read layer tree from XML.
QString layerId() const
Returns the ID for the map layer associated with this node.
QgsMapLayerRef mRef
Weak reference to the layer (or just it's ID if the reference is not resolved yet) ...
QString mLayerName
Layer name - only used if layer does not exist or if mUseLayerName is false.
This class is a base class for nodes in a layer tree.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts, annotations, canvases, etc.
Definition: qgsproject.h:89
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsMapLayer * layer() const
Returns the map layer associated with this node.
QString mLabelExpression
Expression to evaluate in the legend.
virtual void resolveReferences(const QgsProject *project, bool looseMatching=false)=0
Turn textual references to layers into map layer object from project.
Layer tree node points to a map layer.