Skip to content

Commit

Permalink
Revert "[API] Remove specific deprecated QgsVectorLayer::setDataSource"
Browse files Browse the repository at this point in the history
This reverts commit 88c0d3f.
  • Loading branch information
rldhont committed Apr 28, 2021
1 parent 4afa66a commit 2524f96
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 5 deletions.
1 change: 0 additions & 1 deletion doc/api_break.dox
Expand Up @@ -22,7 +22,6 @@ QGIS 3.20 {#qgis_api_break_3_20}
setDataSource {#qgis_api_break_3_20_setdatasource}
-------------

- QgsVectorLayer::setDataSource deprecated and specific method without ProviderOptions has been removed
- QgsMapLayer::setDataSource is no longer virtual. If has been replaced with QgsMapLayer::setDataSourcePrivate. This is only relevant for subclassing QgsMapLayer, for code that only uses the subclasses (QgsVectorLayer, QgsRasterLayer, ...) this has no effect.

QGIS 3.4 {#qgis_api_break_3_4}
Expand Down
16 changes: 16 additions & 0 deletions python/core/auto_generated/vector/qgsvectorlayer.sip.in
Expand Up @@ -1082,6 +1082,22 @@ Determines if this vector layer has features.
.. versionadded:: 3.4
%End

void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, bool loadDefaultStyleFlag = false ) /Deprecated/;
%Docstring
Update the data source of the layer. The layer's renderer and legend will be preserved only
if the geometry type of the new data source matches the current geometry type of the layer.

:param dataSource: new layer data source
:param baseName: base name of the layer
:param provider: provider string
:param loadDefaultStyleFlag: set to ``True`` to reset the layer's style to the default for the
data source

.. versionadded:: 2.10

.. deprecated::
Use version with ProviderOptions argument instead
%End

virtual QString loadDefaultStyle( bool &resultFlag /Out/ ) ${SIP_FINAL};

Expand Down
5 changes: 3 additions & 2 deletions src/app/qgisapp.cpp
Expand Up @@ -8251,7 +8251,8 @@ void QgisApp::changeDataSource( QgsMapLayer *layer )
subsetString = vlayer->subsetString();
}

layer->setDataSource( uri.uri, layer->name(), uri.providerKey, QgsDataProvider::ProviderOptions() );
layer->setDataSource( uri.uri, layer->name(), uri.providerKey,
QgsDataProvider::ProviderOptions(), QgsDataProvider::ReadFlags() );
// Re-apply original style and subset string when fixing bad layers
if ( !( layerWasValid || layer->originalXmlProperties().isEmpty() ) )
{
Expand Down Expand Up @@ -8820,7 +8821,7 @@ void QgisApp::makeMemoryLayerPermanent( QgsVectorLayer *layer )
QString source = newFilename;
if ( ! newLayerName.isEmpty() )
source += QStringLiteral( "|layername=%1" ).arg( newLayerName );
vl->setDataSource( source, vl->name(), QStringLiteral( "ogr" ), options );
vl->QgsMapLayer::setDataSource( source, vl->name(), QStringLiteral( "ogr" ), options );
vl->triggerRepaint();
this->visibleMessageBar()->pushMessage( tr( "Layer Saved" ),
tr( "Successfully saved scratch layer to <a href=\"%1\">%2</a>" ).arg( QUrl::fromLocalFile( newFilename ).toString(), QDir::toNativeSeparators( newFilename ) ),
Expand Down
17 changes: 17 additions & 0 deletions src/core/vector/qgsvectorlayer.cpp
Expand Up @@ -1634,6 +1634,23 @@ bool QgsVectorLayer::readXml( const QDomNode &layer_node, QgsReadWriteContext &c

} // void QgsVectorLayer::readXml

void QgsVectorLayer::setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, bool loadDefaultStyleFlag )
{
QgsDataProvider::ProviderOptions options;

QgsDataProvider::ReadFlags flags = QgsDataProvider::ReadFlags();
if ( loadDefaultStyleFlag )
{
flags |= QgsDataProvider::FlagLoadDefaultStyle;
}

if ( mReadFlags & QgsMapLayer::FlagTrustLayerMetadata )
{
flags |= QgsDataProvider::FlagTrustDataSource;
}
setDataSourcePrivate( dataSource, baseName, provider, options, flags );
}

void QgsVectorLayer::setDataSourcePrivate( const QString &dataSource, const QString &baseName, const QString &provider,
const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags )
{
Expand Down
12 changes: 12 additions & 0 deletions src/core/vector/qgsvectorlayer.h
Expand Up @@ -1131,6 +1131,18 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
*/
FeatureAvailability hasFeatures() const FINAL;

/**
* Update the data source of the layer. The layer's renderer and legend will be preserved only
* if the geometry type of the new data source matches the current geometry type of the layer.
* \param dataSource new layer data source
* \param baseName base name of the layer
* \param provider provider string
* \param loadDefaultStyleFlag set to TRUE to reset the layer's style to the default for the
* data source
* \since QGIS 2.10
* \deprecated Use version with ProviderOptions argument instead
*/
Q_DECL_DEPRECATED void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, bool loadDefaultStyleFlag = false ) SIP_DEPRECATED;

QString loadDefaultStyle( bool &resultFlag SIP_OUT ) FINAL;

Expand Down
4 changes: 2 additions & 2 deletions src/gui/vector/qgsvectorlayerproperties.cpp
Expand Up @@ -635,8 +635,8 @@ void QgsVectorLayerProperties::apply()
const QString newSource = mSourceWidget->sourceUri();
if ( newSource != mLayer->source() )
{
mLayer->setDataSource( newSource, mLayer->name(), mLayer->providerType(),
QgsDataProvider::ProviderOptions(), QgsDataProvider::ReadFlags() );
mLayer->QgsMapLayer::setDataSource( newSource, mLayer->name(), mLayer->providerType(),
QgsDataProvider::ProviderOptions(), QgsDataProvider::ReadFlags() );
}
}

Expand Down

0 comments on commit 2524f96

Please sign in to comment.