QGIS API Documentation  2.99.0-Master (a18066b)
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 "qgslayertreenode.h"
21 #include "qgsmaplayerref.h"
22 
23 class QgsMapLayer;
24 
39 class CORE_EXPORT QgsLayerTreeLayer : public QgsLayerTreeNode
40 {
41  Q_OBJECT
42  public:
43  explicit QgsLayerTreeLayer( QgsMapLayer* layer );
44  QgsLayerTreeLayer( const QgsLayerTreeLayer& other );
45 
46  explicit QgsLayerTreeLayer( const QString& layerId, const QString& name = QString() );
47 
48  QString layerId() const { return mRef.layerId; }
49 
50  QgsMapLayer* layer() const { return mRef.layer.data(); }
51 
54  QString name() const override;
57  void setName( const QString& n ) override;
58 
61  static QgsLayerTreeLayer* readXml( QDomElement& element );
65  static QgsLayerTreeLayer* readXml( QDomElement& element, const QgsProject* project );
66 
67  virtual void writeXml( QDomElement& parentElement ) override;
68 
69  virtual QString dump() const override;
70 
71  virtual QgsLayerTreeLayer* clone() const override;
72 
75  virtual void resolveReferences( const QgsProject* project ) override;
76 
77  private slots:
80  void layerNameChanged();
83  void layerWillBeDeleted();
84 
85  signals:
87  void layerLoaded();
90  void layerWillBeUnloaded();
91 
92  protected:
93  void attachToLayer();
94 
98  QString mLayerName;
99 };
100 
101 
102 
103 #endif // QGSLAYERTREELAYER_H
Base class for all map layer types.
Definition: qgsmaplayer.h:52
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) ...
virtual void resolveReferences(const QgsProject *project)=0
Turn textual references to layers into map layer object from project.
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:74
QgsMapLayer * layer() const
Layer tree node points to a map layer.