QGIS API Documentation  3.8.0-Zanzibar (11aff65)
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 
86 {
87  mCreationDateTime = creationDateTime;
88 }
virtual bool readMetadataXml(const QDomElement &metadataElement)
Sets state from DOM document.
void setCreationDateTime(const QDateTime &creationDateTime)
Sets the project&#39;s creation date/timestamp.
QString author() const
Returns the project author string.
bool readMetadataXml(const QDomElement &metadataElement) override
Sets state from DOM document.
void setAuthor(const QString &author)
Sets the project author string.
bool equals(const QgsAbstractMetadataBase &other) const
Tests whether the common metadata fields in this object are equal to other.
bool writeMetadataXml(QDomElement &metadataElement, QDomDocument &document) const override
Stores state in a DOM node.
QDateTime creationDateTime() const
Returns the project&#39;s creation date/timestamp.
virtual bool writeMetadataXml(QDomElement &metadataElement, QDomDocument &document) const
Stores state in a DOM node.
QgsProjectMetadata()=default
Constructor for QgsProjectMetadata.
bool operator==(const QgsProjectMetadata &metadataOther) const
QgsProjectMetadata * clone() const override
Clones the metadata object.
A structured metadata store for a map layer.