20 #include <QDomElement>
30 mRange = QgsDateTimeRange();
41 if ( range == mRange )
50 const QDomElement temporalElement = element.firstChildElement( QStringLiteral(
"TemporalRange" ) );
51 if ( !temporalElement.isNull() )
53 const QDomNode begin = temporalElement.namedItem( QStringLiteral(
"start" ) );
54 const QDomNode end = temporalElement.namedItem( QStringLiteral(
"end" ) );
56 const QDateTime beginDate = QDateTime::fromString( begin.toElement().text(), Qt::ISODate );
57 const QDateTime endDate = QDateTime::fromString( end.toElement().text(), Qt::ISODate );
64 mTimeStep = element.attribute( QStringLiteral(
"timeStep" ),
"1" ).toDouble();
65 mFrameRate = element.attribute( QStringLiteral(
"frameRate" ),
"1" ).toDouble();
66 mCumulativeTemporalRange = element.attribute( QStringLiteral(
"cumulativeTemporalRange" ),
"0" ).toInt();
73 QDomElement element = document.createElement( QStringLiteral(
"ProjectTimeSettings" ) );
75 if ( mRange.begin().isValid() && mRange.end().isValid() )
77 QDomElement temporalElement = document.createElement( QStringLiteral(
"TemporalRange" ) );
78 QDomElement startElement = document.createElement( QStringLiteral(
"start" ) );
79 QDomElement endElement = document.createElement( QStringLiteral(
"end" ) );
81 const QDomText startText = document.createTextNode( mRange.begin().toTimeSpec( Qt::OffsetFromUTC ).toString( Qt::ISODate ) );
82 const QDomText endText = document.createTextNode( mRange.end().toTimeSpec( Qt::OffsetFromUTC ).toString( Qt::ISODate ) );
84 startElement.appendChild( startText );
85 endElement.appendChild( endText );
87 temporalElement.appendChild( startElement );
88 temporalElement.appendChild( endElement );
90 element.appendChild( temporalElement );
94 element.setAttribute( QStringLiteral(
"timeStep" ),
qgsDoubleToString( mTimeStep ) );
95 element.setAttribute( QStringLiteral(
"frameRate" ),
qgsDoubleToString( mFrameRate ) );
96 element.setAttribute( QStringLiteral(
"cumulativeTemporalRange" ), mCumulativeTemporalRange ? 1 : 0 );
103 return mTimeStepUnit;
108 mTimeStepUnit = unit;
133 mCumulativeTemporalRange = state;
137 return mCumulativeTemporalRange;
QgsDateTimeRange temporalRange() const
Returns the project's temporal range, which indicates the earliest and latest datetime ranges associa...
void setTemporalRange(const QgsDateTimeRange &range)
Sets the project's temporal range, which indicates the earliest and latest datetime ranges associated...
void setTimeStepUnit(QgsUnitTypes::TemporalUnit unit)
Sets the project's time step (length of one animation frame) unit, which is used as the default value...
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.
QgsUnitTypes::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 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.
static Q_INVOKABLE QString encodeUnit(QgsUnitTypes::DistanceUnit unit)
Encodes a distance unit to a string.
TemporalUnit
Temporal units.
static Q_INVOKABLE QgsUnitTypes::TemporalUnit decodeTemporalUnit(const QString &string, bool *ok=nullptr)
Decodes a temporal unit from a string.
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.