QGIS API Documentation  2.99.0-Master (6a61179)
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 "qgslayertreenode.h"
20 
21 class QgsMapLayer;
22 
41 class CORE_EXPORT QgsLayerTreeLayer : public QgsLayerTreeNode
42 {
43  Q_OBJECT
44  public:
45  explicit QgsLayerTreeLayer( QgsMapLayer* layer );
46  QgsLayerTreeLayer( const QgsLayerTreeLayer& other );
47 
48  explicit QgsLayerTreeLayer( const QString& layerId, const QString& name = QString() );
49 
50  QString layerId() const { return mLayerId; }
51 
52  QgsMapLayer* layer() const { return mLayer; }
53 
56  QString name() const override;
59  void setName( const QString& n ) override;
60 
61  Qt::CheckState isVisible() const { return mVisible; }
62  void setVisible( Qt::CheckState visible );
63 
64  static QgsLayerTreeLayer* readXml( QDomElement& element );
65  virtual void writeXml( QDomElement& parentElement ) override;
66 
67  virtual QString dump() const override;
68 
69  virtual QgsLayerTreeLayer* clone() const override;
70 
71  protected slots:
72  void registryLayersAdded( const QList<QgsMapLayer*>& layers );
73  void registryLayersWillBeRemoved( const QStringList& layerIds );
76  void layerNameChanged();
77 
78  signals:
80  void layerLoaded();
83  void layerWillBeUnloaded();
84 
85  protected:
86  void attachToLayer();
87 
88  QString mLayerId;
89  QString mLayerName; // only used if layer does not exist
90  QgsMapLayer* mLayer; // not owned! may be null
91  Qt::CheckState mVisible;
92 };
93 
94 
95 
96 #endif // QGSLAYERTREELAYER_H
Base class for all map layer types.
Definition: qgsmaplayer.h:49
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.
Qt::CheckState isVisible() const
virtual QString dump() const =0
Return string with layer tree structure. For debug purposes only.
QString layerId() const
QgsMapLayer * mLayer
virtual void writeXml(QDomElement &parentElement)=0
Write layer tree to XML.
static QgsLayerTreeNode * readXml(QDomElement &element)
Read layer tree from XML. Returns new instance.
This class is a base class for nodes in a layer tree.
QgsMapLayer * layer() const
Qt::CheckState mVisible
Layer tree node points to a map layer.