QGIS API Documentation  2.14.0-Essen
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 
54  QString layerName() const;
55  void setLayerName( const QString& n );
56 
57  Qt::CheckState isVisible() const { return mVisible; }
58  void setVisible( Qt::CheckState visible );
59 
60  static QgsLayerTreeLayer* readXML( QDomElement& element );
61  virtual void writeXML( QDomElement& parentElement ) override;
62 
63  virtual QString dump() const override;
64 
65  virtual QgsLayerTreeLayer* clone() const override;
66 
67  protected slots:
68  void registryLayersAdded( const QList<QgsMapLayer*>& layers );
69  void registryLayersWillBeRemoved( const QStringList& layerIds );
70 
71  signals:
73  void layerLoaded();
76  void layerWillBeUnloaded();
77 
78  protected:
79  void attachToLayer();
80 
82  QString mLayerName; // only used if layer does not exist
83  QgsMapLayer* mLayer; // not owned! may be null
84  Qt::CheckState mVisible;
85 };
86 
87 
88 
89 #endif // QGSLAYERTREELAYER_H
Base class for all map layer types.
Definition: qgsmaplayer.h:49
QgsMapLayer * layer() const
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.
virtual void writeXML(QDomElement &parentElement)=0
Write layer tree to XML.
QgsMapLayer * mLayer
Qt::CheckState isVisible() const
This class is a base class for nodes in a layer tree.
QString layerId() const
static QgsLayerTreeNode * readXML(QDomElement &element)
Read layer tree from XML. Returns new instance.
Qt::CheckState mVisible
Layer tree node points to a map layer.