QGIS API Documentation 3.30.0-'s-Hertogenbosch (f186b8efe0)
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#include <QObject>
26
35class CORE_EXPORT QgsMapLayerStore : public QObject
36{
37 Q_OBJECT
38
39 public:
40
44 explicit QgsMapLayerStore( QObject *parent SIP_TRANSFERTHIS = nullptr );
45
46 ~QgsMapLayerStore() override;
47
51 int count() const;
52
57 int validCount() const;
58
59#ifdef SIP_RUN
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#endif
75
83 QgsMapLayer *mapLayer( const QString &id ) const;
84
92 QList<QgsMapLayer *> mapLayersByName( const QString &name ) const;
93
100 QMap<QString, QgsMapLayer *> mapLayers() const;
101
109 QMap<QString, QgsMapLayer *> validMapLayers() const;
110
111#ifndef SIP_RUN
112
123 template <typename T>
124 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,
164 bool takeOwnership SIP_PYARGREMOVE = true );
165
187 QgsMapLayer *addMapLayer( QgsMapLayer *layer SIP_TRANSFER,
188 bool takeOwnership SIP_PYARGREMOVE = true );
189
204 void removeMapLayers( const QStringList &layerIds ) SIP_PYNAME( removeMapLayersById );
205
219 void removeMapLayers( const QList<QgsMapLayer *> &layers );
220
233 void removeMapLayer( const QString &id );
234
247 void removeMapLayer( QgsMapLayer *layer );
248
255 QgsMapLayer *takeMapLayer( QgsMapLayer *layer ) SIP_TRANSFERBACK;
256
265 void removeAllMapLayers();
266
272 void transferLayersFromStore( QgsMapLayerStore *other );
273
274 signals:
275
283 void layersWillBeRemoved( const QStringList &layerIds );
284
292 void layersWillBeRemoved( const QList<QgsMapLayer *> &layers );
293
303 void layerWillBeRemoved( const QString &layerId );
304
315
322 void layersRemoved( const QStringList &layerIds );
323
332 void layerRemoved( const QString &layerId );
333
341
349 void layersAdded( const QList<QgsMapLayer *> &layers );
350
358
359 private slots:
360
361 void onMapLayerDeleted( QObject *obj );
362
363 private:
364
365 QMap<QString, QgsMapLayer *> mMapLayers;
366
367};
368
369#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.
void layersWillBeRemoved(const QStringList &layerIds)
Emitted when one or more layers are about to be removed from 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.
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:73
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
#define SIP_PYNAME(name)
Definition: qgis_sip.h:81
#define SIP_PYARGREMOVE
Definition: qgis_sip.h:151
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_TRANSFERBACK
Definition: qgis_sip.h:48