Skip to content

Commit 8a61372

Browse files
committed
Remove the deep copy functionality
1 parent 8aa2e9b commit 8a61372

12 files changed

+21
-51
lines changed

python/core/qgsmaplayer.sip

+5-7
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ class QgsMapLayer : QObject
6767
virtual ~QgsMapLayer();
6868

6969

70-
virtual QgsMapLayer *clone( bool deep ) const = 0;
70+
virtual QgsMapLayer *clone() const = 0;
7171
%Docstring
72-
Returns a new instance equivalent to this one.
73-
\param deep If true, a deep copy is done
72+
Returns a new instance equivalent to this one except for the id which
73+
is still unique.
7474
:return: a new layer instance
7575
.. versionadded:: 3.0
7676
:rtype: QgsMapLayer
@@ -1045,12 +1045,10 @@ Signal emitted when the blend mode is changed, through QgsMapLayer.setBlendMode(
10451045

10461046
protected:
10471047

1048-
void clone( QgsMapLayer *layer, bool deep = false ) const;
1048+
void clone( QgsMapLayer *layer ) const;
10491049
%Docstring
1050-
Copies attributes like name, short name, ... into another layer. The
1051-
unique ID is copied too if deep parameter is true.
1050+
Copies attributes like name, short name, ... into another layer.
10521051
\param layer The copy recipient
1053-
\param deep To copy the unique ID or not
10541052
.. versionadded:: 3.0
10551053
%End
10561054

python/core/qgspluginlayer.sip

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ In order to be readable from project files, they should set these attributes in
2626
QgsPluginLayer( const QString &layerType, const QString &layerName = QString() );
2727
~QgsPluginLayer();
2828

29-
virtual QgsPluginLayer *clone( bool deep ) const = 0;
29+
virtual QgsPluginLayer *clone() const = 0;
3030
%Docstring
3131
Returns a new instance equivalent to this one.
3232
\param deep If true, a deep copy is done

python/core/qgsvectorlayer.sip

+1-2
Original file line numberDiff line numberDiff line change
@@ -334,13 +334,12 @@ class QgsVectorLayer : QgsMapLayer, QgsExpressionContextGenerator, QgsFeatureSin
334334
virtual ~QgsVectorLayer();
335335

336336

337-
virtual QgsVectorLayer *clone( bool deep = false ) const /Factory/;
337+
virtual QgsVectorLayer *clone() const /Factory/;
338338
%Docstring
339339
Returns a new instance equivalent to this one. A new provider is
340340
created for the same data source and renderers for features and diagrams
341341
are cloned too. Moreover, each attributes (transparency, extent, selected
342342
features and so on) are identicals.
343-
\param deep If true, a deep copy is done (unique ID is copied too)
344343
:return: a new layer instance
345344
.. versionadded:: 3.0
346345
:rtype: QgsVectorLayer

python/core/raster/qgsrasterlayer.sip

+1-2
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,10 @@ class QgsRasterLayer : QgsMapLayer
4343

4444
/** Returns a new instance equivalent to this one. A new provider is
4545
* created for the same data source and renderer is cloned too.
46-
* \param deep If true, a deep copy is done (unique ID is copy too)
4746
* \returns a new layer instance
4847
* \since QGIS 3.0
4948
*/
50-
virtual QgsRasterLayer *clone( bool deep = true ) const /Factory/;
49+
virtual QgsRasterLayer *clone() const /Factory/;
5150

5251
/** \brief This enumerator describes the types of shading that can be used */
5352
enum ColorShadingAlgorithm

src/core/qgsmaplayer.cpp

+1-11
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ QgsMapLayer::~QgsMapLayer()
9494
delete mStyleManager;
9595
}
9696

97-
void QgsMapLayer::clone( QgsMapLayer *layer, bool deep ) const
97+
void QgsMapLayer::clone( QgsMapLayer *layer ) const
9898
{
9999
layer->setBlendMode( blendMode() );
100100

@@ -123,11 +123,6 @@ void QgsMapLayer::clone( QgsMapLayer *layer, bool deep ) const
123123
layer->setDependencies( dependencies() );
124124
layer->setCrs( crs() );
125125
layer->setCustomProperties( mCustomProperties );
126-
127-
if ( deep )
128-
{
129-
layer->setId( id() );
130-
}
131126
}
132127

133128
QgsMapLayer::LayerType QgsMapLayer::type() const
@@ -140,11 +135,6 @@ QString QgsMapLayer::id() const
140135
return mID;
141136
}
142137

143-
void QgsMapLayer::setId( const QString &id )
144-
{
145-
mID = id;
146-
}
147-
148138
void QgsMapLayer::setName( const QString &name )
149139
{
150140
QString newName = capitalizeLayerName( name );

src/core/qgsmaplayer.h

+5-12
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,12 @@ class CORE_EXPORT QgsMapLayer : public QObject
110110
//! QgsMapLayer cannot be copied
111111
QgsMapLayer &operator=( QgsMapLayer const & ) = delete;
112112

113-
/** Returns a new instance equivalent to this one.
114-
* \param deep If true, a deep copy is done
113+
/** Returns a new instance equivalent to this one except for the id which
114+
* is still unique.
115115
* \returns a new layer instance
116116
* \since QGIS 3.0
117117
*/
118-
virtual QgsMapLayer *clone( bool deep ) const = 0;
118+
virtual QgsMapLayer *clone() const = 0;
119119

120120
/** Returns the type of the layer.
121121
*/
@@ -930,13 +930,11 @@ class CORE_EXPORT QgsMapLayer : public QObject
930930

931931
protected:
932932

933-
/** Copies attributes like name, short name, ... into another layer. The
934-
* unique ID is copied too if deep parameter is true.
933+
/** Copies attributes like name, short name, ... into another layer.
935934
* \param layer The copy recipient
936-
* \param deep To copy the unique ID or not
937935
* \since QGIS 3.0
938936
*/
939-
void clone( QgsMapLayer *layer, bool deep = false ) const;
937+
void clone( QgsMapLayer *layer ) const;
940938

941939
//! Set the extent
942940
virtual void setExtent( const QgsRectangle &rect );
@@ -1031,11 +1029,6 @@ class CORE_EXPORT QgsMapLayer : public QObject
10311029

10321030
private:
10331031

1034-
/** Set the unique id of the layer.
1035-
* /param id the new unique id of the layer
1036-
*/
1037-
void setId( const QString &id );
1038-
10391032
/**
10401033
* This method returns true by default but can be overwritten to specify
10411034
* that a certain layer is writable.

src/core/qgspluginlayer.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class CORE_EXPORT QgsPluginLayer : public QgsMapLayer
4141
* \returns a new layer instance
4242
* \since QGIS 3.0
4343
*/
44-
virtual QgsPluginLayer *clone( bool deep ) const override = 0;
44+
virtual QgsPluginLayer *clone() const override = 0;
4545

4646
//! Return plugin layer type (the same as used in QgsPluginLayerRegistry)
4747
QString pluginLayerType();

src/core/qgsvectorlayer.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,10 @@ QgsVectorLayer::~QgsVectorLayer()
202202
delete mConditionalStyles;
203203
}
204204

205-
QgsVectorLayer *QgsVectorLayer::clone( bool deep ) const
205+
QgsVectorLayer *QgsVectorLayer::clone() const
206206
{
207207
QgsVectorLayer *layer = new QgsVectorLayer( source(), originalName(), mProviderKey );
208-
QgsMapLayer::clone( layer, deep );
208+
QgsMapLayer::clone( layer );
209209

210210
QList<QgsVectorLayerJoinInfo> joins = vectorJoins();
211211
Q_FOREACH ( QgsVectorLayerJoinInfo join, joins )

src/core/qgsvectorlayer.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -404,11 +404,10 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
404404
* created for the same data source and renderers for features and diagrams
405405
* are cloned too. Moreover, each attributes (transparency, extent, selected
406406
* features and so on) are identicals.
407-
* \param deep If true, a deep copy is done (unique ID is copied too)
408407
* \returns a new layer instance
409408
* \since QGIS 3.0
410409
*/
411-
virtual QgsVectorLayer *clone( bool deep = false ) const override SIP_FACTORY;
410+
virtual QgsVectorLayer *clone() const override SIP_FACTORY;
412411

413412
//! Returns the permanent storage type for this layer as a friendly name.
414413
QString storageType() const;

src/core/raster/qgsrasterlayer.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,10 @@ QgsRasterLayer::~QgsRasterLayer()
144144
// Note: provider and other interfaces are owned and deleted by pipe
145145
}
146146

147-
QgsRasterLayer *QgsRasterLayer::clone( bool deep ) const
147+
QgsRasterLayer *QgsRasterLayer::clone() const
148148
{
149149
QgsRasterLayer *layer = new QgsRasterLayer( source(), originalName(), mProviderKey );
150-
QgsMapLayer::clone( layer, deep );
150+
QgsMapLayer::clone( layer );
151151
layer->setRenderer( renderer()->clone() );
152152
return layer;
153153
}

src/core/raster/qgsrasterlayer.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,10 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
190190

191191
/** Returns a new instance equivalent to this one. A new provider is
192192
* created for the same data source and renderer is cloned too.
193-
* \param deep If true, a deep copy is done (unique ID is copy too)
194193
* \returns a new layer instance
195194
* \since QGIS 3.0
196195
*/
197-
virtual QgsRasterLayer *clone( bool deep = false ) const override SIP_FACTORY;
196+
virtual QgsRasterLayer *clone() const override SIP_FACTORY;
198197

199198
//! \brief This enumerator describes the types of shading that can be used
200199
enum ColorShadingAlgorithm

tests/src/python/test_qgsvectorlayer.py

-7
Original file line numberDiff line numberDiff line change
@@ -2195,16 +2195,9 @@ def testCloneMapLayerAttributes(self):
21952195
def testCloneId(self):
21962196
layer = createLayerWithFivePoints()
21972197

2198-
# deep clone by default
21992198
clone = layer.clone()
22002199
self.assertFalse(clone.id() == layer.id())
22012200

2202-
clone = layer.clone(False)
2203-
self.assertFalse(clone.id() == layer.id())
2204-
2205-
clone = layer.clone(True)
2206-
self.assertEqual(clone.id(), layer.id())
2207-
22082201
def testCloneVectorLayerAttributes(self):
22092202
# init layer
22102203
layer = createLayerWithFivePoints()

0 commit comments

Comments
 (0)