QGIS API Documentation
3.14.0-Pi (9f7028fd23)
|
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 switch ( mNavigationMode )
133 switch ( mNavigationMode )
137 int currentFrameNmber = mCurrentFrameNumber;
141 if ( currentFrameNmber == mCurrentFrameNumber )
155 return mTemporalExtents;
160 if ( mCurrentFrameNumber != frameNumber )
162 mCurrentFrameNumber = std::max( 0LL, std::min( frameNumber,
totalFrameCount() - 1 ) );
170 return mCurrentFrameNumber;
181 return mFrameDuration;
186 if ( framesPerSeconds > 0 )
188 mFramesPerSecond = framesPerSeconds;
189 mNewFrameTimer->setInterval( ( 1.0 / mFramesPerSecond ) * 1000 );
195 return mFramesPerSecond;
200 mCumulativeTemporalRange = state;
205 return mCumulativeTemporalRange;
210 mNewFrameTimer->start( ( 1.0 / mFramesPerSecond ) * 1000 );
215 mNewFrameTimer->stop();
233 if ( mPlayBackMode ==
Idle && mCurrentFrameNumber <= 0 )
266 QgsInterval totalAnimationLength = mTemporalExtents.end() - mTemporalExtents.begin();
267 return std::floor( totalAnimationLength.
seconds() / mFrameDuration.
seconds() ) + 1;
272 if ( mode != mPlayBackMode )
274 mPlayBackMode = mode;
281 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...
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.
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.
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 ...