QGIS API Documentation  3.20.0-Odense (decaadbb31)
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 
59 {
61 
62  if ( const QgsProjectMetadata *otherProjectMetadata = dynamic_cast< const QgsProjectMetadata * >( other ) )
63  {
64  if ( !otherProjectMetadata->author().isEmpty() )
65  mAuthor = otherProjectMetadata->author();
66 
67  if ( otherProjectMetadata->creationDateTime().isValid() )
68  mCreationDateTime = otherProjectMetadata->creationDateTime();
69  }
70 }
71 
72 bool QgsProjectMetadata::operator==( const QgsProjectMetadata &metadataOther ) const
73 {
74  return equals( metadataOther ) &&
75  mAuthor == metadataOther.mAuthor &&
76  mCreationDateTime == metadataOther.mCreationDateTime ;
77 }
78 
80 {
81  return new QgsProjectMetadata( *this );
82 }
83 
85 {
86  return mAuthor;
87 }
88 
89 void QgsProjectMetadata::setAuthor( const QString &author )
90 {
91  mAuthor = author;
92 }
93 
95 {
96  return mCreationDateTime;
97 }
98 
99 void QgsProjectMetadata::setCreationDateTime( const QDateTime &creationDateTime )
100 {
101  mCreationDateTime = creationDateTime;
102 }
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.
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.