QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
qgsprojectmetadata.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsprojectmetadata.cpp
3 --------------------
4 begin : March 2018
5 copyright : (C) 2018 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#include "qgsprojectmetadata.h"
19#include <QDomNode>
20#include <QDomDocument>
21
22bool QgsProjectMetadata::readMetadataXml( const QDomElement &metadataElement )
23{
25
26 QDomNode mnl;
27
28 // set author
29 mnl = metadataElement.namedItem( QStringLiteral( "author" ) );
30 mAuthor = mnl.toElement().text();
31
32 if ( !mDates.contains( Qgis::MetadataDateType::Created ) )
33 {
34 // creation datetime -- old format
35 mnl = metadataElement.namedItem( QStringLiteral( "creation" ) );
36 const QDateTime creationDateTime = QDateTime::fromString( mnl.toElement().text(), Qt::ISODate );
38 }
39
40 return true;
41}
42
43bool QgsProjectMetadata::writeMetadataXml( QDomElement &metadataElement, QDomDocument &document ) const
44{
45 QgsAbstractMetadataBase::writeMetadataXml( metadataElement, document );
46
47 // author
48 QDomElement author = document.createElement( QStringLiteral( "author" ) );
49 const QDomText authorText = document.createTextNode( mAuthor );
50 author.appendChild( authorText );
51 metadataElement.appendChild( author );
52
53 // creation datetime
54 QDomElement creation = document.createElement( QStringLiteral( "creation" ) );
55 const QDomText creationText = document.createTextNode( mDates.value( Qgis::MetadataDateType::Created ).toString( Qt::ISODate ) );
56 creation.appendChild( creationText );
57 metadataElement.appendChild( creation );
58
59 return true;
60}
61
63{
65
66 if ( const QgsProjectMetadata *otherProjectMetadata = dynamic_cast< const QgsProjectMetadata * >( other ) )
67 {
68 if ( !otherProjectMetadata->author().isEmpty() )
69 mAuthor = otherProjectMetadata->author();
70 }
71}
72
73bool QgsProjectMetadata::operator==( const QgsProjectMetadata &metadataOther ) const
74{
75 return equals( metadataOther ) &&
76 mAuthor == metadataOther.mAuthor;
77}
78
80{
81 return new QgsProjectMetadata( *this );
82}
83
85{
86 return mAuthor;
87}
88
89void QgsProjectMetadata::setAuthor( const QString &author )
90{
91 mAuthor = author;
92}
93
95{
97}
98
99void QgsProjectMetadata::setCreationDateTime( const QDateTime &creationDateTime )
100{
102}
@ Created
Date created.
An abstract base class for metadata stores.
virtual bool writeMetadataXml(QDomElement &metadataElement, QDomDocument &document) const
Stores state in a DOM node.
virtual void combine(const QgsAbstractMetadataBase *other)
Combines the metadata from this object with the metadata from an other object.
QMap< Qgis::MetadataDateType, QDateTime > mDates
Metadata dates.
bool equals(const QgsAbstractMetadataBase &other) const
Tests whether the common metadata fields in this object are equal to other.
virtual bool readMetadataXml(const QDomElement &metadataElement)
Sets state from DOM document.
A structured metadata store for a map layer.
QString author() const
Returns the project author string.
QgsProjectMetadata()=default
Constructor for QgsProjectMetadata.
bool writeMetadataXml(QDomElement &metadataElement, QDomDocument &document) const override
Stores state in a DOM node.
void combine(const QgsAbstractMetadataBase *other) override
Combines the metadata from this object with the metadata from an other object.
void setCreationDateTime(const QDateTime &creationDateTime)
Sets the project's creation date/timestamp.
bool readMetadataXml(const QDomElement &metadataElement) override
Sets state from DOM document.
bool operator==(const QgsProjectMetadata &metadataOther) const
void setAuthor(const QString &author)
Sets the project author string.
QgsProjectMetadata * clone() const override
Clones the metadata object.
QDateTime creationDateTime() const
Returns the project's creation date/timestamp.