QGIS API Documentation 3.99.0-Master (357b655ed83)
Loading...
Searching...
No Matches
qgsprojecttimesettings.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsprojecttimesettings.cpp
3 ---------------
4 begin : February 2020
5 copyright : (C) 2020 by Samweli Mwakisambwe
6 email : samweli at kartoza 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
19
20#include "qgis.h"
21#include "qgsunittypes.h"
22
23#include <QDomElement>
24#include <QString>
25
26#include "moc_qgsprojecttimesettings.cpp"
27
28using namespace Qt::StringLiterals;
29
31 : QObject( parent )
32{
33
34}
35
41
46
48{
49 if ( range == mRange )
50 return;
51 mRange = range;
52
54}
55
56bool QgsProjectTimeSettings::readXml( const QDomElement &element, const QgsReadWriteContext & )
57{
58 const QDomElement temporalElement = element.firstChildElement( u"TemporalRange"_s );
59 if ( !temporalElement.isNull() )
60 {
61 const QDomNode begin = temporalElement.namedItem( u"start"_s );
62 const QDomNode end = temporalElement.namedItem( u"end"_s );
63
64 const QDateTime beginDate = QDateTime::fromString( begin.toElement().text(), Qt::ISODate );
65 const QDateTime endDate = QDateTime::fromString( end.toElement().text(), Qt::ISODate );
66
67 setTemporalRange( QgsDateTimeRange( beginDate, endDate ) );
68
69 }
70
71 mTimeStepUnit = QgsUnitTypes::decodeTemporalUnit( element.attribute( u"timeStepUnit"_s, QgsUnitTypes::encodeUnit( Qgis::TemporalUnit::Hours ) ) );
72 mTimeStep = element.attribute( u"timeStep"_s, "1" ).toDouble();
73 mFrameRate = element.attribute( u"frameRate"_s, "1" ).toDouble();
74 mCumulativeTemporalRange = element.attribute( u"cumulativeTemporalRange"_s, "0" ).toInt();
75
76 mTotalMovieFrames = element.attribute( u"totalMovieFrames"_s, "100" ).toLongLong();
77
78 return true;
79}
80
81QDomElement QgsProjectTimeSettings::writeXml( QDomDocument &document, const QgsReadWriteContext & ) const
82{
83 QDomElement element = document.createElement( u"ProjectTimeSettings"_s );
84
85 if ( mRange.begin().isValid() && mRange.end().isValid() )
86 {
87 QDomElement temporalElement = document.createElement( u"TemporalRange"_s );
88 QDomElement startElement = document.createElement( u"start"_s );
89 QDomElement endElement = document.createElement( u"end"_s );
90
91 const QDomText startText = document.createTextNode( mRange.begin().toTimeSpec( Qt::OffsetFromUTC ).toString( Qt::ISODate ) );
92 const QDomText endText = document.createTextNode( mRange.end().toTimeSpec( Qt::OffsetFromUTC ).toString( Qt::ISODate ) );
93
94 startElement.appendChild( startText );
95 endElement.appendChild( endText );
96
97 temporalElement.appendChild( startElement );
98 temporalElement.appendChild( endElement );
99
100 element.appendChild( temporalElement );
101 }
102
103 element.setAttribute( u"timeStepUnit"_s, QgsUnitTypes::encodeUnit( mTimeStepUnit ) );
104 element.setAttribute( u"timeStep"_s, qgsDoubleToString( mTimeStep ) );
105 element.setAttribute( u"frameRate"_s, qgsDoubleToString( mFrameRate ) );
106 element.setAttribute( u"cumulativeTemporalRange"_s, mCumulativeTemporalRange ? 1 : 0 );
107 element.setAttribute( u"totalMovieFrames"_s, mTotalMovieFrames );
108
109 return element;
110}
111
113{
114 return mTimeStepUnit;
115}
116
118{
119 mTimeStepUnit = unit;
120}
121
123{
124 return mTimeStep;
125}
126
128{
129 mTimeStep = timeStep;
130}
131
133{
134 mFrameRate = rate;
135}
136
138{
139 return mFrameRate;
140}
141
143{
144 mCumulativeTemporalRange = state;
145}
146
148{
149 return mCumulativeTemporalRange;
150}
151
153{
154 return mTotalMovieFrames;
155}
156
158{
159 mTotalMovieFrames = frames;
160}
161
TemporalUnit
Temporal units.
Definition qgis.h:5266
@ Hours
Hours.
Definition qgis.h:5270
long long totalMovieFrames() const
Returns the total number of frames for the project's movie.
QgsDateTimeRange temporalRange() const
Returns the project's temporal range, which indicates the earliest and latest datetime ranges associa...
void setTotalMovieFrames(long long frames)
Sets the total number of frames for the movie.
void setTemporalRange(const QgsDateTimeRange &range)
Sets the project's temporal range, which indicates the earliest and latest datetime ranges associated...
double timeStep() const
Returns the project's time step (length of one animation frame), which is used as the default value w...
void setFramesPerSecond(double rate)
Sets the project's default animation frame rate, in frames per second.
bool readXml(const QDomElement &element, const QgsReadWriteContext &context)
Reads the settings's state from a DOM element.
void temporalRangeChanged()
Emitted when the temporal range changes.
Qgis::TemporalUnit timeStepUnit() const
Returns the project's time step (length of one animation frame) unit, which is used as the default va...
QgsProjectTimeSettings(QObject *parent=nullptr)
Constructor for QgsProjectTimeSettings with the specified parent object.
bool isTemporalRangeCumulative() const
Returns the value of cumulative temporal range in animation settings.
void setTimeStepUnit(Qgis::TemporalUnit unit)
Sets the project's time step (length of one animation frame) unit, which is used as the default value...
void setIsTemporalRangeCumulative(bool state)
Sets the project's temporal range as cumulative in animation settings.
void reset()
Resets the settings to a default state.
QDomElement writeXml(QDomDocument &document, const QgsReadWriteContext &context) const
Returns a DOM element representing the settings.
void setTimeStep(double step)
Sets the project's time step (length of one animation frame), which is used as the default value when...
double framesPerSecond() const
Returns the project's default animation frame rate, in frames per second.
A container for the context for various read/write operations on objects.
static Q_INVOKABLE Qgis::TemporalUnit decodeTemporalUnit(const QString &string, bool *ok=nullptr)
Decodes a temporal unit from a string.
static Q_INVOKABLE QString encodeUnit(Qgis::DistanceUnit unit)
Encodes a distance unit to a string.
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
Definition qgis.h:6852
QgsTemporalRange< QDateTime > QgsDateTimeRange
QgsRange which stores a range of date times.
Definition qgsrange.h:764