Skip to content

Commit

Permalink
Remove the deep copy functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
pblottiere committed May 18, 2017
1 parent 8aa2e9b commit 8a61372
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 51 deletions.
12 changes: 5 additions & 7 deletions python/core/qgsmaplayer.sip
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ class QgsMapLayer : QObject
virtual ~QgsMapLayer();


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

protected:

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

Expand Down
2 changes: 1 addition & 1 deletion python/core/qgspluginlayer.sip
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ In order to be readable from project files, they should set these attributes in
QgsPluginLayer( const QString &layerType, const QString &layerName = QString() );
~QgsPluginLayer();

virtual QgsPluginLayer *clone( bool deep ) const = 0;
virtual QgsPluginLayer *clone() const = 0;
%Docstring
Returns a new instance equivalent to this one.
\param deep If true, a deep copy is done
Expand Down
3 changes: 1 addition & 2 deletions python/core/qgsvectorlayer.sip
Original file line number Diff line number Diff line change
Expand Up @@ -334,13 +334,12 @@ class QgsVectorLayer : QgsMapLayer, QgsExpressionContextGenerator, QgsFeatureSin
virtual ~QgsVectorLayer();


virtual QgsVectorLayer *clone( bool deep = false ) const /Factory/;
virtual QgsVectorLayer *clone() const /Factory/;
%Docstring
Returns a new instance equivalent to this one. A new provider is
created for the same data source and renderers for features and diagrams
are cloned too. Moreover, each attributes (transparency, extent, selected
features and so on) are identicals.
\param deep If true, a deep copy is done (unique ID is copied too)
:return: a new layer instance
.. versionadded:: 3.0
:rtype: QgsVectorLayer
Expand Down
3 changes: 1 addition & 2 deletions python/core/raster/qgsrasterlayer.sip
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,10 @@ class QgsRasterLayer : QgsMapLayer

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

/** \brief This enumerator describes the types of shading that can be used */
enum ColorShadingAlgorithm
Expand Down
12 changes: 1 addition & 11 deletions src/core/qgsmaplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ QgsMapLayer::~QgsMapLayer()
delete mStyleManager;
}

void QgsMapLayer::clone( QgsMapLayer *layer, bool deep ) const
void QgsMapLayer::clone( QgsMapLayer *layer ) const
{
layer->setBlendMode( blendMode() );

Expand Down Expand Up @@ -123,11 +123,6 @@ void QgsMapLayer::clone( QgsMapLayer *layer, bool deep ) const
layer->setDependencies( dependencies() );
layer->setCrs( crs() );
layer->setCustomProperties( mCustomProperties );

if ( deep )
{
layer->setId( id() );
}
}

QgsMapLayer::LayerType QgsMapLayer::type() const
Expand All @@ -140,11 +135,6 @@ QString QgsMapLayer::id() const
return mID;
}

void QgsMapLayer::setId( const QString &id )
{
mID = id;
}

void QgsMapLayer::setName( const QString &name )
{
QString newName = capitalizeLayerName( name );
Expand Down
17 changes: 5 additions & 12 deletions src/core/qgsmaplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ class CORE_EXPORT QgsMapLayer : public QObject
//! QgsMapLayer cannot be copied
QgsMapLayer &operator=( QgsMapLayer const & ) = delete;

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

/** Returns the type of the layer.
*/
Expand Down Expand Up @@ -930,13 +930,11 @@ class CORE_EXPORT QgsMapLayer : public QObject

protected:

/** Copies attributes like name, short name, ... into another layer. The
* unique ID is copied too if deep parameter is true.
/** Copies attributes like name, short name, ... into another layer.
* \param layer The copy recipient
* \param deep To copy the unique ID or not
* \since QGIS 3.0
*/
void clone( QgsMapLayer *layer, bool deep = false ) const;
void clone( QgsMapLayer *layer ) const;

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

private:

/** Set the unique id of the layer.
* /param id the new unique id of the layer
*/
void setId( const QString &id );

/**
* This method returns true by default but can be overwritten to specify
* that a certain layer is writable.
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgspluginlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class CORE_EXPORT QgsPluginLayer : public QgsMapLayer
* \returns a new layer instance
* \since QGIS 3.0
*/
virtual QgsPluginLayer *clone( bool deep ) const override = 0;
virtual QgsPluginLayer *clone() const override = 0;

//! Return plugin layer type (the same as used in QgsPluginLayerRegistry)
QString pluginLayerType();
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgsvectorlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,10 @@ QgsVectorLayer::~QgsVectorLayer()
delete mConditionalStyles;
}

QgsVectorLayer *QgsVectorLayer::clone( bool deep ) const
QgsVectorLayer *QgsVectorLayer::clone() const
{
QgsVectorLayer *layer = new QgsVectorLayer( source(), originalName(), mProviderKey );
QgsMapLayer::clone( layer, deep );
QgsMapLayer::clone( layer );

QList<QgsVectorLayerJoinInfo> joins = vectorJoins();
Q_FOREACH ( QgsVectorLayerJoinInfo join, joins )
Expand Down
3 changes: 1 addition & 2 deletions src/core/qgsvectorlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -404,11 +404,10 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
* created for the same data source and renderers for features and diagrams
* are cloned too. Moreover, each attributes (transparency, extent, selected
* features and so on) are identicals.
* \param deep If true, a deep copy is done (unique ID is copied too)
* \returns a new layer instance
* \since QGIS 3.0
*/
virtual QgsVectorLayer *clone( bool deep = false ) const override SIP_FACTORY;
virtual QgsVectorLayer *clone() const override SIP_FACTORY;

//! Returns the permanent storage type for this layer as a friendly name.
QString storageType() const;
Expand Down
4 changes: 2 additions & 2 deletions src/core/raster/qgsrasterlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@ QgsRasterLayer::~QgsRasterLayer()
// Note: provider and other interfaces are owned and deleted by pipe
}

QgsRasterLayer *QgsRasterLayer::clone( bool deep ) const
QgsRasterLayer *QgsRasterLayer::clone() const
{
QgsRasterLayer *layer = new QgsRasterLayer( source(), originalName(), mProviderKey );
QgsMapLayer::clone( layer, deep );
QgsMapLayer::clone( layer );
layer->setRenderer( renderer()->clone() );
return layer;
}
Expand Down
3 changes: 1 addition & 2 deletions src/core/raster/qgsrasterlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,10 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer

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

//! \brief This enumerator describes the types of shading that can be used
enum ColorShadingAlgorithm
Expand Down
7 changes: 0 additions & 7 deletions tests/src/python/test_qgsvectorlayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2195,16 +2195,9 @@ def testCloneMapLayerAttributes(self):
def testCloneId(self):
layer = createLayerWithFivePoints()

# deep clone by default
clone = layer.clone()
self.assertFalse(clone.id() == layer.id())

clone = layer.clone(False)
self.assertFalse(clone.id() == layer.id())

clone = layer.clone(True)
self.assertEqual(clone.id(), layer.id())

def testCloneVectorLayerAttributes(self):
# init layer
layer = createLayerWithFivePoints()
Expand Down

0 comments on commit 8a61372

Please sign in to comment.