Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add metadata validator
Adds a new abstract base class QgsMetadataValidator for validating
metadata against standard schemas.

Initially only QgsNativeMetadataValidator for validating against
the native QGIS metadata schema is implemented.

In future this could be extended with Dublin Core, ISO 19115
validators, etc...
  • Loading branch information
nyalldawson committed May 3, 2017
1 parent cc3d67a commit 5600395
Show file tree
Hide file tree
Showing 8 changed files with 463 additions and 18 deletions.
1 change: 1 addition & 0 deletions python/core/core.sip
Expand Up @@ -277,6 +277,7 @@
%Include layertree/qgslayertreeutils.sip

%Include metadata/qgslayermetadata.sip
%Include metadata/qgslayermetadatavalidator.sip

%Include processing/qgsprocessingalgorithm.sip
%Include processing/qgsprocessingcontext.sip
Expand Down
32 changes: 16 additions & 16 deletions python/core/metadata/qgslayermetadata.sip
Expand Up @@ -253,7 +253,7 @@ class QgsLayerMetadata

void setLanguage( const QString &language );
%Docstring
Sets the human language associated with the resource. While a formal vocabulary is not imposed,
Sets the human ``language`` associated with the resource. While a formal vocabulary is not imposed,
ideally values should be taken from the ISO 639.2 or ISO 3166 specifications,
e.g. 'ENG' or 'SPA' (ISO 639.2) or 'EN-AU' (ISO 3166).
\see language()
Expand All @@ -269,7 +269,7 @@ class QgsLayerMetadata

void setType( const QString &type );
%Docstring
Sets the type (nature) of the resource. While a formal vocabulary is not imposed, it is advised
Sets the ``type`` (nature) of the resource. While a formal vocabulary is not imposed, it is advised
to use the ISO 19115 MD_ScopeCode values. E.g. 'dataset' or 'series'.
\see type()
%End
Expand All @@ -283,7 +283,7 @@ class QgsLayerMetadata

void setTitle( const QString &title );
%Docstring
Sets the human readable title (name) of the resource, typically displayed in search results.
Sets the human readable ``title`` (name) of the resource, typically displayed in search results.
\see title()
%End

Expand All @@ -296,7 +296,7 @@ class QgsLayerMetadata

void setAbstract( const QString &abstract );
%Docstring
Sets a free-form abstract (description) of the resource.
Sets a free-form ``abstract`` (description) of the resource.
\see abstract()
%End

Expand All @@ -310,7 +310,7 @@ class QgsLayerMetadata

void setFees( const QString &fees );
%Docstring
Sets the fees associated with using the resource.
Sets the ``fees`` associated with using the resource.
Use an empty string if no fees are set.
\see fees()
%End
Expand All @@ -324,7 +324,7 @@ class QgsLayerMetadata

void setConstraints( const QgsLayerMetadata::ConstraintList &constraints );
%Docstring
Sets the list of constraints associated with using the resource.
Sets the list of ``constraints`` associated with using the resource.
\see constraints()
%End

Expand All @@ -337,7 +337,7 @@ class QgsLayerMetadata

void setRights( const QStringList &rights );
%Docstring
Sets a list of rights (attribution or copyright strings) associated with the resource.
Sets a list of ``rights`` (attribution or copyright strings) associated with the resource.
\see rights()
%End

Expand All @@ -350,7 +350,7 @@ class QgsLayerMetadata

void setEncoding( const QString &encoding );
%Docstring
Sets the character encoding of the data in the resource. Use an empty string if no encoding is set.
Sets the character ``encoding`` of the data in the resource. Use an empty string if no encoding is set.
\see encoding()
%End

Expand Down Expand Up @@ -401,7 +401,7 @@ class QgsLayerMetadata

void setKeywords( const KeywordMap &keywords );
%Docstring
Sets the keywords map, which is a set of descriptive keywords associated with the resource.
Sets the ``keywords`` map, which is a set of descriptive keywords associated with the resource.

The map key is the vocabulary string and map value is a list of keywords for that vocabulary.
Calling this replaces any existing keyword vocabularies.
Expand All @@ -415,7 +415,7 @@ class QgsLayerMetadata

void addKeywords( const QString &vocabulary, const QStringList &keywords );
%Docstring
Adds a list of descriptive keywords for a specified vocabulary. Any existing
Adds a list of descriptive ``keywords`` for a specified ``vocabulary``. Any existing
keywords for the same vocabulary will be replaced. Other vocabularies
will not be affected.

Expand All @@ -438,7 +438,7 @@ class QgsLayerMetadata

QStringList keywords( const QString &vocabulary ) const;
%Docstring
Returns a list of keywords for the specified vocabulary.
Returns a list of keywords for the specified ``vocabulary``.
If the vocabulary is not contained in the metadata, an empty
list will be returned.

Expand All @@ -458,15 +458,15 @@ class QgsLayerMetadata

void setContacts( const QgsLayerMetadata::ContactList &contacts );
%Docstring
Sets the list of contacts or entities associated with the resource. Any existing contacts
Sets the list of ``contacts`` or entities associated with the resource. Any existing contacts
will be replaced.
\see contacts()
\see addContact()
%End

void addContact( const QgsLayerMetadata::Contact &contact );
%Docstring
Adds an individual contact to the existing contacts.
Adds an individual ``contact`` to the existing contacts.
\see contacts()
\see setContacts()
%End
Expand All @@ -488,20 +488,20 @@ class QgsLayerMetadata

void addLink( const QgsLayerMetadata::Link &link );
%Docstring
Adds an individual link to the existing links.
Adds an individual ``link`` to the existing links.
\see links()
\see setLinks()
%End

void saveToLayer( QgsMapLayer *layer ) const;
%Docstring
Saves the metadata to a layer's custom properties (see QgsMapLayer.setCustomProperty() ).
Saves the metadata to a ``layer``'s custom properties (see QgsMapLayer.setCustomProperty() ).
\see readFromLayer()
%End

void readFromLayer( const QgsMapLayer *layer );
%Docstring
Reads the metadata state from a layer's custom properties (see QgsMapLayer.customProperty() ).
Reads the metadata state from a ``layer``'s custom properties (see QgsMapLayer.customProperty() ).
\see saveToLayer()
%End

Expand Down
96 changes: 96 additions & 0 deletions python/core/metadata/qgslayermetadatavalidator.sip
@@ -0,0 +1,96 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/metadata/qgslayermetadatavalidator.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/






class QgsMetadataValidator
{
%Docstring
Abstract base class for metadata validators.
.. versionadded:: 3.0
%End

%TypeHeaderCode
#include "qgslayermetadatavalidator.h"
%End
public:

struct ValidationResult
{

ValidationResult( const QString &section, const QString &note, const QVariant &identifier = QVariant() );
%Docstring
Constructor for ValidationResult.
%End

QString section;
%Docstring
Metadata section which failed the validation
%End

QVariant identifier;
%Docstring
Optional identifier for the failed metadata item.
For instance, in list type metadata elements this
will be set to the list index of the failed metadata
item.
%End

QString note;
%Docstring
The reason behind the validation failure.
%End
};

virtual ~QgsMetadataValidator();

virtual bool validate( const QgsLayerMetadata &metadata, QList< QgsMetadataValidator::ValidationResult > &results /Out/ ) const = 0;
%Docstring
Validates a ``metadata`` object, and returns true if the
metadata is considered valid.
If validation fails, the ``results`` list will be filled with a list of
items describing why the validation failed and what needs to be rectified
to fix the metadata.
:rtype: bool
%End

};



class QgsNativeMetadataValidator : QgsMetadataValidator
{
%Docstring
A validator for the native QGIS metadata schema definition.
.. versionadded:: 3.0
%End

%TypeHeaderCode
#include "qgslayermetadatavalidator.h"
%End
public:

QgsNativeMetadataValidator();
%Docstring
Constructor for QgsNativeMetadataValidator.
%End

virtual bool validate( const QgsLayerMetadata &metadata, QList< QgsMetadataValidator::ValidationResult > &results /Out/ ) const;

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/core/metadata/qgslayermetadatavalidator.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
2 changes: 1 addition & 1 deletion python/core/qgsmaplayer.sip
Expand Up @@ -829,7 +829,7 @@ Return pointer to layer's undo stack

virtual void setMetadata( const QgsLayerMetadata &metadata );
%Docstring
Sets the layer's metadata store.
Sets the layer's ``metadata`` store.
.. versionadded:: 3.0
\see metadata()
\see metadataChanged()
Expand Down
2 changes: 2 additions & 0 deletions src/core/CMakeLists.txt
Expand Up @@ -72,6 +72,7 @@ SET(QGIS_CORE_SRCS
layertree/qgslayertree.cpp

metadata/qgslayermetadata.cpp
metadata/qgslayermetadatavalidator.cpp

auth/qgsauthcertutils.cpp
auth/qgsauthconfig.cpp
Expand Down Expand Up @@ -858,6 +859,7 @@ SET(QGIS_CORE_HDRS
composer/qgspaperitem.h

metadata/qgslayermetadata.h
metadata/qgslayermetadatavalidator.h

processing/qgsprocessingalgorithm.h
processing/qgsprocessingcontext.h
Expand Down

0 comments on commit 5600395

Please sign in to comment.