QGIS API Documentation  2.15.0-Master (af20121)
qgsmaplayerregistry.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmaplayerregistry.h
3  Singleton class for keeping track of loaded layers
4  -------------------
5  begin : Sun June 04 2004
6  copyright : (C) 2004 by Tim Sutton
7  email : [email protected]
8  ***************************************************************************/
9 
10 /***************************************************************************
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * *
17  ***************************************************************************/
18 
19 #ifndef QGSMAPLAYERREGISTRY_H
20 #define QGSMAPLAYERREGISTRY_H
21 
22 #include <QMap>
23 #include <QSet>
24 #include <QObject>
25 #include <QStringList>
26 class QString;
27 class QgsMapLayer;
28 
33 class CORE_EXPORT QgsMapLayerRegistry : public QObject
34 {
35  Q_OBJECT
36 
37  public:
39  static QgsMapLayerRegistry * instance();
40 
42  int count();
43 
45 
47  QgsMapLayer *mapLayer( const QString& theLayerId );
48 
50  QList<QgsMapLayer *> mapLayersByName( const QString& layerName );
51 
53  QMap<QString, QgsMapLayer*> mapLayers();
54 
65  template <typename T>
67  {
68  QVector<T> layers;
70  for ( ; layerIt != mMapLayers.constEnd(); ++layerIt )
71  {
72  T tLayer = qobject_cast<T>( layerIt.value() );
73  if ( tLayer )
74  {
75  layers << tLayer;
76  }
77  }
78  return layers;
79  }
80 
103  QList<QgsMapLayer *> addMapLayers( const QList<QgsMapLayer*>& theMapLayers,
104  bool addToLegend = true,
105  bool takeOwnership = true );
106 
132  QgsMapLayer* addMapLayer( QgsMapLayer * theMapLayer, bool addToLegend = true, bool takeOwnership = true );
133 
147  void removeMapLayers( const QStringList& theLayerIds );
148 
162  void removeMapLayers( const QList<QgsMapLayer*>& layers );
163 
177  void removeMapLayer( const QString& theLayerId );
178 
192  void removeMapLayer( QgsMapLayer* layer );
193 
200  void removeAllMapLayers();
201 
208  Q_DECL_DEPRECATED void clearAllLayerCaches() {}
210 
214  void reloadAllLayers();
215 
216  signals:
222  void layersWillBeRemoved( const QStringList& theLayerIds );
223 
229  void layersWillBeRemoved( const QList<QgsMapLayer*>& layers );
230 
238  void layerWillBeRemoved( const QString& theLayerId );
239 
247  void layerWillBeRemoved( QgsMapLayer* layer );
248 
254  void layersRemoved( const QStringList& theLayerIds );
255 
263  void layerRemoved( const QString& theLayerId );
264 
265 
272  void removeAll();
273 
283  void layersAdded( const QList<QgsMapLayer *>& theMapLayers );
284 
292  void layerWasAdded( QgsMapLayer* theMapLayer );
293 
302  void legendLayersAdded( const QList<QgsMapLayer*>& theMapLayers );
303 
304  protected:
305 #if 0
306 
309  void connectNotify( const char * signal ) override;
310 #endif
311 
312  private:
314  QgsMapLayerRegistry( QObject * parent = nullptr );
315 
316  QMap<QString, QgsMapLayer*> mMapLayers;
317  QSet<QgsMapLayer*> mOwnedLayers;
318 }; // class QgsMapLayerRegistry
319 
320 #endif //QgsMapLayerRegistry_H
321 
Base class for all map layer types.
Definition: qgsmaplayer.h:49
QVector< T > layers() const
Get map layers of a certain type.
const_iterator constBegin() const
const_iterator constEnd() const
This class tracks map layers that are currently loaded and provides a means to fetch a pointer to a m...
virtual void connectNotify(const char *signal)
const T value(const Key &key) const