QGIS API Documentation 3.41.0-Master (3440c17df1d)
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#include <QObject>
26
34class CORE_EXPORT QgsMapLayerStore : public QObject
35{
36 Q_OBJECT
37
38 public:
39
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
63 int __len__() const;
64 % MethodCode
65 sipRes = sipCpp->count();
66 % End
67
69 int __bool__() const;
70 % MethodCode
71 sipRes = true;
72 % End
73#endif
74
82 QgsMapLayer *mapLayer( const QString &id ) const;
83
91 QList<QgsMapLayer *> mapLayersByName( const QString &name ) const;
92
99 QMap<QString, QgsMapLayer *> mapLayers() const;
100
108 QMap<QString, QgsMapLayer *> validMapLayers() const;
109
110#ifndef SIP_RUN
111
122 template <typename T>
123 QVector<T> layers() const
124 {
125 QVector<T> layers;
126 QMap<QString, QgsMapLayer *>::const_iterator layerIt = mMapLayers.constBegin();
127 for ( ; layerIt != mMapLayers.constEnd(); ++layerIt )
128 {
129 T tLayer = qobject_cast<T>( layerIt.value() );
130 if ( tLayer )
131 {
132 layers << tLayer;
133 }
134 }
135 return layers;
136 }
137#endif
138
162 QList<QgsMapLayer *> addMapLayers( const QList<QgsMapLayer *> &layers SIP_TRANSFER,
163 bool takeOwnership SIP_PYARGREMOVE = true );
164
186 QgsMapLayer *addMapLayer( QgsMapLayer *layer SIP_TRANSFER,
187 bool takeOwnership SIP_PYARGREMOVE = true );
188
203 void removeMapLayers( const QStringList &layerIds ) SIP_PYNAME( removeMapLayersById );
204
218 void removeMapLayers( const QList<QgsMapLayer *> &layers );
219
232 void removeMapLayer( const QString &id );
233
246 void removeMapLayer( QgsMapLayer *layer );
247
254 QgsMapLayer *takeMapLayer( QgsMapLayer *layer ) SIP_TRANSFERBACK;
255
264 void removeAllMapLayers();
265
271 void transferLayersFromStore( QgsMapLayerStore *other );
272
273 signals:
274
282 void layersWillBeRemoved( const QStringList &layerIds );
283
291 void layersWillBeRemoved( const QList<QgsMapLayer *> &layers );
292
302 void layerWillBeRemoved( const QString &layerId );
303
314
321 void layersRemoved( const QStringList &layerIds );
322
331 void layerRemoved( const QString &layerId );
332
340
348 void layersAdded( const QList<QgsMapLayer *> &layers );
349
357
358 private slots:
359
360 void onMapLayerDeleted( QObject *obj );
361
362 private:
363
364 QMap<QString, QgsMapLayer *> mMapLayers;
365
366};
367
368#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:76
#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