Skip to content

Commit

Permalink
[feature][expressions] New variables @animation_start_time and
Browse files Browse the repository at this point in the history
@animation_end_time and @animation_interval

Contain the OVERALL animation start and end times (the current
frame time ranges is already available by @map_start_time/@map_end_time)
and overall animation interval

Fixes #36320
  • Loading branch information
nyalldawson committed May 10, 2020
1 parent 16a45f4 commit 0b25bd4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/core/expression/qgsexpression.cpp
Expand Up @@ -779,6 +779,9 @@ void QgsExpression::initVariableHelp()
sVariableHelpTexts()->insert( QStringLiteral( "frame_rate" ), QCoreApplication::translate( "variable_help", "Number of frames per second during animation playback" ) );
sVariableHelpTexts()->insert( QStringLiteral( "frame_number" ), QCoreApplication::translate( "variable_help", "Current frame number during animation playback" ) );
sVariableHelpTexts()->insert( QStringLiteral( "frame_duration" ), QCoreApplication::translate( "variable_help", "Temporal duration of each animation frame (as an interval value)" ) );
sVariableHelpTexts()->insert( QStringLiteral( "animation_start_time" ), QCoreApplication::translate( "variable_help", "Start of the animation's overall temporal time range (as a datetime value)" ) );
sVariableHelpTexts()->insert( QStringLiteral( "animation_end_time" ), QCoreApplication::translate( "variable_help", "End of the animation's overall temporal time range (as a datetime value)" ) );
sVariableHelpTexts()->insert( QStringLiteral( "animation_interval" ), QCoreApplication::translate( "variable_help", "Duration of the animation's overall temporal time range (as an interval value)" ) );

// vector tile layer variables
sVariableHelpTexts()->insert( QStringLiteral( "zoom_level" ), QCoreApplication::translate( "variable_help", "Zoom level of the tile that is being rendered (derived from the current map scale). Normally in interval [0, 20]." ) );
Expand Down
3 changes: 3 additions & 0 deletions src/core/qgstemporalnavigationobject.cpp
Expand Up @@ -75,6 +75,9 @@ QgsExpressionContextScope *QgsTemporalNavigationObject::createExpressionContextS
scope->setVariable( QStringLiteral( "frame_rate" ), mFramesPerSecond, true );
scope->setVariable( QStringLiteral( "frame_number" ), mCurrentFrameNumber, true );
scope->setVariable( QStringLiteral( "frame_duration" ), mFrameDuration, true );
scope->setVariable( QStringLiteral( "animation_start_time" ), mTemporalExtents.begin(), true );
scope->setVariable( QStringLiteral( "animation_end_time" ), mTemporalExtents.end(), true );
scope->setVariable( QStringLiteral( "animation_interval" ), mTemporalExtents.end() - mTemporalExtents.begin(), true );
return scope.release();
}

Expand Down
3 changes: 3 additions & 0 deletions tests/src/core/testqgstemporalnavigationobject.cpp
Expand Up @@ -181,6 +181,9 @@ void TestQgsTemporalNavigationObject::expressionContext()
QCOMPARE( scope->variable( QStringLiteral( "frame_rate" ) ).toDouble(), 30.0 );
QCOMPARE( scope->variable( QStringLiteral( "frame_duration" ) ).value< QgsInterval >().seconds(), 3600.0 );
QCOMPARE( scope->variable( QStringLiteral( "frame_number" ) ).toInt(), 1 );
QCOMPARE( scope->variable( QStringLiteral( "animation_start_time" ) ).toDateTime(), range.begin() );
QCOMPARE( scope->variable( QStringLiteral( "animation_end_time" ) ).toDateTime(), range.end() );
QCOMPARE( scope->variable( QStringLiteral( "animation_interval" ) ).value< QgsInterval >(), range.end() - range.begin() );
}

QGSTEST_MAIN( TestQgsTemporalNavigationObject )
Expand Down

0 comments on commit 0b25bd4

Please sign in to comment.