Skip to content
Permalink
Browse files
Make saveLayerMetadata raise QgsNotSupportedException if saving metad…
…ata for uri is not supported

This allows us to disambiguate between "metadata storage for the
layer SHOULD be supported, but an error occurred while doing this"
vs "metadata storage for the layer will NEVER be supported" (eg for
a WFS layer or other read-only format)
  • Loading branch information
nyalldawson committed May 4, 2021
1 parent 64a23d2 commit 667fe63521b5fe3924055626882f85627798f95f
@@ -426,7 +426,7 @@ Loads a layer style defined by ``uri``
.. versionadded:: 3.10
%End

virtual bool saveLayerMetadata( const QString &uri, const QgsLayerMetadata &metadata, QString &errorMessage /Out/ );
virtual bool saveLayerMetadata( const QString &uri, const QgsLayerMetadata &metadata, QString &errorMessage /Out/ ) throw( QgsNotSupportedException );
%Docstring
Saves ``metadata`` to the layer corresponding to the specified ``uri``.

@@ -437,6 +437,10 @@ Saves ``metadata`` to the layer corresponding to the specified ``uri``.
- errorMessage: descriptive string of error if encountered


:raises :: py:class:`QgsNotSupportedException` if the provider does not support saving layer metadata for the
specified ``uri``.


.. versionadded:: 3.20
%End

@@ -233,7 +233,7 @@ Loads a layer style defined by ``uri``
.. versionadded:: 3.10
%End

bool saveLayerMetadata( const QString &providerKey, const QString &uri, const QgsLayerMetadata &metadata, QString &errorMessage /Out/ );
bool saveLayerMetadata( const QString &providerKey, const QString &uri, const QgsLayerMetadata &metadata, QString &errorMessage /Out/ ) throw( QgsNotSupportedException );
%Docstring
Saves ``metadata`` to the layer corresponding to the specified ``uri``.

@@ -245,6 +245,10 @@ Saves ``metadata`` to the layer corresponding to the specified ``uri``.
- errorMessage: descriptive string of error if encountered


:raises :: py:class:`QgsNotSupportedException` if the provider does not support saving layer metadata for the
specified ``uri``.


.. versionadded:: 3.20
%End

@@ -232,10 +232,9 @@ QString QgsProviderMetadata::loadStyle( const QString &, QString &errCause )
return QString();
}

bool QgsProviderMetadata::saveLayerMetadata( const QString &, const QgsLayerMetadata &, QString &errorMessage )
bool QgsProviderMetadata::saveLayerMetadata( const QString &, const QgsLayerMetadata &, QString & )
{
errorMessage = QObject::tr( "Provider %1 does not support writing layer metadata" ).arg( key() );
return false;
throw QgsNotSupportedException( QObject::tr( "Provider %1 does not support writing layer metadata" ).arg( key() ) );
}

bool QgsProviderMetadata::createDb( const QString &, QString &errCause )
@@ -483,9 +483,12 @@ class CORE_EXPORT QgsProviderMetadata : public QObject
*
* \returns TRUE if the metadata was successfully saved.
*
* \throws QgsNotSupportedException if the provider does not support saving layer metadata for the
* specified \a uri.
*
* \since QGIS 3.20
*/
virtual bool saveLayerMetadata( const QString &uri, const QgsLayerMetadata &metadata, QString &errorMessage SIP_OUT );
virtual bool saveLayerMetadata( const QString &uri, const QgsLayerMetadata &metadata, QString &errorMessage SIP_OUT ) SIP_THROW( QgsNotSupportedException );

/**
* Creates database by the provider on the path
@@ -668,8 +668,7 @@ bool QgsProviderRegistry::saveLayerMetadata( const QString &providerKey, const Q
return meta->saveLayerMetadata( uri, metadata, errorMessage );
else
{
errorMessage = QObject::tr( "Unable to load %1 provider" ).arg( providerKey );
return false;
throw QgsNotSupportedException( QObject::tr( "Unable to load %1 provider" ).arg( providerKey ) );
}
}

@@ -271,9 +271,12 @@ class CORE_EXPORT QgsProviderRegistry
*
* \returns TRUE if the metadata was successfully saved.
*
* \throws QgsNotSupportedException if the provider does not support saving layer metadata for the
* specified \a uri.
*
* \since QGIS 3.20
*/
bool saveLayerMetadata( const QString &providerKey, const QString &uri, const QgsLayerMetadata &metadata, QString &errorMessage SIP_OUT );
bool saveLayerMetadata( const QString &providerKey, const QString &uri, const QgsLayerMetadata &metadata, QString &errorMessage SIP_OUT ) SIP_THROW( QgsNotSupportedException );

/**
* Creates database by the provider on the path

0 comments on commit 667fe63

Please sign in to comment.