Skip to content
Permalink
Browse files

Add raw QgsProviderMetadata/QgsProviderRegistry API to save

QGIS layer metadata to a URI for the provider
  • Loading branch information
nyalldawson committed May 2, 2021
1 parent fb1ac59 commit 5d703a4afc4ed9f75e2c0d0b080f7678079a6eb4
@@ -423,6 +423,20 @@ Saves a layer style to provider
Loads a layer style defined by ``uri``

.. versionadded:: 3.10
%End

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

:param uri: uri of layer to store metadata for
:param metadata: layer metadata

:return: - ``True`` if the metadata was successfully saved.
- errorMessage: descriptive string of error if encountered


.. versionadded:: 3.20
%End

virtual bool createDb( const QString &dbPath, QString &errCause );
@@ -231,6 +231,21 @@ Saves a layer style to provider
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/ );
%Docstring
Saves ``metadata`` to the layer corresponding to the specified ``uri``.

:param providerKey: identifier of the provider
:param uri: uri of layer to store metadata for
:param metadata: layer metadata

:return: - ``True`` if the metadata was successfully saved.
- errorMessage: descriptive string of error if encountered


.. versionadded:: 3.20
%End

bool createDb( const QString &providerKey, const QString &dbPath, QString &errCause );
@@ -232,6 +232,12 @@ QString QgsProviderMetadata::loadStyle( const QString &, QString &errCause )
return QString();
}

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

bool QgsProviderMetadata::createDb( const QString &, QString &errCause )
{
errCause = QObject::tr( "Provider %1 has no %2 method" ).arg( key(), QStringLiteral( "createDb" ) );
@@ -43,6 +43,7 @@ class QgsTransaction;
class QgsRasterDataProvider;
class QgsMeshDataProvider;
class QgsAbstractDatabaseProviderConnection;
class QgsLayerMetadata;

struct QgsMesh;

@@ -472,6 +473,19 @@ class CORE_EXPORT QgsProviderMetadata : public QObject
*/
virtual QString loadStyle( const QString &uri, QString &errCause );

/**
* Saves \a metadata to the layer corresponding to the specified \a uri.
*
* \param uri uri of layer to store metadata for
* \param metadata layer metadata
* \param errorMessage descriptive string of error if encountered
*
* \returns TRUE if the metadata was successfully saved.
*
* \since QGIS 3.20
*/
virtual bool saveLayerMetadata( const QString &uri, const QgsLayerMetadata &metadata, QString &errorMessage SIP_OUT );

/**
* Creates database by the provider on the path
* \since QGIS 3.10
@@ -661,6 +661,18 @@ QString QgsProviderRegistry::loadStyle( const QString &providerKey, const QStrin
return ret;
}

bool QgsProviderRegistry::saveLayerMetadata( const QString &providerKey, const QString &uri, const QgsLayerMetadata &metadata, QString &errorMessage )
{
errorMessage.clear();
if ( QgsProviderMetadata *meta = findMetadata_( mProviders, providerKey ) )
return meta->saveLayerMetadata( uri, metadata, errorMessage );
else
{
errorMessage = QObject::tr( "Unable to load %1 provider" ).arg( providerKey );
return false;
}
}

bool QgsProviderRegistry::createDb( const QString &providerKey, const QString &dbPath, QString &errCause )
{
QgsProviderMetadata *meta = findMetadata_( mProviders, providerKey );
@@ -261,6 +261,20 @@ class CORE_EXPORT QgsProviderRegistry
*/
QString loadStyle( const QString &providerKey, const QString &uri, QString &errCause );

/**
* Saves \a metadata to the layer corresponding to the specified \a uri.
*
* \param providerKey identifier of the provider
* \param uri uri of layer to store metadata for
* \param metadata layer metadata
* \param errorMessage descriptive string of error if encountered
*
* \returns TRUE if the metadata was successfully saved.
*
* \since QGIS 3.20
*/
bool saveLayerMetadata( const QString &providerKey, const QString &uri, const QgsLayerMetadata &metadata, QString &errorMessage SIP_OUT );

/**
* Creates database by the provider on the path
* \since QGIS 3.10

0 comments on commit 5d703a4

Please sign in to comment.