QGIS API Documentation  2.14.0-Essen
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  const QMap<QString, QgsMapLayer*> & mapLayers();
54 
77  QList<QgsMapLayer *> addMapLayers( const QList<QgsMapLayer*>& theMapLayers,
78  bool addToLegend = true,
79  bool takeOwnership = true );
80 
106  QgsMapLayer* addMapLayer( QgsMapLayer * theMapLayer, bool addToLegend = true, bool takeOwnership = true );
107 
121  void removeMapLayers( const QStringList& theLayerIds );
122 
136  void removeMapLayers( const QList<QgsMapLayer*>& layers );
137 
151  void removeMapLayer( const QString& theLayerId );
152 
166  void removeMapLayer( QgsMapLayer* layer );
167 
174  void removeAllMapLayers();
175 
182  Q_DECL_DEPRECATED void clearAllLayerCaches() {}
184 
188  void reloadAllLayers();
189 
190  signals:
196  void layersWillBeRemoved( const QStringList& theLayerIds );
197 
203  void layersWillBeRemoved( const QList<QgsMapLayer*>& layers );
204 
212  void layerWillBeRemoved( const QString& theLayerId );
213 
221  void layerWillBeRemoved( QgsMapLayer* layer );
222 
228  void layersRemoved( const QStringList& theLayerIds );
229 
237  void layerRemoved( const QString& theLayerId );
238 
239 
246  void removeAll();
247 
257  void layersAdded( const QList<QgsMapLayer *>& theMapLayers );
258 
266  void layerWasAdded( QgsMapLayer* theMapLayer );
267 
276  void legendLayersAdded( const QList<QgsMapLayer*>& theMapLayers );
277 
278  protected:
279 #if 0
280 
283  void connectNotify( const char * signal ) override;
284 #endif
285 
286  private:
288  QgsMapLayerRegistry( QObject * parent = nullptr );
289 
290  QMap<QString, QgsMapLayer*> mMapLayers;
291  QSet<QgsMapLayer*> mOwnedLayers;
292 }; // class QgsMapLayerRegistry
293 
294 #endif //QgsMapLayerRegistry_H
295 
Base class for all map layer types.
Definition: qgsmaplayer.h:49
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)