QGIS API Documentation  2.99.0-Master (d55fa22)
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 
40 class CORE_EXPORT QgsLayerTreeLayer : public QgsLayerTreeNode
41 {
42  Q_OBJECT
43  public:
44  explicit QgsLayerTreeLayer( QgsMapLayer *layer );
45 
46 #ifndef SIP_RUN
47  QgsLayerTreeLayer( const QgsLayerTreeLayer &other );
48 #endif
49 
53  explicit QgsLayerTreeLayer( const QString &layerId, const QString &name = QString(), const QString &source = QString(), const QString &provider = QString() );
54 
55  QString layerId() const { return mRef.layerId; }
56 
57  QgsMapLayer *layer() const { return mRef.get(); }
58 
63  QString name() const override;
64 
69  void setName( const QString &n ) override;
70 
75  static QgsLayerTreeLayer *readXml( QDomElement &element ) SIP_FACTORY;
76 
82  static QgsLayerTreeLayer *readXml( QDomElement &element, const QgsProject *project ) SIP_FACTORY;
83 
84  virtual void writeXml( QDomElement &parentElement ) override;
85 
86  virtual QString dump() const override;
87 
88  virtual QgsLayerTreeLayer *clone() const override SIP_FACTORY;
89 
94  virtual void resolveReferences( const QgsProject *project, bool looseMatching = false ) override;
95 
96  signals:
97 
101  void layerLoaded();
102 
107  void layerWillBeUnloaded();
108 
109  protected:
110  void attachToLayer();
111 
115  QString mLayerName;
116 
117  private slots:
118 
123  void layerNameChanged();
124 
129  void layerWillBeDeleted();
130 
131  private:
132 
133 #ifdef SIP_RUN
134 
138  QgsLayerTreeLayer( const QgsLayerTreeLayer &other );
139 #endif
140 };
141 
142 
143 
144 #endif // QGSLAYERTREELAYER_H
Base class for all map layer types.
Definition: qgsmaplayer.h:54
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:78
#define SIP_FACTORY
Definition: qgis_sip.h:57
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.