QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
Go to the documentation of this file.
25 mNewFrameTimer =
new QTimer(
this );
27 connect( mNewFrameTimer, &QTimer::timeout,
28 this, &QgsTemporalNavigationObject::timerTimeout );
31 void QgsTemporalNavigationObject::timerTimeout()
33 switch ( mPlayBackMode )
35 case AnimationState::Forward:
40 mCurrentFrameNumber = -1;
46 case AnimationState::Reverse:
48 if ( mCurrentFrameNumber <= 0 )
57 case AnimationState::Idle:
65 return mLoopAnimation;
70 mLoopAnimation = loopAnimation;
75 std::unique_ptr< QgsExpressionContextScope > scope = std::make_unique< QgsExpressionContextScope >( QStringLiteral(
"temporal" ) );
76 scope->setVariable( QStringLiteral(
"frame_rate" ), mFramesPerSecond,
true );
77 scope->setVariable( QStringLiteral(
"frame_number" ), mCurrentFrameNumber,
true );
78 scope->setVariable( QStringLiteral(
"frame_duration" ), mFrameDuration,
true );
79 scope->setVariable( QStringLiteral(
"frame_timestep" ), mFrameDuration.
originalDuration(),
true );
80 scope->setVariable( QStringLiteral(
"frame_timestep_unit" ), mFrameDuration.
originalUnit(),
true );
81 scope->setVariable( QStringLiteral(
"animation_start_time" ), mTemporalExtents.begin(),
true );
82 scope->setVariable( QStringLiteral(
"animation_end_time" ), mTemporalExtents.end(),
true );
83 scope->setVariable( QStringLiteral(
"animation_interval" ), mTemporalExtents.end() - mTemporalExtents.begin(),
true );
84 return scope.release();
89 const QDateTime start = mTemporalExtents.begin();
94 const long long nextFrame = frame + 1;
100 if ( mAllRanges.empty() )
101 return QgsDateTimeRange();
103 return frame < mAllRanges.size() ? mAllRanges.at( frame ) : mAllRanges.constLast();
111 QDateTime frameStart = begin;
113 if ( mCumulativeTemporalRange )
116 return QgsDateTimeRange( frameStart, end,
true,
false );
121 if ( mNavigationMode == mode )
124 mNavigationMode = mode;
127 if ( !mBlockUpdateTemporalRangeSignal )
129 switch ( mNavigationMode )
155 switch ( mNavigationMode )
167 if ( !mBlockUpdateTemporalRangeSignal )
178 return mTemporalExtents;
193 if ( mCurrentFrameNumber != frameNumber )
195 mCurrentFrameNumber = std::max( 0LL, std::min( frameNumber,
totalFrameCount() - 1 ) );
198 if ( !mBlockUpdateTemporalRangeSignal )
205 return mCurrentFrameNumber;
224 if ( !mBlockUpdateTemporalRangeSignal && mNavigationMode ==
Animated )
230 return mFrameDuration;
235 if ( framesPerSeconds > 0 )
237 mFramesPerSecond = framesPerSeconds;
238 mNewFrameTimer->setInterval(
static_cast< int >( ( 1.0 / mFramesPerSecond ) * 1000 ) );
244 return mFramesPerSecond;
249 mCumulativeTemporalRange = state;
254 return mCumulativeTemporalRange;
259 mNewFrameTimer->start(
static_cast< int >( ( 1.0 / mFramesPerSecond ) * 1000 ) );
264 mNewFrameTimer->stop();
282 if ( mPlayBackMode ==
Idle && mCurrentFrameNumber <= 0 )
317 return mAllRanges.count();
321 const QgsInterval totalAnimationLength = mTemporalExtents.end() - mTemporalExtents.begin();
322 return static_cast< long long >( std::ceil( totalAnimationLength.
seconds() / mFrameDuration.
seconds() ) );
328 if ( mode != mPlayBackMode )
330 mPlayBackMode = mode;
337 return mPlayBackMode;
342 long long bestFrame = 0;
345 for (
const QgsDateTimeRange &range : mAllRanges )
347 if ( range.contains( frameStart ) )
349 else if ( range.begin() > frameStart )
351 return std::max( 0LL, bestFrame - 1 );
354 return mAllRanges.count() - 1;
358 const QgsDateTimeRange testFrame = QgsDateTimeRange( frameStart, frameStart );
360 long long roughFrameStart = 0;
368 if ( mTemporalExtents.contains( frameStart ) )
370 roughFrameStart =
static_cast< long long >( std::floor( ( frameStart - mTemporalExtents.begin() ).seconds() / mFrameDuration.
seconds() ) );
372 roughFrameEnd = roughFrameStart + 100;
374 for (
long long i = roughFrameStart; i < roughFrameEnd; ++i )
377 if ( range.overlaps( testFrame ) )
@ TemporalDecades
Decades.
void rewindToStart()
Rewinds the temporal navigation to start of the temporal extent.
@ Animated
Temporal navigation relies on frames within a datetime range.
double seconds() const
Returns the interval duration in seconds.
long long findBestFrameNumberForFrameStart(const QDateTime &frameStart) const
Returns the best suited frame number for the specified datetime, based on the start of the correspond...
long long totalFrameCount() const
Returns the total number of frames for the navigation.
double originalDuration() const
Returns the original interval duration.
void setTemporalRangeCumulative(bool state)
Sets the animation temporal range as cumulative.
void setAvailableTemporalRanges(const QList< QgsDateTimeRange > &ranges)
Sets the list of all available temporal ranges which have data available.
QgsDateTimeRange dateTimeRangeForFrameNumber(long long frame) const
Calculates the temporal range associated with a particular animation frame.
void playForward()
Starts the animation playing in a forward direction up till the end of all frames.
NavigationMode
Represents the current temporal navigation mode.
QgsInterval frameDuration() const
Returns the current set frame duration, which dictates the temporal length of each frame in the anima...
@ TemporalIrregularStep
Special "irregular step" time unit, used for temporal data which uses irregular, non-real-world unit ...
void temporalExtentsChanged(const QgsDateTimeRange &extent)
Emitted whenever the temporalExtent extent changes.
void navigationModeChanged(QgsTemporalNavigationObject::NavigationMode mode)
Emitted whenever the navigation mode changes.
QgsTemporalNavigationObject(QObject *parent=nullptr)
Constructor for QgsTemporalNavigationObject, with the specified parent object.
void setLooping(bool loop)
Sets whether the animation should loop after hitting the end or start frame.
void playBackward()
Starts the animation playing in a reverse direction until the beginning of the time range.
void skipToEnd()
Skips the temporal navigation to end of the temporal extent.
void setCurrentFrameNumber(long long frame)
Sets the current animation frame number.
void setAnimationState(AnimationState state)
Sets the current animation state.
void stateChanged(QgsTemporalNavigationObject::AnimationState state)
Emitted whenever the animation state changes.
void setTemporalExtents(const QgsDateTimeRange &extents)
Sets the navigation temporal extents, which dictate the earliest and latest date time possible in the...
void setFramesPerSecond(double rate)
Sets the animation frame rate, in frames per second.
A controller base class for temporal objects, contains a signal for notifying updates of the objects ...
QgsExpressionContextScope * createExpressionContextScope() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
@ Idle
Animation is paused.
void setFrameDuration(const QgsInterval &duration)
Sets the frame duration, which dictates the temporal length of each frame in the animation.
Single scope for storing variables and functions for use within a QgsExpressionContext....
bool isLooping() const
Returns true if the animation should loop after hitting the end or start frame.
void updateTemporalRange(const QgsDateTimeRange &range)
Signals that a temporal range has changed and needs to be updated in all connected objects.
static QDateTime calculateFrameTime(const QDateTime &start, const long long frame, const QgsInterval &interval)
Calculates the frame time for an animation.
@ TemporalCenturies
Centuries.
void pause()
Pauses the temporal navigation.
void next()
Advances to the next frame.
QList< QgsDateTimeRange > availableTemporalRanges() const
Returns the list of all available temporal ranges which have data available.
void temporalFrameDurationChanged(const QgsInterval &interval)
Emitted whenever the frameDuration interval of the controller changes.
bool temporalRangeCumulative() const
Returns the animation temporal range cumulative settings.
A representation of the interval between two datetime values.
void previous()
Jumps back to the previous frame.
@ NavigationOff
Temporal navigation is disabled.
AnimationState
Represents the current animation state.
void play()
Starts playing the temporal navigation from its current frame, using the direction specified by anima...
long long currentFrameNumber() const
Returns the current frame number.
void setNavigationMode(const NavigationMode mode)
Sets the temporal navigation mode.
@ FixedRange
Temporal navigation relies on a fixed datetime range.
QgsUnitTypes::TemporalUnit originalUnit() const
Returns the original interval temporal unit.
double framesPerSecond() const
Returns the animation frame rate, in frames per second.
AnimationState animationState() const
Returns the current animation state.
QgsDateTimeRange temporalExtents() const
Returns the navigation temporal extents, which dictate the earliest and latest date time possible in ...