Skip to content

Commit 5600395

Browse files
committed
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...
1 parent cc3d67a commit 5600395

File tree

8 files changed

+463
-18
lines changed

8 files changed

+463
-18
lines changed

python/core/core.sip

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@
277277
%Include layertree/qgslayertreeutils.sip
278278

279279
%Include metadata/qgslayermetadata.sip
280+
%Include metadata/qgslayermetadatavalidator.sip
280281

281282
%Include processing/qgsprocessingalgorithm.sip
282283
%Include processing/qgsprocessingcontext.sip

python/core/metadata/qgslayermetadata.sip

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ class QgsLayerMetadata
253253

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

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

284284
void setTitle( const QString &title );
285285
%Docstring
286-
Sets the human readable title (name) of the resource, typically displayed in search results.
286+
Sets the human readable ``title`` (name) of the resource, typically displayed in search results.
287287
\see title()
288288
%End
289289

@@ -296,7 +296,7 @@ class QgsLayerMetadata
296296

297297
void setAbstract( const QString &abstract );
298298
%Docstring
299-
Sets a free-form abstract (description) of the resource.
299+
Sets a free-form ``abstract`` (description) of the resource.
300300
\see abstract()
301301
%End
302302

@@ -310,7 +310,7 @@ class QgsLayerMetadata
310310

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

325325
void setConstraints( const QgsLayerMetadata::ConstraintList &constraints );
326326
%Docstring
327-
Sets the list of constraints associated with using the resource.
327+
Sets the list of ``constraints`` associated with using the resource.
328328
\see constraints()
329329
%End
330330

@@ -337,7 +337,7 @@ class QgsLayerMetadata
337337

338338
void setRights( const QStringList &rights );
339339
%Docstring
340-
Sets a list of rights (attribution or copyright strings) associated with the resource.
340+
Sets a list of ``rights`` (attribution or copyright strings) associated with the resource.
341341
\see rights()
342342
%End
343343

@@ -350,7 +350,7 @@ class QgsLayerMetadata
350350

351351
void setEncoding( const QString &encoding );
352352
%Docstring
353-
Sets the character encoding of the data in the resource. Use an empty string if no encoding is set.
353+
Sets the character ``encoding`` of the data in the resource. Use an empty string if no encoding is set.
354354
\see encoding()
355355
%End
356356

@@ -401,7 +401,7 @@ class QgsLayerMetadata
401401

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

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

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

@@ -438,7 +438,7 @@ class QgsLayerMetadata
438438

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

@@ -458,15 +458,15 @@ class QgsLayerMetadata
458458

459459
void setContacts( const QgsLayerMetadata::ContactList &contacts );
460460
%Docstring
461-
Sets the list of contacts or entities associated with the resource. Any existing contacts
461+
Sets the list of ``contacts`` or entities associated with the resource. Any existing contacts
462462
will be replaced.
463463
\see contacts()
464464
\see addContact()
465465
%End
466466

467467
void addContact( const QgsLayerMetadata::Contact &contact );
468468
%Docstring
469-
Adds an individual contact to the existing contacts.
469+
Adds an individual ``contact`` to the existing contacts.
470470
\see contacts()
471471
\see setContacts()
472472
%End
@@ -488,20 +488,20 @@ class QgsLayerMetadata
488488

489489
void addLink( const QgsLayerMetadata::Link &link );
490490
%Docstring
491-
Adds an individual link to the existing links.
491+
Adds an individual ``link`` to the existing links.
492492
\see links()
493493
\see setLinks()
494494
%End
495495

496496
void saveToLayer( QgsMapLayer *layer ) const;
497497
%Docstring
498-
Saves the metadata to a layer's custom properties (see QgsMapLayer.setCustomProperty() ).
498+
Saves the metadata to a ``layer``'s custom properties (see QgsMapLayer.setCustomProperty() ).
499499
\see readFromLayer()
500500
%End
501501

502502
void readFromLayer( const QgsMapLayer *layer );
503503
%Docstring
504-
Reads the metadata state from a layer's custom properties (see QgsMapLayer.customProperty() ).
504+
Reads the metadata state from a ``layer``'s custom properties (see QgsMapLayer.customProperty() ).
505505
\see saveToLayer()
506506
%End
507507

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/************************************************************************
2+
* This file has been generated automatically from *
3+
* *
4+
* src/core/metadata/qgslayermetadatavalidator.h *
5+
* *
6+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
7+
************************************************************************/
8+
9+
10+
11+
12+
13+
14+
class QgsMetadataValidator
15+
{
16+
%Docstring
17+
Abstract base class for metadata validators.
18+
.. versionadded:: 3.0
19+
%End
20+
21+
%TypeHeaderCode
22+
#include "qgslayermetadatavalidator.h"
23+
%End
24+
public:
25+
26+
struct ValidationResult
27+
{
28+
29+
ValidationResult( const QString &section, const QString &note, const QVariant &identifier = QVariant() );
30+
%Docstring
31+
Constructor for ValidationResult.
32+
%End
33+
34+
QString section;
35+
%Docstring
36+
Metadata section which failed the validation
37+
%End
38+
39+
QVariant identifier;
40+
%Docstring
41+
Optional identifier for the failed metadata item.
42+
For instance, in list type metadata elements this
43+
will be set to the list index of the failed metadata
44+
item.
45+
%End
46+
47+
QString note;
48+
%Docstring
49+
The reason behind the validation failure.
50+
%End
51+
};
52+
53+
virtual ~QgsMetadataValidator();
54+
55+
virtual bool validate( const QgsLayerMetadata &metadata, QList< QgsMetadataValidator::ValidationResult > &results /Out/ ) const = 0;
56+
%Docstring
57+
Validates a ``metadata`` object, and returns true if the
58+
metadata is considered valid.
59+
If validation fails, the ``results`` list will be filled with a list of
60+
items describing why the validation failed and what needs to be rectified
61+
to fix the metadata.
62+
:rtype: bool
63+
%End
64+
65+
};
66+
67+
68+
69+
class QgsNativeMetadataValidator : QgsMetadataValidator
70+
{
71+
%Docstring
72+
A validator for the native QGIS metadata schema definition.
73+
.. versionadded:: 3.0
74+
%End
75+
76+
%TypeHeaderCode
77+
#include "qgslayermetadatavalidator.h"
78+
%End
79+
public:
80+
81+
QgsNativeMetadataValidator();
82+
%Docstring
83+
Constructor for QgsNativeMetadataValidator.
84+
%End
85+
86+
virtual bool validate( const QgsLayerMetadata &metadata, QList< QgsMetadataValidator::ValidationResult > &results /Out/ ) const;
87+
88+
};
89+
90+
/************************************************************************
91+
* This file has been generated automatically from *
92+
* *
93+
* src/core/metadata/qgslayermetadatavalidator.h *
94+
* *
95+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
96+
************************************************************************/

python/core/qgsmaplayer.sip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,7 @@ Return pointer to layer's undo stack
829829

830830
virtual void setMetadata( const QgsLayerMetadata &metadata );
831831
%Docstring
832-
Sets the layer's metadata store.
832+
Sets the layer's ``metadata`` store.
833833
.. versionadded:: 3.0
834834
\see metadata()
835835
\see metadataChanged()

src/core/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ SET(QGIS_CORE_SRCS
7272
layertree/qgslayertree.cpp
7373

7474
metadata/qgslayermetadata.cpp
75+
metadata/qgslayermetadatavalidator.cpp
7576

7677
auth/qgsauthcertutils.cpp
7778
auth/qgsauthconfig.cpp
@@ -858,6 +859,7 @@ SET(QGIS_CORE_HDRS
858859
composer/qgspaperitem.h
859860

860861
metadata/qgslayermetadata.h
862+
metadata/qgslayermetadatavalidator.h
861863

862864
processing/qgsprocessingalgorithm.h
863865
processing/qgsprocessingcontext.h

0 commit comments

Comments
 (0)