QGIS API Documentation
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;
69  Q_FOREACH ( QgsMapLayer* layer, mMapLayers.values() )
70  {
71  T tLayer = qobject_cast<T>( layer );
72  if ( tLayer )
73  {
74  layers << tLayer;
75  }
76  }
77  return layers;
78  }
79 
102  QList<QgsMapLayer *> addMapLayers( const QList<QgsMapLayer*>& theMapLayers,
103  bool addToLegend = true,
104  bool takeOwnership = true );
105 
131  QgsMapLayer* addMapLayer( QgsMapLayer * theMapLayer, bool addToLegend = true, bool takeOwnership = true );
132 
146  void removeMapLayers( const QStringList& theLayerIds );
147 
161  void removeMapLayers( const QList<QgsMapLayer*>& layers );
162 
176  void removeMapLayer( const QString& theLayerId );
177 
191  void removeMapLayer( QgsMapLayer* layer );
192 
199  void removeAllMapLayers();
200 
207  Q_DECL_DEPRECATED void clearAllLayerCaches() {}
209 
213  void reloadAllLayers();
214 
215  signals:
221  void layersWillBeRemoved( const QStringList& theLayerIds );
222 
228  void layersWillBeRemoved( const QList<QgsMapLayer*>& layers );
229 
237  void layerWillBeRemoved( const QString& theLayerId );
238 
246  void layerWillBeRemoved( QgsMapLayer* layer );
247 
253  void layersRemoved( const QStringList& theLayerIds );
254 
262  void layerRemoved( const QString& theLayerId );
263 
264 
271  void removeAll();
272 
282  void layersAdded( const QList<QgsMapLayer *>& theMapLayers );
283 
291  void layerWasAdded( QgsMapLayer* theMapLayer );
292 
301  void legendLayersAdded( const QList<QgsMapLayer*>& theMapLayers );
302 
303  protected:
304 #if 0
305 
308  void connectNotify( const char * signal ) override;
309 #endif
310 
311  private:
313  QgsMapLayerRegistry( QObject * parent = nullptr );
314 
315  QMap<QString, QgsMapLayer*> mMapLayers;
316  QSet<QgsMapLayer*> mOwnedLayers;
317 }; // class QgsMapLayerRegistry
318 
319 #endif //QgsMapLayerRegistry_H
320 
Base class for all map layer types.
Definition: qgsmaplayer.h:49
QVector< T > layers() const
Get map layers of a certain type.
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)