Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QgsMapLayer::setDataSource don't require layer name, provider #58953

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions python/PyQt6/core/auto_generated/qgsmaplayer.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -1327,19 +1327,20 @@ Write just the symbology information for the layer into the document
%End


void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, bool loadDefaultStyleFlag = false );
void setDataSource( const QString &dataSource, const QString &baseName = QString(), const QString &provider = QString(), bool loadDefaultStyleFlag = false );
%Docstring
Updates the data source of the layer.

The ``dataSource`` argument must specify the new data source string for the layer. The format varies depending on
the specified data ``provider`` in use. See :py:class:`QgsDataSourceUri` and the documentation for the various :py:class:`QgsMapLayer`
subclasses for further details on data source strings.

The ``baseName`` argument specifies the user-visible name to use for the layer. (See :py:func:`~QgsMapLayer.name` or :py:func:`~QgsMapLayer.setName`).
The ``baseName`` argument specifies the user-visible name to use for the layer. (See :py:func:`~QgsMapLayer.name` or :py:func:`~QgsMapLayer.setName`). If not
specified, then the current name will be left unchanged (since QGIS 3.40).

The ``provider`` argument is used to specify the unique key of the data provider to use for
the layer. This must match one of the values returned by :py:func:`QgsProviderRegistry.instance()`->:py:func:`~QgsMapLayer.providerList`.
(See :py:func:`~QgsMapLayer.providerType`).
(See :py:func:`~QgsMapLayer.providerType`). If not specified, then the current data provider will be used (since QGIS 3.40).

If ``loadDefaultStyleFlag`` is set to ``True`` then the layer's existing style will be reset to the default
for the data source.
Expand Down
7 changes: 4 additions & 3 deletions python/core/auto_generated/qgsmaplayer.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -1327,19 +1327,20 @@ Write just the symbology information for the layer into the document
%End


void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, bool loadDefaultStyleFlag = false );
void setDataSource( const QString &dataSource, const QString &baseName = QString(), const QString &provider = QString(), bool loadDefaultStyleFlag = false );
%Docstring
Updates the data source of the layer.

The ``dataSource`` argument must specify the new data source string for the layer. The format varies depending on
the specified data ``provider`` in use. See :py:class:`QgsDataSourceUri` and the documentation for the various :py:class:`QgsMapLayer`
subclasses for further details on data source strings.

The ``baseName`` argument specifies the user-visible name to use for the layer. (See :py:func:`~QgsMapLayer.name` or :py:func:`~QgsMapLayer.setName`).
The ``baseName`` argument specifies the user-visible name to use for the layer. (See :py:func:`~QgsMapLayer.name` or :py:func:`~QgsMapLayer.setName`). If not
specified, then the current name will be left unchanged (since QGIS 3.40).

The ``provider`` argument is used to specify the unique key of the data provider to use for
the layer. This must match one of the values returned by :py:func:`QgsProviderRegistry.instance()`->:py:func:`~QgsMapLayer.providerList`.
(See :py:func:`~QgsMapLayer.providerType`).
(See :py:func:`~QgsMapLayer.providerType`). If not specified, then the current data provider will be used (since QGIS 3.40).

If ``loadDefaultStyleFlag`` is set to ``True`` then the layer's existing style will be reset to the default
for the data source.
Expand Down
5 changes: 4 additions & 1 deletion src/core/qgsmaplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2444,7 +2444,10 @@ void QgsMapLayer::setDataSource( const QString &dataSource, const QString &baseN
{
flags |= Qgis::DataProviderReadFlag::TrustDataSource;
}
setDataSource( dataSource, baseName, provider, options, flags );
setDataSource( dataSource,
baseName.isEmpty() ? mLayerName : baseName,
provider.isEmpty() ? mProviderKey : provider,
options, flags );
}

void QgsMapLayer::setDataSource( const QString &dataSource, const QString &baseName, const QString &provider,
Expand Down
7 changes: 4 additions & 3 deletions src/core/qgsmaplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -1399,11 +1399,12 @@ class CORE_EXPORT QgsMapLayer : public QObject
* the specified data \a provider in use. See QgsDataSourceUri and the documentation for the various QgsMapLayer
* subclasses for further details on data source strings.
*
* The \a baseName argument specifies the user-visible name to use for the layer. (See name() or setName()).
* The \a baseName argument specifies the user-visible name to use for the layer. (See name() or setName()). If not
* specified, then the current name will be left unchanged (since QGIS 3.40).
*
* The \a provider argument is used to specify the unique key of the data provider to use for
* the layer. This must match one of the values returned by QgsProviderRegistry::instance()->providerList().
* (See providerType()).
* (See providerType()). If not specified, then the current data provider will be used (since QGIS 3.40).
*
* If \a loadDefaultStyleFlag is set to TRUE then the layer's existing style will be reset to the default
* for the data source.
Expand All @@ -1421,7 +1422,7 @@ class CORE_EXPORT QgsMapLayer : public QObject
* \see dataSourceChanged()
* \since QGIS 3.20
*/
void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, bool loadDefaultStyleFlag = false );
void setDataSource( const QString &dataSource, const QString &baseName = QString(), const QString &provider = QString(), bool loadDefaultStyleFlag = false );

/**
* Updates the data source of the layer.
Expand Down
Loading