Skip to content
Permalink
Browse files

returned setFrameDuration and frameDuration functions in the temporal…

… navigation object
  • Loading branch information
Samweli authored and nyalldawson committed Jan 6, 2021
1 parent 9cd3da6 commit 4513033c0590d226582f85bac1afd00dd4b4394d
@@ -107,6 +107,24 @@ Caling this method will change the controllers current datetime range to match,
Returns the current frame number.

.. seealso:: :py:func:`setCurrentFrameNumber`
%End

void setFrameDuration( QgsInterval duration );
%Docstring
Sets the frame ``duration``, which dictates the temporal length of each frame in the animation.

.. note::

Calling this will reset the :py:func:`~QgsTemporalNavigationObject.currentFrameNumber` to the closest temporal match for the previous temporal range.

.. seealso:: :py:func:`frameDuration`
%End

QgsInterval frameDuration() const;
%Docstring
Returns the current set frame duration, which dictates the temporal length of each frame in the animation.

.. seealso:: :py:func:`setFrameDuration`
%End

void setFrameTimeStep( double timeStep );
@@ -185,15 +185,42 @@ long long QgsTemporalNavigationObject::currentFrameNumber() const
return mCurrentFrameNumber;
}

void QgsTemporalNavigationObject::setFrameDuration( QgsInterval frameDuration )
{
if ( mFrameDuration == frameDuration )
{
return;
}
QgsDateTimeRange oldFrame = dateTimeRangeForFrameNumber( currentFrameNumber() );
mFrameDuration = frameDuration;
mCurrentFrameNumber = findBestFrameNumberForFrameStart( oldFrame.begin() );
emit temporalFrameDurationChanged( mFrameDuration );

// temporarily disable the updateTemporalRange signal, as we'll emit it ourselves at the end of this function...

// forcing an update of our views
QgsDateTimeRange range = dateTimeRangeForFrameNumber( mCurrentFrameNumber );

if ( !mBlockUpdateTemporalRangeSignal && mNavigationMode != NavigationOff )
emit updateTemporalRange( range );
}

QgsInterval QgsTemporalNavigationObject::frameDuration() const
{
return mFrameDuration;
}

void QgsTemporalNavigationObject::setFrameTimeStep( double timeStep )
{
mFrameTimeStep = timeStep;
setCurrentFrameNumber( 0 );
mFrameTimeStep = timeStep;
setFrameDuration( QgsInterval( mFrameTimeStep, mFrameTimeStepUnit ) );
setCurrentFrameNumber( 0 );
}

void QgsTemporalNavigationObject::setFrameTimeStepUnit( QgsUnitTypes::TemporalUnit timeStepUnit )
{
mFrameTimeStepUnit = timeStepUnit;
setFrameDuration( QgsInterval( mFrameTimeStep, mFrameTimeStepUnit ) );
setCurrentFrameNumber( 0 );
}

@@ -290,7 +317,7 @@ void QgsTemporalNavigationObject::skipToEnd()
long long QgsTemporalNavigationObject::totalFrameCount() const
{
QgsInterval totalAnimationLength = mTemporalExtents.end() - mTemporalExtents.begin();
return std::floor( totalAnimationLength.seconds() / QgsInterval( mFrameTimeStep, mFrameTimeStepUnit ).seconds() ) + 1;
return std::floor( totalAnimationLength.seconds() / mFrameDuration.seconds() ) + 1;
}

void QgsTemporalNavigationObject::setAnimationState( AnimationState mode )
@@ -126,6 +126,22 @@ class CORE_EXPORT QgsTemporalNavigationObject : public QgsTemporalController, pu
*/
long long currentFrameNumber() const;

/**
* Sets the frame \a duration, which dictates the temporal length of each frame in the animation.
*
* \note Calling this will reset the currentFrameNumber() to the closest temporal match for the previous temporal range.
*
* \see frameDuration()
*/
void setFrameDuration( QgsInterval duration );

/**
* Returns the current set frame duration, which dictates the temporal length of each frame in the animation.
*
* \see setFrameDuration()
*/
QgsInterval frameDuration() const;

/**
* Sets the frame \a timestep, which together with the frame timestep unit dictates
* the temporal length of each frame in the animation.
@@ -324,6 +340,8 @@ class CORE_EXPORT QgsTemporalNavigationObject : public QgsTemporalController, pu
long long mCurrentFrameNumber = 0;

//! Frame duration
QgsInterval mFrameDuration;

double mFrameTimeStep = 1.0;
QgsUnitTypes::TemporalUnit mFrameTimeStepUnit = QgsUnitTypes::TemporalUnit::TemporalHours;

0 comments on commit 4513033

Please sign in to comment.
You can’t perform that action at this time.