Skip to content

Commit

Permalink
[API] Move specific deprecated QgsVectorLayer::setDataSource to QgsMa…
Browse files Browse the repository at this point in the history
…pLayer
  • Loading branch information
rldhont committed Apr 29, 2021
1 parent b60f5a4 commit e5e8efe
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 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
20 changes: 19 additions & 1 deletion src/core/qgsmaplayer.cpp
Expand Up @@ -1638,9 +1638,12 @@ bool QgsMapLayer::writeStyle( QDomNode &node, QDomDocument &doc, QString &errorM
return false;
}


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

QgsDataProvider::ReadFlags flags = QgsDataProvider::ReadFlags();
if ( loadDefaultStyleFlag )
{
Expand All @@ -1654,6 +1657,21 @@ void QgsMapLayer::setDataSource( const QString &dataSource, const QString &baseN
setDataSource( dataSource, baseName, provider, options, flags );
}

void QgsMapLayer::setDataSource( const QString &dataSource, const QString &baseName, const QString &provider,
const QgsDataProvider::ProviderOptions &options, bool loadDefaultStyleFlag )
{
QgsDataProvider::ReadFlags flags = QgsDataProvider::ReadFlags();
if ( loadDefaultStyleFlag )
{
flags |= QgsDataProvider::FlagLoadDefaultStyle;
}

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

void QgsMapLayer::setDataSource( const QString &dataSource, const QString &baseName, const QString &provider,
const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags )
Expand Down
16 changes: 16 additions & 0 deletions src/core/qgsmaplayer.h
Expand Up @@ -984,6 +984,22 @@ class CORE_EXPORT QgsMapLayer : public QObject
StyleCategories categories = AllStyleCategories ) const;


/**
* Updates 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.
*
* This method was defined in QgsVectorLayer since 2.10 and was marked as deprecated since 3.2
*
* \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
* \see dataSourceChanged()
* \since QGIS 3.20
*/
void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, bool loadDefaultStyleFlag = false );

/**
* Updates 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.
Expand Down

0 comments on commit e5e8efe

Please sign in to comment.