Skip to content
Permalink
Browse files

Add new QgsProjectMetadata metadata class

For storing QgsProject metadata. Contains all metadata items
from QgsMetadataBase, plus adds author and creation datetime
metadata items.
  • Loading branch information
nyalldawson committed Mar 22, 2018
1 parent 1e05de0 commit 09aca080ec5c8d34791092fb324ba26ee1f2ecba
@@ -173,6 +173,7 @@
%Include metadata/qgslayermetadatavalidator.sip
%Include metadata/qgslayermetadataformatter.sip
%Include metadata/qgsmetadatabase.sip
%Include metadata/qgsprojectmetadata.sip
%Include processing/qgsprocessing.sip
%Include processing/qgsprocessingalgorithm.sip
%Include processing/qgsprocessingcontext.sip
@@ -133,8 +133,6 @@ Constructor for Constraint.
Constructor for QgsLayerMetadata.
%End

virtual ~QgsLayerMetadata();

QString fees() const;
%Docstring
Returns any fees associated with using the resource.
@@ -58,7 +58,7 @@ class QgsNativeMetadataBaseValidator : QgsMetadataValidator
%Docstring
A validator for the native base QGIS metadata schema definition.

.. versionadded:: 3.20
.. versionadded:: 3.2
%End

%TypeHeaderCode
@@ -81,7 +81,7 @@ Constructor for QgsNativeMetadataBaseValidator.
class QgsNativeMetadataValidator : QgsNativeMetadataBaseValidator
{
%Docstring
A validator for the native QGIS metadata schema definition.
A validator for the native QGIS layer metadata schema definition.

.. versionadded:: 3.0
%End
@@ -99,6 +99,30 @@ Constructor for QgsNativeMetadataValidator.
virtual bool validate( const QgsMetadataBase *metadata, QList< QgsMetadataValidator::ValidationResult > &results /Out/ ) const;


};


class QgsNativeProjectMetadataValidator : QgsNativeMetadataBaseValidator
{
%Docstring
A validator for the native QGIS project metadata schema definition.

.. versionadded:: 3.2
%End

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

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

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


};

/************************************************************************
@@ -0,0 +1,107 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/metadata/qgsprojectmetadata.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/




class QgsProjectMetadata : QgsMetadataBase
{
%Docstring
A structured metadata store for a map layer.

QgsProjectMetadata handles storage and management of the metadata
for a QgsProject. This class is an internal QGIS format with a common
metadata structure, which allows for code to access the metadata properties for
projects in a uniform way.

The metadata store is designed to be compatible with the Dublin Core metadata
specifications, and will be expanded to allow compatibility with ISO specifications
in future releases. However, the QGIS internal schema does not represent a superset
of all existing metadata schemas and accordingly conversion from specific
metadata formats to QgsProjectMetadata may result in a loss of information.

This class is designed to follow the specifications detailed in
the schema definition available at resources/qgis-resource-metadata.xsd
within the QGIS source code.

Metadata can be validated through the use of QgsLayerMetadataValidator
subclasses. E.g. validating against the native QGIS metadata schema can be performed
using QgsNativeProjectMetadataValidator.

.. versionadded:: 3.2
%End

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

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

QString author() const;
%Docstring
Returns the project author string.

.. seealso:: :py:func:`setAuthor`
%End

void setAuthor( const QString &author );
%Docstring
Sets the project ``author`` string

.. seealso:: :py:func:`author`
%End

QDateTime creationDateTime() const;
%Docstring
Returns the project's creation date/timestamp.

.. seealso:: :py:func:`setCreationDateTime`
%End

void setCreationDateTime( const QDateTime &creationDateTime );
%Docstring
Sets the project's creation date/timestamp.

.. seealso:: :py:func:`creationDateTime`
%End

bool readMetadataXml( const QDomElement &metadataElement );
%Docstring
Sets state from DOM document

:param metadataElement: The Dom element corresponding to ``resourceMetadata'' tag

:return: true if successful
%End

bool writeMetadataXml( QDomElement &metadataElement, QDomDocument &document ) const;
%Docstring
Stores state in DOM node

:param metadataElement: is a Dom element corresponding to ``resourceMetadata'' tag
:param document: is a the dom document being written

:return: true if successful
%End

bool operator==( const QgsProjectMetadata &metadataOther ) const;

};


/************************************************************************
* This file has been generated automatically from *
* *
* src/core/metadata/qgsprojectmetadata.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -76,6 +76,7 @@ SET(QGIS_CORE_SRCS
metadata/qgslayermetadatavalidator.cpp
metadata/qgslayermetadataformatter.cpp
metadata/qgsmetadatabase.cpp
metadata/qgsprojectmetadata.cpp

auth/qgsauthcertutils.cpp
auth/qgsauthconfig.cpp
@@ -993,6 +994,7 @@ SET(QGIS_CORE_HDRS
metadata/qgslayermetadatavalidator.h
metadata/qgslayermetadataformatter.h
metadata/qgsmetadatabase.h
metadata/qgsprojectmetadata.h

processing/qgsprocessing.h
processing/qgsprocessingalgorithm.h
@@ -217,8 +217,6 @@ class CORE_EXPORT QgsLayerMetadata : public QgsMetadataBase
*/
QgsLayerMetadata() = default;

virtual ~QgsLayerMetadata() = default;

/**
* Returns any fees associated with using the resource.
* An empty string will be returned if no fees are set.
@@ -17,7 +17,11 @@

#include "qgslayermetadatavalidator.h"
#include "qgslayermetadata.h"
#include "qgsprojectmetadata.h"

//
// QgsNativeMetadataBaseValidator
//

bool QgsNativeMetadataBaseValidator::validate( const QgsMetadataBase *metadata, QList<QgsMetadataValidator::ValidationResult> &results ) const
{
@@ -125,6 +129,10 @@ bool QgsNativeMetadataBaseValidator::validate( const QgsMetadataBase *metadata,
return result;
}

//
// QgsNativeMetadataValidator
//

bool QgsNativeMetadataValidator::validate( const QgsMetadataBase *baseMetadata, QList<ValidationResult> &results ) const
{
results.clear();
@@ -169,3 +177,34 @@ bool QgsNativeMetadataValidator::validate( const QgsMetadataBase *baseMetadata,
return result;
}


//
// QgsNativeProjectMetadataValidator
//

bool QgsNativeProjectMetadataValidator::validate( const QgsMetadataBase *baseMetadata, QList<QgsMetadataValidator::ValidationResult> &results ) const
{
results.clear();

const QgsProjectMetadata *metadata = dynamic_cast< const QgsProjectMetadata * >( baseMetadata );
if ( !metadata )
return false;

bool result = true;
if ( !QgsNativeMetadataBaseValidator::validate( metadata, results ) )
result = false;

if ( metadata->author().isEmpty() )
{
result = false;
results << ValidationResult( QObject::tr( "author" ), QObject::tr( "A project author is required." ) );
}

if ( !metadata->creationDateTime().isValid() )
{
result = false;
results << ValidationResult( QObject::tr( "creation" ), QObject::tr( "The project creation date/time is required." ) );
}

return result;
}
@@ -84,7 +84,7 @@ class CORE_EXPORT QgsMetadataValidator
* \ingroup core
* \class QgsNativeMetadataBaseValidator
* \brief A validator for the native base QGIS metadata schema definition.
* \since QGIS 3.20
* \since QGIS 3.2
*/

class CORE_EXPORT QgsNativeMetadataBaseValidator : public QgsMetadataValidator
@@ -105,7 +105,7 @@ class CORE_EXPORT QgsNativeMetadataBaseValidator : public QgsMetadataValidator
/**
* \ingroup core
* \class QgsNativeMetadataValidator
* \brief A validator for the native QGIS metadata schema definition.
* \brief A validator for the native QGIS layer metadata schema definition.
* \since QGIS 3.0
*/

@@ -123,4 +123,25 @@ class CORE_EXPORT QgsNativeMetadataValidator : public QgsNativeMetadataBaseValid

};

/**
* \ingroup core
* \class QgsNativeProjectMetadataValidator
* \brief A validator for the native QGIS project metadata schema definition.
* \since QGIS 3.2
*/

class CORE_EXPORT QgsNativeProjectMetadataValidator : public QgsNativeMetadataBaseValidator
{

public:

/**
* Constructor for QgsNativeProjectMetadataValidator.
*/
QgsNativeProjectMetadataValidator() = default;

bool validate( const QgsMetadataBase *metadata, QList< QgsMetadataValidator::ValidationResult > &results SIP_OUT ) const override;

};

#endif // QGSLAYERMETADATAVALIDATOR_H

0 comments on commit 09aca08

Please sign in to comment.
You can’t perform that action at this time.