QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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  const 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  const 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 }
QgsProjectMetadata::author
QString author() const
Returns the project author string.
Definition: qgsprojectmetadata.cpp:84
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:471
QgsAbstractMetadataBase::combine
virtual void combine(const QgsAbstractMetadataBase *other)
Combines the metadata from this object with the metadata from an other object.
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:72
QgsProjectMetadata::setAuthor
void setAuthor(const QString &author)
Sets the project author string.
Definition: qgsprojectmetadata.cpp:89
QgsProjectMetadata::combine
void combine(const QgsAbstractMetadataBase *other) override
Combines the metadata from this object with the metadata from an other object.
Definition: qgsprojectmetadata.cpp:58
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:79
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:94
QgsProjectMetadata::QgsProjectMetadata
QgsProjectMetadata()=default
Constructor for QgsProjectMetadata.
QgsAbstractMetadataBase
An abstract base class for metadata stores.
Definition: qgsabstractmetadatabase.h:56
QgsProjectMetadata::setCreationDateTime
void setCreationDateTime(const QDateTime &creationDateTime)
Sets the project's creation date/timestamp.
Definition: qgsprojectmetadata.cpp:99