QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 
20 #include "qgsproject.h"
21 #include "qgsprojecttimesettings.h"
22 
24  QgsMapLayerTemporalProperties( parent, enabled )
25 {}
26 
27 QDomElement QgsMeshLayerTemporalProperties::writeXml( QDomElement &element, QDomDocument &doc, const QgsReadWriteContext &context )
28 {
29  Q_UNUSED( context );
30 
31  QDomElement temporalElement = doc.createElement( QStringLiteral( "temporal" ) );
32  temporalElement.setAttribute( QStringLiteral( "temporal-active" ), isActive() ? true : false );
33  temporalElement.setAttribute( QStringLiteral( "reference-time" ), mReferenceTime.toTimeSpec( Qt::UTC ).toString( Qt::ISODate ) );
34  temporalElement.setAttribute( QStringLiteral( "start-time-extent" ), mTimeExtent.begin().toTimeSpec( Qt::UTC ).toString( Qt::ISODate ) );
35  temporalElement.setAttribute( QStringLiteral( "end-time-extent" ), mTimeExtent.end().toTimeSpec( Qt::UTC ).toString( Qt::ISODate ) );
36  temporalElement.setAttribute( QStringLiteral( "matching-method" ), mMatchingMethod );
37 
38  element.appendChild( temporalElement );
39 
40  return element;
41 }
42 
43 bool QgsMeshLayerTemporalProperties::readXml( const QDomElement &element, const QgsReadWriteContext &context )
44 {
45  Q_UNUSED( context );
46 
47  const QDomElement temporalElement = element.firstChildElement( QStringLiteral( "temporal" ) );
48  const bool active = temporalElement.attribute( QStringLiteral( "temporal-active" ) ).toInt();
49  setIsActive( active );
50 
51  mReferenceTime = QDateTime::fromString( temporalElement.attribute( QStringLiteral( "reference-time" ) ), Qt::ISODate );
52 
53  if ( temporalElement.hasAttribute( QStringLiteral( "start-time-extent" ) )
54  && temporalElement.hasAttribute( QStringLiteral( "end-time-extent" ) ) )
55  {
56  const QDateTime start = QDateTime::fromString( temporalElement.attribute( QStringLiteral( "start-time-extent" ) ), Qt::ISODate );
57  const QDateTime end = QDateTime::fromString( temporalElement.attribute( QStringLiteral( "end-time-extent" ) ), Qt::ISODate );
58  mTimeExtent = QgsDateTimeRange( start, end );
59  }
60 
62  temporalElement.attribute( QStringLiteral( "matching-method" ) ).toInt() );
63 
64  mIsValid = true;
65  return true;
66 }
67 
69 {
70  const QgsMeshDataProviderTemporalCapabilities *temporalCapabilities =
71  static_cast<const QgsMeshDataProviderTemporalCapabilities *>( capabilities );
72 
73  setIsActive( temporalCapabilities->hasTemporalCapabilities() );
74  mReferenceTime = temporalCapabilities->referenceTime();
75 
76  if ( mReferenceTime.isValid() )
77  mTimeExtent = temporalCapabilities->timeExtent();
78 
79  mIsValid = true;
80 }
81 
83 {
84  return mTimeExtent;
85 }
86 
88 {
89  return mTimeExtent;
90 }
91 
93 {
94  return mReferenceTime;
95 }
96 
97 void QgsMeshLayerTemporalProperties::setReferenceTime( const QDateTime &referenceTime, const QgsDataProviderTemporalCapabilities *capabilities )
98 {
99  mReferenceTime = referenceTime;
100  if ( capabilities )
101  {
102  const QgsMeshDataProviderTemporalCapabilities *tempCap = static_cast<const QgsMeshDataProviderTemporalCapabilities *>( capabilities );
103  mTimeExtent = tempCap->timeExtent( referenceTime );
104  }
105  else
106  mTimeExtent = QgsDateTimeRange( referenceTime, referenceTime );
107 }
108 
110 {
111  return mMatchingMethod;
112 }
113 
115 {
116  mMatchingMethod = matchingMethod;
117 }
118 
120 {
121  return mIsValid;
122 }
123 
125 {
126  mIsValid = isValid;
127 }
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:34
QgsMeshDataProviderTemporalCapabilities
Class for handling properties relating to a mesh data provider's temporal capabilities.
Definition: qgsmeshdataprovidertemporalcapabilities.h:34
QgsMeshLayerTemporalProperties::isValid
bool isValid() const
Returns whether the instance is valid.
Definition: qgsmeshlayertemporalproperties.cpp:119
QgsMeshLayerTemporalProperties::QgsMeshLayerTemporalProperties
QgsMeshLayerTemporalProperties(QObject *parent=nullptr, bool enabled=true)
Constructor for QgsMeshLayerTemporalProperties.
Definition: qgsmeshlayertemporalproperties.cpp:23
QgsMeshLayerTemporalProperties::setMatchingMethod
void setMatchingMethod(const QgsMeshDataProviderTemporalCapabilities::MatchingTemporalDatasetMethod &matchingMethod)
Sets the method used to match dataset from temporal capabilities.
Definition: qgsmeshlayertemporalproperties.cpp:114
QgsMeshLayerTemporalProperties::setReferenceTime
void setReferenceTime(const QDateTime &referenceTime, const QgsDataProviderTemporalCapabilities *capabilities)
Sets the reference time and update the time extent from the temporal capabilities,...
Definition: qgsmeshlayertemporalproperties.cpp:97
QgsMeshLayerTemporalProperties::calculateTemporalExtent
QgsDateTimeRange calculateTemporalExtent(QgsMapLayer *layer) const override
Attempts to calculate the overall temporal extent for the specified layer, using the settings defined...
Definition: qgsmeshlayertemporalproperties.cpp:82
QgsMeshLayerTemporalProperties::timeExtent
QgsDateTimeRange timeExtent() const
Returns the time extent.
Definition: qgsmeshlayertemporalproperties.cpp:87
QgsDataProviderTemporalCapabilities
Base class for handling properties relating to a data provider's temporal capabilities.
Definition: qgsdataprovidertemporalcapabilities.h:33
QgsTemporalProperty::isActive
bool isActive() const
Returns true if the temporal property is active.
Definition: qgstemporalproperty.cpp:36
QgsMeshLayerTemporalProperties::readXml
bool readXml(const QDomElement &element, const QgsReadWriteContext &context) override
Reads temporal properties from a DOM element previously written by writeXml().
Definition: qgsmeshlayertemporalproperties.cpp:43
QgsMeshLayerTemporalProperties::referenceTime
QDateTime referenceTime() const
Returns the reference time.
Definition: qgsmeshlayertemporalproperties.cpp:92
QgsMeshDataProviderTemporalCapabilities::MatchingTemporalDatasetMethod
MatchingTemporalDatasetMethod
Method for selection of temporal mesh dataset from a range time.
Definition: qgsmeshdataprovidertemporalcapabilities.h:41
QgsMapLayerTemporalProperties
Base class for storage of map layer temporal properties.
Definition: qgsmaplayertemporalproperties.h:42
QgsMeshLayerTemporalProperties::setDefaultsFromDataProviderTemporalCapabilities
void setDefaultsFromDataProviderTemporalCapabilities(const QgsDataProviderTemporalCapabilities *capabilities) override
Sets the layers temporal settings to appropriate defaults based on a provider's temporal capabilities...
Definition: qgsmeshlayertemporalproperties.cpp:68
QgsTemporalProperty::setIsActive
void setIsActive(bool active)
Sets whether the temporal property is active.
Definition: qgstemporalproperty.cpp:27
qgsprojecttimesettings.h
QgsMapLayer
Base class for all map layer types. This is the base class for all map layer types (vector,...
Definition: qgsmaplayer.h:72
QgsMeshLayerTemporalProperties::setIsValid
void setIsValid(bool isValid)
Sets whether the instance is valid.
Definition: qgsmeshlayertemporalproperties.cpp:124
qgsmeshdataprovidertemporalcapabilities.h
QgsDataProviderTemporalCapabilities::hasTemporalCapabilities
bool hasTemporalCapabilities() const
Returns true if the provider has temporal capabilities available.
Definition: qgsdataprovidertemporalcapabilities.h:74
QgsMeshLayerTemporalProperties::matchingMethod
QgsMeshDataProviderTemporalCapabilities::MatchingTemporalDatasetMethod matchingMethod() const
Returns the method used to match dataset from temporal capabilities.
Definition: qgsmeshlayertemporalproperties.cpp:109
QgsMeshLayerTemporalProperties::writeXml
QDomElement writeXml(QDomElement &element, QDomDocument &doc, const QgsReadWriteContext &context) override
Writes the properties to a DOM element, to be used later with readXml().
Definition: qgsmeshlayertemporalproperties.cpp:27
qgsproject.h
QgsMeshDataProviderTemporalCapabilities::timeExtent
QgsDateTimeRange timeExtent() const
Returns the time extent using the internal reference time and the first and last times available from...
Definition: qgsmeshdataprovidertemporalcapabilities.cpp:109
qgsmeshlayertemporalproperties.h
QgsMeshDataProviderTemporalCapabilities::referenceTime
QDateTime referenceTime() const
Returns the reference time.
Definition: qgsmeshdataprovidertemporalcapabilities.cpp:104