QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
27 #include "qgssingleton.h"
28 class QString;
29 class QgsMapLayer;
30 
35 class CORE_EXPORT QgsMapLayerRegistry : public QObject, public QgsSingleton<QgsMapLayerRegistry>
36 {
37  Q_OBJECT
38 
39  public:
41  int count();
42 
44 
46  QgsMapLayer *mapLayer( QString theLayerId );
47 
49  QList<QgsMapLayer *> mapLayersByName( QString layerName );
50 
52  const QMap<QString, QgsMapLayer*> & mapLayers();
53 
76  QList<QgsMapLayer *> addMapLayers( QList<QgsMapLayer *> theMapLayers,
77  bool addToLegend = true,
78  bool takeOwnership = true );
79 
105  QgsMapLayer* addMapLayer( QgsMapLayer * theMapLayer, bool addToLegend = true, bool takeOwnership = true );
106 
120  void removeMapLayers( QStringList theLayerIds );
121 
135  void removeMapLayer( const QString& theLayerId );
136 
143  void removeAllMapLayers();
144 
151 
152  Q_DECL_DEPRECATED void clearAllLayerCaches();
153 
157  void reloadAllLayers();
158 
159  signals:
165  void layersWillBeRemoved( QStringList theLayerIds );
166 
174  void layerWillBeRemoved( QString theLayerId );
175 
181  void layersRemoved( QStringList theLayerIds );
182 
190  void layerRemoved( QString theLayerId );
191 
192 
199  void removeAll();
200 
210  void layersAdded( QList<QgsMapLayer *> theMapLayers );
211 
219  void layerWasAdded( QgsMapLayer* theMapLayer );
220 
229  void legendLayersAdded( QList<QgsMapLayer*> theMapLayers );
230 
231  protected:
232 #if 0
233 
236  void connectNotify( const char * signal ) override;
237 #endif
238 
239  private:
241  QgsMapLayerRegistry( QObject * parent = 0 );
242 
243  QMap<QString, QgsMapLayer*> mMapLayers;
244  QSet<QgsMapLayer*> mOwnedLayers;
245 
246  friend class QgsSingleton<QgsMapLayerRegistry>; // Let QgsSingleton access private constructor
247 }; // class QgsMapLayerRegistry
248 
249 #endif //QgsMapLayerRegistry_H
250