QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 
22 bool 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  // creation datetime
33  mnl = metadataElement.namedItem( QStringLiteral( "creation" ) );
34  mCreationDateTime = QDateTime::fromString( mnl.toElement().text(), Qt::ISODate );
35 
36  return true;
37 }
38 
39 bool QgsProjectMetadata::writeMetadataXml( QDomElement &metadataElement, QDomDocument &document ) const
40 {
41  QgsAbstractMetadataBase::writeMetadataXml( metadataElement, document );
42 
43  // author
44  QDomElement author = document.createElement( QStringLiteral( "author" ) );
45  QDomText authorText = document.createTextNode( mAuthor );
46  author.appendChild( authorText );
47  metadataElement.appendChild( author );
48 
49  // creation datetime
50  QDomElement creation = document.createElement( QStringLiteral( "creation" ) );
51  QDomText creationText = document.createTextNode( mCreationDateTime.toString( Qt::ISODate ) );
52  creation.appendChild( creationText );
53  metadataElement.appendChild( creation );
54 
55  return true;
56 }
57 
58 bool QgsProjectMetadata::operator==( const QgsProjectMetadata &metadataOther ) const
59 {
60  return equals( metadataOther ) &&
61  mAuthor == metadataOther.mAuthor &&
62  mCreationDateTime == metadataOther.mCreationDateTime ;
63 }
64 
66 {
67  return new QgsProjectMetadata( *this );
68 }
69 
71 {
72  return mAuthor;
73 }
74 
75 void QgsProjectMetadata::setAuthor( const QString &author )
76 {
77  mAuthor = author;
78 }
79 
81 {
82  return mCreationDateTime;
83 }
84 
85 void QgsProjectMetadata::setCreationDateTime( const QDateTime &creationDateTime )
86 {
87  mCreationDateTime = creationDateTime;
88 }
QgsProjectMetadata::author
QString author() const
Returns the project author string.
Definition: qgsprojectmetadata.cpp:70
QgsProjectMetadata
A structured metadata store for a map layer.
Definition: qgsprojectmetadata.h:53
QgsProjectMetadata::readMetadataXml
bool readMetadataXml(const QDomElement &metadataElement) override
Sets state from DOM document.
Definition: qgsprojectmetadata.cpp:22
QgsAbstractMetadataBase::equals
bool equals(const QgsAbstractMetadataBase &other) const
Tests whether the common metadata fields in this object are equal to other.
Definition: qgsabstractmetadatabase.cpp:435
QgsAbstractMetadataBase::readMetadataXml
virtual bool readMetadataXml(const QDomElement &metadataElement)
Sets state from DOM document.
Definition: qgsabstractmetadatabase.cpp:173
QgsProjectMetadata::operator==
bool operator==(const QgsProjectMetadata &metadataOther) const
Definition: qgsprojectmetadata.cpp:58
QgsProjectMetadata::setAuthor
void setAuthor(const QString &author)
Sets the project author string.
Definition: qgsprojectmetadata.cpp:75
qgsprojectmetadata.h
QgsProjectMetadata::writeMetadataXml
bool writeMetadataXml(QDomElement &metadataElement, QDomDocument &document) const override
Stores state in a DOM node.
Definition: qgsprojectmetadata.cpp:39
QgsProjectMetadata::clone
QgsProjectMetadata * clone() const override
Clones the metadata object.
Definition: qgsprojectmetadata.cpp:65
QgsAbstractMetadataBase::writeMetadataXml
virtual bool writeMetadataXml(QDomElement &metadataElement, QDomDocument &document) const
Stores state in a DOM node.
Definition: qgsabstractmetadatabase.cpp:287
QgsProjectMetadata::creationDateTime
QDateTime creationDateTime() const
Returns the project's creation date/timestamp.
Definition: qgsprojectmetadata.cpp:80
QgsProjectMetadata::QgsProjectMetadata
QgsProjectMetadata()=default
Constructor for QgsProjectMetadata.
QgsProjectMetadata::setCreationDateTime
void setCreationDateTime(const QDateTime &creationDateTime)
Sets the project's creation date/timestamp.
Definition: qgsprojectmetadata.cpp:85