QGIS API Documentation
3.16.0-Hannover (43b64b13f3)
|
Go to the documentation of this file.
24 mNewFrameTimer =
new QTimer(
this );
26 connect( mNewFrameTimer, &QTimer::timeout,
27 this, &QgsTemporalNavigationObject::timerTimeout );
30 void QgsTemporalNavigationObject::timerTimeout()
32 switch ( mPlayBackMode )
34 case AnimationState::Forward:
39 mCurrentFrameNumber = -1;
45 case AnimationState::Reverse:
47 if ( mCurrentFrameNumber <= 0 )
56 case AnimationState::Idle:
64 return mLoopAnimation;
69 mLoopAnimation = loopAnimation;
74 std::unique_ptr< QgsExpressionContextScope > scope = qgis::make_unique< QgsExpressionContextScope >( QStringLiteral(
"temporal" ) );
75 scope->setVariable( QStringLiteral(
"frame_rate" ), mFramesPerSecond,
true );
76 scope->setVariable( QStringLiteral(
"frame_number" ), mCurrentFrameNumber,
true );
77 scope->setVariable( QStringLiteral(
"frame_duration" ), mFrameDuration,
true );
78 scope->setVariable( QStringLiteral(
"animation_start_time" ), mTemporalExtents.begin(),
true );
79 scope->setVariable( QStringLiteral(
"animation_end_time" ), mTemporalExtents.end(),
true );
80 scope->setVariable( QStringLiteral(
"animation_interval" ), mTemporalExtents.end() - mTemporalExtents.begin(),
true );
81 return scope.release();
86 const QDateTime start = mTemporalExtents.begin();
91 const long long nextFrame = frame + 1;
93 const QDateTime begin = start.addSecs( frame * mFrameDuration.
seconds() );
94 const QDateTime end = start.addSecs( nextFrame * mFrameDuration.
seconds() );
96 QDateTime frameStart = begin;
98 if ( mCumulativeTemporalRange )
101 if ( end <= mTemporalExtents.end() )
102 return QgsDateTimeRange( frameStart, end,
true,
false );
104 return QgsDateTimeRange( frameStart, mTemporalExtents.end(),
true,
false );
109 if ( mNavigationMode == mode )
112 mNavigationMode = mode;
115 if ( !mBlockUpdateTemporalRangeSignal )
117 switch ( mNavigationMode )
141 switch ( mNavigationMode )
154 if ( !mBlockUpdateTemporalRangeSignal )
165 return mTemporalExtents;
170 if ( mCurrentFrameNumber != frameNumber )
172 mCurrentFrameNumber = std::max( 0LL, std::min( frameNumber,
totalFrameCount() - 1 ) );
175 if ( !mBlockUpdateTemporalRangeSignal )
182 return mCurrentFrameNumber;
195 mBlockUpdateTemporalRangeSignal++;
197 mBlockUpdateTemporalRangeSignal--;
202 if ( !mBlockUpdateTemporalRangeSignal )
208 return mFrameDuration;
213 if ( framesPerSeconds > 0 )
215 mFramesPerSecond = framesPerSeconds;
216 mNewFrameTimer->setInterval( ( 1.0 / mFramesPerSecond ) * 1000 );
222 return mFramesPerSecond;
227 mCumulativeTemporalRange = state;
232 return mCumulativeTemporalRange;
237 mNewFrameTimer->start( ( 1.0 / mFramesPerSecond ) * 1000 );
242 mNewFrameTimer->stop();
260 if ( mPlayBackMode ==
Idle && mCurrentFrameNumber <= 0 )
293 QgsInterval totalAnimationLength = mTemporalExtents.end() - mTemporalExtents.begin();
294 return std::floor( totalAnimationLength.
seconds() / mFrameDuration.
seconds() ) + 1;
299 if ( mode != mPlayBackMode )
301 mPlayBackMode = mode;
308 return mPlayBackMode;
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.
void setTemporalRangeCumulative(bool state)
Sets the animation temporal range as cumulative.
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.
void navigationModeChanged(NavigationMode mode)
Emitted whenever the navigation mode changes.
void setFrameDuration(QgsInterval duration)
Sets the frame duration, which dictates the temporal length of each frame in the animation.
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...
void temporalExtentsChanged(const QgsDateTimeRange &extent)
Emitted whenever the temporalExtent extent 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 stateChanged(AnimationState state)
Emitted whenever the animation state changes.
void setCurrentFrameNumber(long long frame)
Sets the current animation frame number.
void setAnimationState(AnimationState state)
Sets the current animation state.
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.
long long totalFrameCount()
Returns the total number of frames for the navigation.
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.
void pause()
Pauses the temporal navigation.
void next()
Advances to the next frame.
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.
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 ...