QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
qgsmeshtimesettings.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmeshtimesettings.cpp
3 -- ---------------------
4  begin : March 2019
5  copyright : (C) 2019 by Peter Petrik
6  email : zilolv 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 "qgsmeshtimesettings.h"
19 
21 
22 QgsMeshTimeSettings::QgsMeshTimeSettings( double relativeTimeOffsetHours, const QString &relativeTimeFormat )
23  : mUseAbsoluteTime( false )
24  , mRelativeTimeOffsetHours( relativeTimeOffsetHours )
25  , mRelativeTimeFormat( relativeTimeFormat )
26 {}
27 
29  : mUseAbsoluteTime( true )
30  , mAbsoluteTimeReferenceTime( absoluteTimeReferenceTime )
31  , mAbsoluteTimeFormat( absoluteTimeFormat )
32 {}
33 
34 QDomElement QgsMeshTimeSettings::writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const
35 {
36  Q_UNUSED( context )
37  QDomElement elem = doc.createElement( QStringLiteral( "mesh-time-settings" ) );
38  elem.setAttribute( QStringLiteral( "use-absolute-time" ), mUseAbsoluteTime ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
39  elem.setAttribute( QStringLiteral( "relative-time-offset-hours" ), mRelativeTimeOffsetHours );
40  elem.setAttribute( QStringLiteral( "relative-time-format" ), mRelativeTimeFormat );
41  elem.setAttribute( QStringLiteral( "absolute-time-reference-time" ), mAbsoluteTimeReferenceTime.toString() );
42  elem.setAttribute( QStringLiteral( "absolute-time-format" ), mAbsoluteTimeFormat );
43  return elem;
44 }
45 
46 void QgsMeshTimeSettings::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
47 {
48  Q_UNUSED( context )
49  mUseAbsoluteTime = elem.attribute( QStringLiteral( "use-absolute-time" ) ).toInt(); //bool
50  mRelativeTimeOffsetHours = elem.attribute( QStringLiteral( "relative-time-offset-hours" ) ).toDouble();
51  mRelativeTimeFormat = elem.attribute( QStringLiteral( "relative-time-format" ) );
52  mAbsoluteTimeReferenceTime = QDateTime::fromString( elem.attribute( QStringLiteral( "absolute-time-reference-time" ) ) );
53  mAbsoluteTimeFormat = elem.attribute( QStringLiteral( "absolute-time-format" ) );
54 }
55 
57 {
58  return mUseAbsoluteTime;
59 }
60 
62 {
63  mUseAbsoluteTime = useAbsoluteTime;
64 }
65 
66 
68 {
69  return mRelativeTimeOffsetHours;
70 }
71 
73 {
74  mRelativeTimeOffsetHours = relativeTimeOffsetHours;
75 }
76 
78 {
79  return mRelativeTimeFormat;
80 }
81 
83 {
84  mRelativeTimeFormat = relativeTimeFormat;
85 }
86 
88 {
89  return mAbsoluteTimeReferenceTime;
90 }
91 
93 {
94  mAbsoluteTimeReferenceTime = absoluteTimeReferenceTime;
95 }
96 
98 {
99  return mAbsoluteTimeFormat;
100 }
101 
103 {
104  mAbsoluteTimeFormat = absoluteTimeFormat;
105 }
void setRelativeTimeFormat(const QString &relativeTimeFormat)
Sets format used for relative time.
The class is used as a container of context for various read/write operations on other objects...
void setUseAbsoluteTime(bool useAbsoluteTime)
Sets use absolute time flag.
QgsMeshTimeSettings()
Default constructor for relative time formate and 0 offset.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Reads configuration from the given DOM element.
void setAbsoluteTimeFormat(const QString &absoluteTimeFormat)
Sets format used for absolute time.
double relativeTimeOffsetHours() const
Returns number of offset hours for relative time formatting.
QString absoluteTimeFormat() const
Returns format used for absolute time.
void setRelativeTimeOffsetHours(double relativeTimeOffsetHours)
Sets number of offset hours for relative time formatting.
bool useAbsoluteTime() const
Returns whether to use absolute time format.
QDateTime absoluteTimeReferenceTime() const
Returns reference time used for absolute time format.
void setAbsoluteTimeReferenceTime(const QDateTime &absoluteTimeReferenceTime)
Sets reference time used for absolute time format.
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Writes configuration to a new DOM element.
QString relativeTimeFormat() const
Returns format used for relative time.