QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 
48  {
55  };
56 
57  explicit QgsLayerTreeLayer( QgsMapLayer* layer );
58  QgsLayerTreeLayer( const QgsLayerTreeLayer& other );
59 
66  static QgsLayerTreeLayer* createLayerFromParams( const LayerMatchParams& source );
67 
68  explicit QgsLayerTreeLayer( const QString& layerId, const QString& name = QString() );
69 
70  QString layerId() const { return mLayerId; }
71 
72  QgsMapLayer* layer() const { return mLayer; }
73 
76  QString name() const override;
79  void setName( const QString& n ) override;
80 
87  void attachToSource( const LayerMatchParams &source );
88 
89  QString layerName() const;
90  void setLayerName( const QString& n );
91 
92  Qt::CheckState isVisible() const { return mVisible; }
93  void setVisible( Qt::CheckState visible );
94 
100  static QgsLayerTreeLayer* readXML( QDomElement& element, bool looseMatch = false );
101 
102  virtual void writeXML( QDomElement& parentElement ) override;
103 
104  virtual QString dump() const override;
105 
106  virtual QgsLayerTreeLayer* clone() const override;
107 
108  protected slots:
109  void registryLayersAdded( const QList<QgsMapLayer*>& layers );
110  void registryLayersWillBeRemoved( const QStringList& layerIds );
113  void layerNameChanged();
114 
115  signals:
117  void layerLoaded();
120  void layerWillBeUnloaded();
121 
122  protected:
123  void attachToLayer();
124 
126  QString mLayerName; // only used if layer does not exist
127 
131 
132  QgsMapLayer* mLayer; // not owned! may be null
133  Qt::CheckState mVisible;
134 
135  private:
136 
137  bool layerMatchesSource( QgsMapLayer *layer, const LayerMatchParams& params ) const;
138 };
139 
140 
141 
142 #endif // QGSLAYERTREELAYER_H
Base class for all map layer types.
Definition: qgsmaplayer.h:49
LayerMatchParams mLooseMatchParams
Only used when loosely matching to layers - eg when creating a composer legend from template If set t...
Qt::CheckState isVisible() const
QString layerId() const
QgsMapLayer * mLayer
This class is a base class for nodes in a layer tree.
QgsMapLayer * layer() const
QString source
Layer public source.
Parameters for loose layer matching.
Qt::CheckState mVisible
Layer tree node points to a map layer.