QGIS API Documentation 4.1.0-Master (60fea48833c)
Loading...
Searching...
No Matches
qgsmaplayerstore.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsmaplayerstore.h
3 ------------------
4 begin : May 2017
5 copyright : (C) 2017 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18
19#ifndef QGSMAPLAYERSTORE_H
20#define QGSMAPLAYERSTORE_H
21
22#include "qgis_core.h"
23#include "qgis_sip.h"
24#include "qgsmaplayer.h"
25
26#include <QObject>
27
34
35class CORE_EXPORT QgsMapLayerStore : public QObject
36{
37 Q_OBJECT
38
39 public:
43 explicit QgsMapLayerStore( QObject *parent SIP_TRANSFERTHIS = nullptr );
44
45 ~QgsMapLayerStore() override;
46
50 int count() const;
51
56 int validCount() const;
57
58#ifdef SIP_RUN
59 // clang-format off
60
64 int __len__() const;
65 % MethodCode
66 sipRes = sipCpp->count();
67 % End
68
70 int __bool__() const;
71 % MethodCode
72 sipRes = true;
73 % End
74// clang-format on
75#endif
76
84 QgsMapLayer *mapLayer( const QString &id ) const;
85
93 QList<QgsMapLayer *> mapLayersByName( const QString &name ) const;
94
101 QMap<QString, QgsMapLayer *> mapLayers() const;
102
110 QMap<QString, QgsMapLayer *> validMapLayers() const;
111
112#ifndef SIP_RUN
113
124 template<typename T> QVector<T> layers() const
125 {
126 QVector<T> layers;
127 QMap<QString, QgsMapLayer *>::const_iterator layerIt = mMapLayers.constBegin();
128 for ( ; layerIt != mMapLayers.constEnd(); ++layerIt )
129 {
130 T tLayer = qobject_cast<T>( layerIt.value() );
131 if ( tLayer )
132 {
133 layers << tLayer;
134 }
135 }
136 return layers;
137 }
138#endif
139
163 QList<QgsMapLayer *> addMapLayers( const QList<QgsMapLayer *> &layers SIP_TRANSFER, bool takeOwnership SIP_PYARGREMOVE = true );
164
186 QgsMapLayer *addMapLayer( QgsMapLayer *layer SIP_TRANSFER, bool takeOwnership SIP_PYARGREMOVE = true );
187
202 void removeMapLayers( const QStringList &layerIds ) SIP_PYNAME( removeMapLayersById );
203
217 void removeMapLayers( const QList<QgsMapLayer *> &layers );
218
231 void removeMapLayer( const QString &id );
232
245 void removeMapLayer( QgsMapLayer *layer );
246
253 QgsMapLayer *takeMapLayer( QgsMapLayer *layer ) SIP_TRANSFERBACK;
254
263 void removeAllMapLayers();
264
270 void transferLayersFromStore( QgsMapLayerStore *other );
271
272 signals:
273
281 void layersWillBeRemoved( const QStringList &layerIds );
282
290 void layersWillBeRemoved( const QList<QgsMapLayer *> &layers );
291
301 void layerWillBeRemoved( const QString &layerId );
302
313
320 void layersRemoved( const QStringList &layerIds );
321
330 void layerRemoved( const QString &layerId );
331
339
347 void layersAdded( const QList<QgsMapLayer *> &layers );
348
356
357 private slots:
358
359 void onMapLayerDeleted( QObject *obj );
360
361 private:
362 QMap<QString, QgsMapLayer *> mMapLayers;
363};
364
365#endif //QGSMAPLAYERSTORE_H
A storage object for map layers, in which the layers are owned by the store and have their lifetime b...
void layerWillBeRemoved(QgsMapLayer *layer)
Emitted when a layer is about to be removed from the store.
void layersWillBeRemoved(const QList< QgsMapLayer * > &layers)
Emitted when one or more layers are about to be removed from the store.
int count() const
Returns the number of layers contained in the store.
QMap< QString, QgsMapLayer * > mapLayers() const
Returns a map of all layers by layer ID.
QgsMapLayerStore(QObject *parent=nullptr)
Constructor for QgsMapLayerStore.
void layersWillBeRemoved(const QStringList &layerIds)
Emitted when one or more layers are about to be removed from the store.
int validCount() const
Returns the number of valid layers contained in the store.
void layerWillBeRemoved(const QString &layerId)
Emitted when a layer is about to be removed from the store.
QVector< T > layers() const
Returns a list of registered map layers with a specified layer type.
void layersRemoved(const QStringList &layerIds)
Emitted after one or more layers were removed from the store.
void allLayersRemoved()
Emitted when all layers are removed, before layersWillBeRemoved() and layerWillBeRemoved() signals ar...
void layerRemoved(const QString &layerId)
Emitted after a layer was removed from the store.
void layerWasAdded(QgsMapLayer *layer)
Emitted when a layer was added to the store.
QList< QgsMapLayer * > mapLayersByName(const QString &name) const
Retrieve a list of matching layers by layer name.
QMap< QString, QgsMapLayer * > validMapLayers() const
Returns a map of all valid layers by layer ID.
QgsMapLayer * mapLayer(const QString &id) const
Retrieve a pointer to a layer by layer id.
void layersAdded(const QList< QgsMapLayer * > &layers)
Emitted when one or more layers were added to the store.
Base class for all map layer types.
Definition qgsmaplayer.h:83
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:52
#define SIP_PYNAME(name)
Definition qgis_sip.h:88
#define SIP_PYARGREMOVE
Definition qgis_sip.h:158
#define SIP_TRANSFER
Definition qgis_sip.h:35
#define SIP_TRANSFERBACK
Definition qgis_sip.h:47