QGIS API Documentation 3.41.0-Master (45a0abf3bec)
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#include "moc_qgsprojecttimesettings.cpp"
20#include "qgis.h"
21#include "qgsunittypes.h"
22#include <QDomElement>
23
25 : QObject( parent )
26{
27
28}
29
35
40
42{
43 if ( range == mRange )
44 return;
45 mRange = range;
46
48}
49
50bool QgsProjectTimeSettings::readXml( const QDomElement &element, const QgsReadWriteContext & )
51{
52 const QDomElement temporalElement = element.firstChildElement( QStringLiteral( "TemporalRange" ) );
53 if ( !temporalElement.isNull() )
54 {
55 const QDomNode begin = temporalElement.namedItem( QStringLiteral( "start" ) );
56 const QDomNode end = temporalElement.namedItem( QStringLiteral( "end" ) );
57
58 const QDateTime beginDate = QDateTime::fromString( begin.toElement().text(), Qt::ISODate );
59 const QDateTime endDate = QDateTime::fromString( end.toElement().text(), Qt::ISODate );
60
61 setTemporalRange( QgsDateTimeRange( beginDate, endDate ) );
62
63 }
64
65 mTimeStepUnit = QgsUnitTypes::decodeTemporalUnit( element.attribute( QStringLiteral( "timeStepUnit" ), QgsUnitTypes::encodeUnit( Qgis::TemporalUnit::Hours ) ) );
66 mTimeStep = element.attribute( QStringLiteral( "timeStep" ), "1" ).toDouble();
67 mFrameRate = element.attribute( QStringLiteral( "frameRate" ), "1" ).toDouble();
68 mCumulativeTemporalRange = element.attribute( QStringLiteral( "cumulativeTemporalRange" ), "0" ).toInt();
69
70 mTotalMovieFrames = element.attribute( QStringLiteral( "totalMovieFrames" ), "100" ).toLongLong();
71
72 return true;
73}
74
75QDomElement QgsProjectTimeSettings::writeXml( QDomDocument &document, const QgsReadWriteContext & ) const
76{
77 QDomElement element = document.createElement( QStringLiteral( "ProjectTimeSettings" ) );
78
79 if ( mRange.begin().isValid() && mRange.end().isValid() )
80 {
81 QDomElement temporalElement = document.createElement( QStringLiteral( "TemporalRange" ) );
82 QDomElement startElement = document.createElement( QStringLiteral( "start" ) );
83 QDomElement endElement = document.createElement( QStringLiteral( "end" ) );
84
85 const QDomText startText = document.createTextNode( mRange.begin().toTimeSpec( Qt::OffsetFromUTC ).toString( Qt::ISODate ) );
86 const QDomText endText = document.createTextNode( mRange.end().toTimeSpec( Qt::OffsetFromUTC ).toString( Qt::ISODate ) );
87
88 startElement.appendChild( startText );
89 endElement.appendChild( endText );
90
91 temporalElement.appendChild( startElement );
92 temporalElement.appendChild( endElement );
93
94 element.appendChild( temporalElement );
95 }
96
97 element.setAttribute( QStringLiteral( "timeStepUnit" ), QgsUnitTypes::encodeUnit( mTimeStepUnit ) );
98 element.setAttribute( QStringLiteral( "timeStep" ), qgsDoubleToString( mTimeStep ) );
99 element.setAttribute( QStringLiteral( "frameRate" ), qgsDoubleToString( mFrameRate ) );
100 element.setAttribute( QStringLiteral( "cumulativeTemporalRange" ), mCumulativeTemporalRange ? 1 : 0 );
101 element.setAttribute( QStringLiteral( "totalMovieFrames" ), mTotalMovieFrames );
102
103 return element;
104}
105
107{
108 return mTimeStepUnit;
109}
110
112{
113 mTimeStepUnit = unit;
114}
115
117{
118 return mTimeStep;
119}
120
122{
123 mTimeStep = timeStep;
124}
125
127{
128 mFrameRate = rate;
129}
130
132{
133 return mFrameRate;
134}
135
137{
138 mCumulativeTemporalRange = state;
139}
140
142{
143 return mCumulativeTemporalRange;
144}
145
147{
148 return mTotalMovieFrames;
149}
150
152{
153 mTotalMovieFrames = frames;
154}
155
TemporalUnit
Temporal units.
Definition qgis.h:4823
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.
The class is used as a container of context for various read/write operations on other objects.
T begin() const
Returns the beginning of the range.
Definition qgsrange.h:444
T end() const
Returns the upper bound of the range.
Definition qgsrange.h:451
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:5875
QgsTemporalRange< QDateTime > QgsDateTimeRange
QgsRange which stores a range of date times.
Definition qgsrange.h:742