QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
qgsmeshlayertemporalproperties.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsmeshlayertemporalproperties.cpp
3 -----------------------
4 begin : March 2020
5 copyright : (C) 2020 by Vincent Cloarec
6 email : vcloarec 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
19
21#include "qgsproject.h"
23
24#include "moc_qgsmeshlayertemporalproperties.cpp"
25
27 QgsMapLayerTemporalProperties( parent, enabled )
28{}
29
30QDomElement QgsMeshLayerTemporalProperties::writeXml( QDomElement &element, QDomDocument &doc, const QgsReadWriteContext &context )
31{
32 Q_UNUSED( context );
33
34 QDomElement temporalElement = doc.createElement( QStringLiteral( "temporal" ) );
35 temporalElement.setAttribute( QStringLiteral( "temporal-active" ), isActive() ? true : false );
36 temporalElement.setAttribute( QStringLiteral( "reference-time" ), mReferenceTime.toTimeSpec( Qt::UTC ).toString( Qt::ISODate ) );
37 temporalElement.setAttribute( QStringLiteral( "start-time-extent" ), mTimeExtent.begin().toTimeSpec( Qt::UTC ).toString( Qt::ISODate ) );
38 temporalElement.setAttribute( QStringLiteral( "end-time-extent" ), mTimeExtent.end().toTimeSpec( Qt::UTC ).toString( Qt::ISODate ) );
39 temporalElement.setAttribute( QStringLiteral( "matching-method" ), mMatchingMethod );
40 temporalElement.setAttribute( QStringLiteral( "always-load-reference-time-from-source" ), mAlwaysLoadReferenceTimeFromSource ? 1 : 0 );
41 element.appendChild( temporalElement );
42
43 return element;
44}
45
46bool QgsMeshLayerTemporalProperties::readXml( const QDomElement &element, const QgsReadWriteContext &context )
47{
48 Q_UNUSED( context );
49
50 const QDomElement temporalElement = element.firstChildElement( QStringLiteral( "temporal" ) );
51 const bool active = temporalElement.attribute( QStringLiteral( "temporal-active" ) ).toInt();
52 setIsActive( active );
53
54 mAlwaysLoadReferenceTimeFromSource = temporalElement.attribute( QStringLiteral( "always-load-reference-time-from-source" ) ).toInt();
55
56 mReferenceTime = QDateTime::fromString( temporalElement.attribute( QStringLiteral( "reference-time" ) ), Qt::ISODate );
57
58 if ( temporalElement.hasAttribute( QStringLiteral( "start-time-extent" ) )
59 && temporalElement.hasAttribute( QStringLiteral( "end-time-extent" ) ) )
60 {
61 const QDateTime start = QDateTime::fromString( temporalElement.attribute( QStringLiteral( "start-time-extent" ) ), Qt::ISODate );
62 const QDateTime end = QDateTime::fromString( temporalElement.attribute( QStringLiteral( "end-time-extent" ) ), Qt::ISODate );
63 mTimeExtent = QgsDateTimeRange( start, end );
64 }
65
67 temporalElement.attribute( QStringLiteral( "matching-method" ) ).toInt() );
68
69 mIsValid = true;
70 return true;
71}
72
74{
75 const QgsMeshDataProviderTemporalCapabilities *temporalCapabilities =
76 static_cast<const QgsMeshDataProviderTemporalCapabilities *>( capabilities );
77
78 setIsActive( temporalCapabilities->hasTemporalCapabilities() );
79 mReferenceTime = temporalCapabilities->referenceTime();
80
81 if ( mReferenceTime.isValid() )
82 mTimeExtent = temporalCapabilities->timeExtent();
83
84 mIsValid = true;
85}
86
91
93{
94 return mTimeExtent;
95}
96
98{
99 return mReferenceTime;
100}
101
103{
104 mReferenceTime = referenceTime;
105 if ( capabilities )
106 {
107 const QgsMeshDataProviderTemporalCapabilities *tempCap = static_cast<const QgsMeshDataProviderTemporalCapabilities *>( capabilities );
108 mTimeExtent = tempCap->timeExtent( referenceTime );
109 }
110 else
112}
113
118
123
125{
126 return mIsValid;
127}
128
130{
131 mIsValid = isValid;
132}
133
135{
136 return mAlwaysLoadReferenceTimeFromSource;
137}
138
140{
141 mAlwaysLoadReferenceTimeFromSource = autoReloadFromProvider;
142}
Base class for handling properties relating to a data provider's temporal capabilities.
bool hasTemporalCapabilities() const
Returns true if the provider has temporal capabilities available.
QgsMapLayerTemporalProperties(QObject *parent, bool enabled=false)
Constructor for QgsMapLayerTemporalProperties, with the specified parent object.
Base class for all map layer types.
Definition qgsmaplayer.h:80
Handles properties relating to a mesh data provider's temporal capabilities.
QDateTime referenceTime() const
Returns the reference time.
QgsDateTimeRange timeExtent() const
Returns the time extent using the internal reference time and the first and last times available from...
MatchingTemporalDatasetMethod
Method for selection of temporal mesh dataset from a range time.
QgsDateTimeRange calculateTemporalExtent(QgsMapLayer *layer) const override
Attempts to calculate the overall temporal extent for the specified layer, using the settings defined...
QDateTime referenceTime() const
Returns the reference time.
void setAlwaysLoadReferenceTimeFromSource(bool autoReloadFromProvider)
Sets whether the time proporties are automatically reloaded from provider when project is opened or l...
bool isValid() const
Returns whether the instance is valid.
QDomElement writeXml(QDomElement &element, QDomDocument &doc, const QgsReadWriteContext &context) override
Writes the properties to a DOM element, to be used later with readXml().
void setMatchingMethod(const QgsMeshDataProviderTemporalCapabilities::MatchingTemporalDatasetMethod &matchingMethod)
Sets the method used to match dataset from temporal capabilities.
QgsMeshDataProviderTemporalCapabilities::MatchingTemporalDatasetMethod matchingMethod() const
Returns the method used to match dataset from temporal capabilities.
void setReferenceTime(const QDateTime &referenceTime, const QgsDataProviderTemporalCapabilities *capabilities)
Sets the reference time and update the time extent from the temporal capabilities,...
void setDefaultsFromDataProviderTemporalCapabilities(const QgsDataProviderTemporalCapabilities *capabilities) override
Sets the layers temporal settings to appropriate defaults based on a provider's temporal capabilities...
bool alwaysLoadReferenceTimeFromSource() const
Returns whether the time proporties are automatically reloaded from provider when project is opened o...
void setIsValid(bool isValid)
Sets whether the instance is valid.
QgsDateTimeRange timeExtent() const
Returns the time extent.
QgsMeshLayerTemporalProperties(QObject *parent=nullptr, bool enabled=true)
Constructor for QgsMeshLayerTemporalProperties.
bool readXml(const QDomElement &element, const QgsReadWriteContext &context) override
Reads temporal properties from a DOM element previously written by writeXml().
A container for the context for various read/write operations on objects.
bool isActive() const
Returns true if the temporal property is active.
void setIsActive(bool active)
Sets whether the temporal property is active.
QgsTemporalRange< QDateTime > QgsDateTimeRange
QgsRange which stores a range of date times.
Definition qgsrange.h:761