QGIS API Documentation  2.99.0-Master (9fdd060)
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.h"
21 #include "qgslayertreenode.h"
22 #include "qgsmaplayerref.h"
23 
24 class QgsMapLayer;
25 
41 class CORE_EXPORT QgsLayerTreeLayer : public QgsLayerTreeNode
42 {
43  Q_OBJECT
44  public:
45  explicit QgsLayerTreeLayer( QgsMapLayer *layer );
46 
47 #ifndef SIP_RUN
48  QgsLayerTreeLayer( const QgsLayerTreeLayer &other );
49 #endif
50 
54  explicit QgsLayerTreeLayer( const QString &layerId, const QString &name = QString(), const QString &source = QString(), const QString &provider = QString() );
55 
56  QString layerId() const { return mRef.layerId; }
57 
58  QgsMapLayer *layer() const { return mRef.get(); }
59 
64  QString name() const override;
65 
70  void setName( const QString &n ) override;
71 
76  static QgsLayerTreeLayer *readXml( QDomElement &element ) SIP_FACTORY;
77 
83  static QgsLayerTreeLayer *readXml( QDomElement &element, const QgsProject *project ) SIP_FACTORY;
84 
85  virtual void writeXml( QDomElement &parentElement ) override;
86 
87  virtual QString dump() const override;
88 
89  virtual QgsLayerTreeLayer *clone() const override SIP_FACTORY;
90 
95  virtual void resolveReferences( const QgsProject *project, bool looseMatching = false ) override;
96 
97  signals:
98 
102  void layerLoaded();
103 
108  void layerWillBeUnloaded();
109 
110  protected:
111  void attachToLayer();
112 
116  QString mLayerName;
117 
118  private slots:
119 
124  void layerNameChanged();
125 
130  void layerWillBeDeleted();
131 
132  private:
133 
134 #ifdef SIP_RUN
135 
139  QgsLayerTreeLayer( const QgsLayerTreeLayer &other );
140 #endif
141 };
142 
143 
144 
145 #endif // QGSLAYERTREELAYER_H
Base class for all map layer types.
Definition: qgsmaplayer.h:56
virtual QString name() const =0
Return name of the node.
virtual void setName(const QString &name)=0
Set name of the node.
virtual QgsLayerTreeNode * clone() const =0
Create a copy of the node. Returns new instance.
virtual QString dump() const =0
Return string with layer tree structure. For debug purposes only.
QString layerId() const
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.
virtual void writeXml(QDomElement &parentElement)=0
Write layer tree to XML.
static QgsLayerTreeNode * readXml(QDomElement &element)
Read layer tree from XML.
This class is a base class for nodes in a layer tree.
Reads and writes project states.
Definition: qgsproject.h:81
#define SIP_FACTORY
Definition: qgis_sip.h:69
QgsMapLayer * layer() const
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.