Skip to content

Commit 2524f96

Browse files
committedApr 28, 2021
Revert "[API] Remove specific deprecated QgsVectorLayer::setDataSource"
This reverts commit 88c0d3f.
1 parent 4afa66a commit 2524f96

File tree

6 files changed

+50
-5
lines changed

6 files changed

+50
-5
lines changed
 

‎doc/api_break.dox

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ QGIS 3.20 {#qgis_api_break_3_20}
2222
setDataSource {#qgis_api_break_3_20_setdatasource}
2323
-------------
2424

25-
- QgsVectorLayer::setDataSource deprecated and specific method without ProviderOptions has been removed
2625
- 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.
2726

2827
QGIS 3.4 {#qgis_api_break_3_4}

‎python/core/auto_generated/vector/qgsvectorlayer.sip.in

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,6 +1082,22 @@ Determines if this vector layer has features.
10821082
.. versionadded:: 3.4
10831083
%End
10841084

1085+
void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, bool loadDefaultStyleFlag = false ) /Deprecated/;
1086+
%Docstring
1087+
Update the data source of the layer. The layer's renderer and legend will be preserved only
1088+
if the geometry type of the new data source matches the current geometry type of the layer.
1089+
1090+
:param dataSource: new layer data source
1091+
:param baseName: base name of the layer
1092+
:param provider: provider string
1093+
:param loadDefaultStyleFlag: set to ``True`` to reset the layer's style to the default for the
1094+
data source
1095+
1096+
.. versionadded:: 2.10
1097+
1098+
.. deprecated::
1099+
Use version with ProviderOptions argument instead
1100+
%End
10851101

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

‎src/app/qgisapp.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8251,7 +8251,8 @@ void QgisApp::changeDataSource( QgsMapLayer *layer )
82518251
subsetString = vlayer->subsetString();
82528252
}
82538253

8254-
layer->setDataSource( uri.uri, layer->name(), uri.providerKey, QgsDataProvider::ProviderOptions() );
8254+
layer->setDataSource( uri.uri, layer->name(), uri.providerKey,
8255+
QgsDataProvider::ProviderOptions(), QgsDataProvider::ReadFlags() );
82558256
// Re-apply original style and subset string when fixing bad layers
82568257
if ( !( layerWasValid || layer->originalXmlProperties().isEmpty() ) )
82578258
{
@@ -8820,7 +8821,7 @@ void QgisApp::makeMemoryLayerPermanent( QgsVectorLayer *layer )
88208821
QString source = newFilename;
88218822
if ( ! newLayerName.isEmpty() )
88228823
source += QStringLiteral( "|layername=%1" ).arg( newLayerName );
8823-
vl->setDataSource( source, vl->name(), QStringLiteral( "ogr" ), options );
8824+
vl->QgsMapLayer::setDataSource( source, vl->name(), QStringLiteral( "ogr" ), options );
88248825
vl->triggerRepaint();
88258826
this->visibleMessageBar()->pushMessage( tr( "Layer Saved" ),
88268827
tr( "Successfully saved scratch layer to <a href=\"%1\">%2</a>" ).arg( QUrl::fromLocalFile( newFilename ).toString(), QDir::toNativeSeparators( newFilename ) ),

‎src/core/vector/qgsvectorlayer.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1634,6 +1634,23 @@ bool QgsVectorLayer::readXml( const QDomNode &layer_node, QgsReadWriteContext &c
16341634

16351635
} // void QgsVectorLayer::readXml
16361636

1637+
void QgsVectorLayer::setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, bool loadDefaultStyleFlag )
1638+
{
1639+
QgsDataProvider::ProviderOptions options;
1640+
1641+
QgsDataProvider::ReadFlags flags = QgsDataProvider::ReadFlags();
1642+
if ( loadDefaultStyleFlag )
1643+
{
1644+
flags |= QgsDataProvider::FlagLoadDefaultStyle;
1645+
}
1646+
1647+
if ( mReadFlags & QgsMapLayer::FlagTrustLayerMetadata )
1648+
{
1649+
flags |= QgsDataProvider::FlagTrustDataSource;
1650+
}
1651+
setDataSourcePrivate( dataSource, baseName, provider, options, flags );
1652+
}
1653+
16371654
void QgsVectorLayer::setDataSourcePrivate( const QString &dataSource, const QString &baseName, const QString &provider,
16381655
const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags )
16391656
{

‎src/core/vector/qgsvectorlayer.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,6 +1131,18 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
11311131
*/
11321132
FeatureAvailability hasFeatures() const FINAL;
11331133

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

11351147
QString loadDefaultStyle( bool &resultFlag SIP_OUT ) FINAL;
11361148

‎src/gui/vector/qgsvectorlayerproperties.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -635,8 +635,8 @@ void QgsVectorLayerProperties::apply()
635635
const QString newSource = mSourceWidget->sourceUri();
636636
if ( newSource != mLayer->source() )
637637
{
638-
mLayer->setDataSource( newSource, mLayer->name(), mLayer->providerType(),
639-
QgsDataProvider::ProviderOptions(), QgsDataProvider::ReadFlags() );
638+
mLayer->QgsMapLayer::setDataSource( newSource, mLayer->name(), mLayer->providerType(),
639+
QgsDataProvider::ProviderOptions(), QgsDataProvider::ReadFlags() );
640640
}
641641
}
642642

0 commit comments

Comments
 (0)
Please sign in to comment.