27 const QList<qint64> &datasetTimes = mDatasetTimeSinceGroupReference[group];
28 if ( datasetTimes.isEmpty() )
30 const QDateTime groupReference = mGroupsReferenceDateTime[group];
31 const qint64 timeSinceGroupReference =
32 timeSinceGlobalReference - mGlobalReferenceDateTime.msecsTo( groupReference );
34 if ( timeSinceGroupReference > datasetTimes.last()
35 || timeSinceGroupReference < datasetTimes.first() )
38 for (
int i = 1 ; i < datasetTimes.count(); ++i )
40 const qint64 time1 = datasetTimes.at( i - 1 );
41 const qint64 time2 = datasetTimes.at( i );
42 if ( time1 <= timeSinceGroupReference && timeSinceGroupReference <= time2 )
44 if ( abs( timeSinceGroupReference - time2 ) < abs( timeSinceGroupReference - time1 ) )
57 const QList<qint64> &datasetTimes = mDatasetTimeSinceGroupReference[group];
58 if ( datasetTimes.isEmpty() )
60 const QDateTime groupReference = mGroupsReferenceDateTime[group];
61 const qint64 timeSinceGroupReference =
62 timeSinceGlobalReference - mGlobalReferenceDateTime.msecsTo( groupReference );
64 if ( timeSinceGroupReference > datasetTimes.last()
65 || timeSinceGroupReference < datasetTimes.first() )
68 for (
int i = 1; i < datasetTimes.count(); ++i )
70 const qint64 time = datasetTimes.at( i );
71 if ( timeSinceGroupReference < time )
80 if ( ( !mGlobalReferenceDateTime.isValid() && reference.isValid() ) ||
81 ( reference.isValid() && mGlobalReferenceDateTime.isValid() && reference < mGlobalReferenceDateTime ) )
82 mGlobalReferenceDateTime = reference;
84 mGroupsReferenceDateTime[group] = reference;
89 QList<qint64> &datasetTimes = mDatasetTimeSinceGroupReference[group];
90 datasetTimes.append( time );
101 return mGlobalReferenceDateTime.isValid();
106 return mGlobalReferenceDateTime;
112 return timeExtent( mGlobalReferenceDateTime );
119 for ( QHash<int, QDateTime>::const_iterator it = mGroupsReferenceDateTime.constBegin() ;
120 it != mGroupsReferenceDateTime.constEnd(); ++it )
122 QDateTime groupReference = it.value();
123 if ( !groupReference.isValid() )
124 groupReference = mGlobalReferenceDateTime;
126 if ( !groupReference.isValid() )
127 groupReference = reference;
129 const QList<qint64> times = mDatasetTimeSinceGroupReference[it.key()];
130 qint64 durationSinceFirst = groupReference.msecsTo( reference );
131 qint64 durationSinceLast = groupReference.msecsTo( reference );
132 if ( !times.isEmpty() )
134 durationSinceFirst += times.first();
135 durationSinceLast += times.last();
138 if ( !end.isValid() || groupReference.addMSecs( durationSinceLast ) > end )
139 end = groupReference.addMSecs( durationSinceLast );
141 if ( !begin.isValid() || groupReference.addMSecs( durationSinceFirst ) > begin )
142 begin = groupReference.addMSecs( durationSinceFirst );
145 return QgsDateTimeRange( begin, end );
150 mTemporalUnit = timeUnit;
155 return mTemporalUnit;
163 const QList<qint64> ×List = mDatasetTimeSinceGroupReference[index.
group()];
164 if ( index.
dataset() < timesList.count() )
165 return timesList.at( index.
dataset() );
172 mGlobalReferenceDateTime = QDateTime();
173 mGroupsReferenceDateTime.clear();
174 mDatasetTimeSinceGroupReference.clear();
180 if ( mDatasetTimeSinceGroupReference.contains( group ) )
182 const QList<qint64> times = mDatasetTimeSinceGroupReference[group];
183 if ( times.count() > 1 )
184 ret = times.at( 1 ) - times.at( 0 );
Base class for handling properties relating to a data provider's temporal capabilities.
void addDatasetTime(int group, double time)
Adds a time (in provider unit) from a dataset contained in group.
QgsUnitTypes::TemporalUnit temporalUnit() const
Returns the temporal unit used to read data by the data provider.
QDateTime referenceTime() const
Returns the reference time.
QgsMeshDatasetIndex datasetIndexClosestFromRelativeTime(int group, qint64 timeSinceGlobalReference) const
Returns the closest dataset index from the timeSinceGlobalReference.
void setTemporalUnit(QgsUnitTypes::TemporalUnit temporalUnit)
Sets the temporal unit (temporalUnit) used to read data by the data provider.
bool hasReferenceTime() const
Returns whether the reference time is set.
QgsMeshDataProviderTemporalCapabilities()
Constructor for QgsMeshDataProviderTemporalCapabilities.
QgsDateTimeRange timeExtent() const
Returns the time extent using the internal reference time and the first and last times available from...
QgsMeshDatasetIndex datasetIndexClosestBeforeRelativeTime(int group, qint64 timeSinceGlobalReference) const
Returns the last dataset with time less than or equal to timeSinceGlobalReference.
void addDatasetTimeInMilliseconds(int group, qint64 time)
Adds a time (in milliseconds) from a dataset contained in group.
void clear()
Clears alls stored reference times and dataset times.
qint64 datasetTime(const QgsMeshDatasetIndex &index) const
Returns the relative time in milliseconds of the dataset.
void addGroupReferenceDateTime(int group, const QDateTime &reference)
Adds a reference date/time from a dataset group.
qint64 firstTimeStepDuration(int group) const
Returns the duration of the first time step of the dataset group with index group.
QgsMeshDatasetIndex is index that identifies the dataset group (e.g.
bool isValid() const
Returns whether index is valid, ie at least groups is set.
int group() const
Returns a group index.
int dataset() const
Returns a dataset index within group()
static Q_INVOKABLE double fromUnitToUnitFactor(QgsUnitTypes::DistanceUnit fromUnit, QgsUnitTypes::DistanceUnit toUnit)
Returns the conversion factor between the specified distance units.
TemporalUnit
Temporal units.
@ TemporalMilliseconds
Milliseconds.
#define INVALID_MESHLAYER_TIME