Skip to content

Commit f9bd83c

Browse files
committedMay 2, 2017
Split off map layer storage handling from QgsProject to QgsMapLayerStore
Turns out that there's valid use cases for having layer stores outside of the cost of using a whole QgsProject. Partially reverts the merger of QgsMapLayerRegistry into QgsProject, except that there's no singletons here.
1 parent 8e70aa8 commit f9bd83c

File tree

7 files changed

+1316
-0
lines changed

7 files changed

+1316
-0
lines changed
 

‎python/core/core.sip

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
%Include qgsmaplayermodel.sip
9393
%Include qgsmaplayerproxymodel.sip
9494
%Include qgsmaplayerrenderer.sip
95+
%Include qgsmaplayerstore.sip
9596
%Include qgsmaplayerstylemanager.sip
9697
%Include qgsmaprenderercache.sip
9798
%Include qgsmaprenderercustompainterjob.sip

‎python/core/qgsmaplayerstore.sip

Lines changed: 292 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,292 @@
1+
/************************************************************************
2+
* This file has been generated automatically from *
3+
* *
4+
* src/core/qgsmaplayerstore.h *
5+
* *
6+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
7+
************************************************************************/
8+
9+
10+
11+
12+
13+
14+
class QgsMapLayerStore : QObject
15+
{
16+
%Docstring
17+
A storage object for map layers, in which the layers are owned by the
18+
store and have their lifetime bound to the store.
19+
.. versionadded:: 3.0
20+
%End
21+
22+
%TypeHeaderCode
23+
#include "qgsmaplayerstore.h"
24+
%End
25+
public:
26+
27+
explicit QgsMapLayerStore( QObject *parent /TransferThis/ = 0 );
28+
%Docstring
29+
Constructor for QgsMapLayerStore.
30+
%End
31+
32+
~QgsMapLayerStore();
33+
34+
int count() const;
35+
%Docstring
36+
Returns the number of layers contained in the store.
37+
:rtype: int
38+
%End
39+
40+
41+
int __len__() const;
42+
%Docstring
43+
Returns the number of layers contained in the store.
44+
:rtype: int
45+
%End
46+
%MethodCode
47+
sipRes = sipCpp->count();
48+
%End
49+
50+
QgsMapLayer *mapLayer( const QString &id ) const;
51+
%Docstring
52+
Retrieve a pointer to a layer by layer ``id``.
53+
\param id ID of layer to retrieve
54+
:return: matching layer, or None if no matching layer found
55+
.. seealso:: mapLayersByName()
56+
.. seealso:: mapLayers()
57+
:rtype: QgsMapLayer
58+
%End
59+
60+
QList<QgsMapLayer *> mapLayersByName( const QString &name ) const;
61+
%Docstring
62+
Retrieve a list of matching layers by layer ``name``.
63+
\param name name of layers to match
64+
:return: list of matching layers
65+
.. seealso:: mapLayer()
66+
.. seealso:: mapLayers()
67+
:rtype: list of QgsMapLayer
68+
%End
69+
70+
QMap<QString, QgsMapLayer *> mapLayers() const;
71+
%Docstring
72+
Returns a map of all layers by layer ID.
73+
.. seealso:: mapLayer()
74+
.. seealso:: mapLayersByName()
75+
.. seealso:: layers()
76+
:rtype: QMap<str, QgsMapLayer *>
77+
%End
78+
79+
80+
QList<QgsMapLayer *> addMapLayers( const QList<QgsMapLayer *> &layers /Transfer/ );
81+
%Docstring
82+
\brief
83+
Add a list of ``layers`` to the store. Ownership of the layers is transferred
84+
to the store.
85+
86+
The layersAdded() and layerWasAdded() signals will always be emitted.
87+
88+
\param layers A list of layer which should be added to the store.
89+
90+
:return: a list of the map layers that were added
91+
successfully. If a layer is invalid, or already exists in the store,
92+
it will not be part of the returned list.
93+
94+
.. seealso:: addMapLayer()
95+
:rtype: list of QgsMapLayer
96+
%End
97+
98+
QgsMapLayer *addMapLayer( QgsMapLayer *layer /Transfer/ );
99+
%Docstring
100+
\brief
101+
Add a ``layer`` to the store. Ownership of the layer is transferred to the
102+
store.
103+
104+
The layersAdded() and layerWasAdded() signals will always be emitted.
105+
If you are adding multiple layers at once, you should use
106+
addMapLayers() instead.
107+
108+
\param layer A layer to add to the store
109+
110+
:return: None if unable to add layer, otherwise pointer to newly added layer
111+
112+
.. seealso:: addMapLayers
113+
114+
.. note::
115+
116+
Use addMapLayers() if adding more than one layer at a time.
117+
.. seealso:: addMapLayers()
118+
:rtype: QgsMapLayer
119+
%End
120+
121+
void removeMapLayers( const QStringList &layerIds ) /PyName=removeMapLayersById/;
122+
%Docstring
123+
\brief
124+
Remove a set of layers from the store by layer ID.
125+
126+
The specified layers will be removed from the store.
127+
These layers will also be deleted.
128+
129+
\param layerIds list of IDs of the layers to remove
130+
131+
.. seealso:: takeMapLayer()
132+
.. seealso:: removeMapLayer()
133+
.. seealso:: removeAllMapLayers()
134+
.. note::
135+
136+
available in Python bindings as removeMapLayersById.
137+
%End
138+
139+
void removeMapLayers( const QList<QgsMapLayer *> &layers );
140+
141+
void removeMapLayer( const QString &id );
142+
%Docstring
143+
\brief
144+
Remove a layer from the store by layer ``id``.
145+
146+
The specified layer will be removed from the store. The layer will also be deleted.
147+
148+
\param id ID of the layer to remove
149+
150+
.. seealso:: takeMapLayer()
151+
.. seealso:: removeMapLayers()
152+
.. seealso:: removeAllMapLayers()
153+
%End
154+
155+
void removeMapLayer( QgsMapLayer *layer );
156+
%Docstring
157+
\brief
158+
Remove a ``layer`` from the store.
159+
160+
The specified layer will be removed from the store. The layer will also be deleted.
161+
162+
\param layer The layer to remove. Null pointers are ignored.
163+
164+
.. seealso:: takeMapLayer()
165+
.. seealso:: removeMapLayers()
166+
.. seealso:: removeAllMapLayers()
167+
%End
168+
169+
QgsMapLayer *takeMapLayer( QgsMapLayer *layer ) /TransferBack/;
170+
%Docstring
171+
Takes a ``layer`` from the store. If the layer was owned by the store, the
172+
layer will be returned without deleting it. The caller takes ownership of
173+
the layer and is responsible for deleting it.
174+
.. seealso:: removeMapLayer()
175+
:rtype: QgsMapLayer
176+
%End
177+
178+
void removeAllMapLayers();
179+
%Docstring
180+
Removes all registered layers. These layers will also be deleted.
181+
182+
.. note::
183+
184+
Calling this method will cause the removeAll() signal to
185+
be emitted.
186+
.. seealso:: removeMapLayer()
187+
.. seealso:: removeMapLayers()
188+
%End
189+
190+
signals:
191+
192+
void layersWillBeRemoved( const QStringList &layerIds );
193+
%Docstring
194+
Emitted when one or more layers are about to be removed from the store.
195+
196+
\param layerIds A list of IDs for the layers which are to be removed.
197+
.. seealso:: layerWillBeRemoved()
198+
.. seealso:: layersRemoved()
199+
%End
200+
201+
void layersWillBeRemoved( const QList<QgsMapLayer *> &layers );
202+
%Docstring
203+
Emitted when one or more layers are about to be removed from the store.
204+
205+
\param layers A list of layers which are to be removed.
206+
.. seealso:: layerWillBeRemoved()
207+
.. seealso:: layersRemoved()
208+
%End
209+
210+
void layerWillBeRemoved( const QString &layerId );
211+
%Docstring
212+
Emitted when a layer is about to be removed from the store.
213+
214+
\param layerId The ID of the layer to be removed.
215+
216+
.. note::
217+
218+
Consider using layersWillBeRemoved() instead.
219+
.. seealso:: layersWillBeRemoved()
220+
.. seealso:: layerRemoved()
221+
%End
222+
223+
void layerWillBeRemoved( QgsMapLayer *layer );
224+
%Docstring
225+
Emitted when a layer is about to be removed from the store.
226+
227+
\param layer The layer to be removed.
228+
229+
.. note::
230+
231+
Consider using layersWillBeRemoved() instead.
232+
.. seealso:: layersWillBeRemoved()
233+
.. seealso:: layerRemoved()
234+
%End
235+
236+
void layersRemoved( const QStringList &layerIds );
237+
%Docstring
238+
Emitted after one or more layers were removed from the store.
239+
240+
\param layerIds A list of IDs of the layers which were removed.
241+
.. seealso:: layersWillBeRemoved()
242+
%End
243+
244+
void layerRemoved( const QString &layerId );
245+
%Docstring
246+
Emitted after a layer was removed from the store.
247+
248+
\param layerId The ID of the layer removed.
249+
250+
.. note::
251+
252+
Consider using layersRemoved() instead
253+
.. seealso:: layerWillBeRemoved()
254+
%End
255+
256+
void allLayersRemoved();
257+
%Docstring
258+
Emitted when all layers are removed, before layersWillBeRemoved() and
259+
layerWillBeRemoved() signals are emitted. The layersWillBeRemoved() and
260+
layerWillBeRemoved() signals will still be emitted following this signal.
261+
You can use this signal to do easy (and fast) cleanup.
262+
%End
263+
264+
void layersAdded( const QList<QgsMapLayer *> &layers );
265+
%Docstring
266+
Emitted when one or more layers were added to the store.
267+
268+
\param layers List of layers which have been added.
269+
270+
.. seealso:: legendLayersAdded()
271+
.. seealso:: layerWasAdded()
272+
%End
273+
274+
void layerWasAdded( QgsMapLayer *layer );
275+
%Docstring
276+
Emitted when a ``layer`` was added to the store.
277+
278+
.. note::
279+
280+
Consider using layersAdded() instead
281+
.. seealso:: layersAdded()
282+
%End
283+
284+
};
285+
286+
/************************************************************************
287+
* This file has been generated automatically from *
288+
* *
289+
* src/core/qgsmaplayerstore.h *
290+
* *
291+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
292+
************************************************************************/

‎src/core/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ SET(QGIS_CORE_SRCS
176176
qgsmaplayerlegend.cpp
177177
qgsmaplayermodel.cpp
178178
qgsmaplayerproxymodel.cpp
179+
qgsmaplayerstore.cpp
179180
qgsmaplayerstylemanager.cpp
180181
qgsmaprenderercache.cpp
181182
qgsmaprenderercustompainterjob.cpp
@@ -525,6 +526,7 @@ SET(QGIS_CORE_MOC_HDRS
525526
qgsmaplayerlegend.h
526527
qgsmaplayermodel.h
527528
qgsmaplayerproxymodel.h
529+
qgsmaplayerstore.h
528530
qgsmaplayerstylemanager.h
529531
qgsmaprenderercache.h
530532
qgsmaprenderercustompainterjob.h

0 commit comments

Comments
 (0)
Please sign in to comment.