Skip to content

Commit

Permalink
updates on temporal animation logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Samweli committed Mar 11, 2020
1 parent 8981f9d commit bbb1e7c
Show file tree
Hide file tree
Showing 34 changed files with 589 additions and 234 deletions.
4 changes: 1 addition & 3 deletions python/core/auto_generated/qgstemporalcontroller.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@ updates of the objects temporal range.
%End
public:

QgsTemporalController();
QgsTemporalController( QObject *parent = 0 );
%Docstring
Constructor for QgsTemporalController.
%End

virtual ~QgsTemporalController();

signals:

void updateTemporalRange( const QgsDateTimeRange &range );
Expand Down
21 changes: 5 additions & 16 deletions python/core/auto_generated/qgstemporalnavigationobject.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@



class QgsTemporalNavigationObject : QObject
class QgsTemporalNavigationObject : QgsTemporalController
{
%Docstring
The QgsTemporalNavigationObject class
Expand Down Expand Up @@ -123,7 +123,8 @@ Returns the total number of frames for the navigation.

void play();
%Docstring
Plays the temporal navigation
Starts playing the temporal navigation from its current frame,
using the direction specified by playBackMode()
%End

void pause();
Expand All @@ -133,12 +134,12 @@ Stops the temporal navigation.

void forward();
%Docstring
Forward the temporal navigation up till the end of frames.
Starts the animation playing in a forward direction up till the end of frames.
%End

void backward();
%Docstring
Decrement the temporal navigation till the end of frames.
Starts the animation playing in a reverse direction until the beginning of the time range.
%End

void next();
Expand All @@ -159,18 +160,6 @@ Rewind the temporal navigation to start of the temporal extent.
void skipToEnd();
%Docstring
Skips the temporal navigation to end of the temporal extent.
%End

void timerTimeout();
%Docstring
Handles logic when the temporal navigation timer emit a timeout signal.
%End

signals:

void updateTemporalRange( QgsDateTimeRange temporalRange );
%Docstring
Emitted when navigation range changes.
%End

};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@




class QgsRasterDataProviderTemporalCapabilities : QgsDataProviderTemporalCapabilities
{
%Docstring
Expand All @@ -36,6 +35,72 @@ The ``enabled`` argument specifies whether the data provider has temporal capabi

virtual ~QgsRasterDataProviderTemporalCapabilities();

enum TemporalMode
{
ModeFixedTemporalRange,
ModeTemporalRangeFromDataProvider
};

TemporalMode mode() const;
%Docstring
Returns the temporal mode.

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

void setMode( TemporalMode mode );
%Docstring
Sets the temporal ``mode``.

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

enum FetchMode
{
Earliest,
Latest,
Range
};

FetchMode fetchMode() const;
%Docstring
Returns the temporal capabilities fetch mode.

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

void setFetchMode( FetchMode mode );
%Docstring
Sets the temporal properties fetch ``mode``.

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

enum TimeInterval
{
Seconds,
Minutes,
Hours,
Days,
Months,
Years,
None
};

TimeInterval timeInterval() const;
%Docstring
Returns the temporal interval.

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

void setTimeInterval( TimeInterval interval );
%Docstring
Sets the temporal time ``interval``.

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

void setFixedTemporalRange( const QgsDateTimeRange &range );
%Docstring
Sets the fixed datetime ``range`` for the temporal properties.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,27 @@ Returns the temporal properties mode.
Sets the temporal properties ``mode``.

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

enum FetchMode
{
Earliest,
Latest,
Range
};

FetchMode fetchMode() const;
%Docstring
Returns the temporal properties fetch mode.

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

void setFetchMode( FetchMode mode );
%Docstring
Sets the temporal properties fetch ``mode``.

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

void setFixedTemporalRange( const QgsDateTimeRange &range );
Expand Down Expand Up @@ -164,6 +185,16 @@ Returns the current active reference datetime range for these temporal propertie
virtual bool readXml( const QDomElement &element, const QgsReadWriteContext &context );


TemporalMode indexToMode( int index );
%Docstring
Returns the temporal mode given index
%End

FetchMode indexToFetchMode( int index );
%Docstring
Returns the temporal fetch mode given index
%End

};

/************************************************************************
Expand Down
3 changes: 2 additions & 1 deletion python/gui/auto_generated/qgsmapcanvas.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@




class QgsMapCanvas : QGraphicsView
{
%Docstring
Expand Down Expand Up @@ -72,7 +73,7 @@ Gets access to properties used for map rendering
.. versionadded:: 2.4
%End

void setTemporalController( QgsTemporalNavigationObject *controller );
void setTemporalController( QgsTemporalController *controller );
%Docstring
Sets the temporal controller, this controller will be used to
update the canvas temporal range.
Expand Down
12 changes: 11 additions & 1 deletion python/gui/auto_generated/qgstemporalcontrollerdockwidget.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,21 @@ Constructor for QgsTemporalControllerDockWidget

~QgsTemporalControllerDockWidget();

QgsTemporalNavigationObject *temporalController();
QgsTemporalController *temporalController();
%Docstring
Returns the temporal controller object used by this object in navigation.
%End

enum TimeUnit
{
Seconds,
Minutes,
Hours,
Days,
Months,
Years
};

};

/************************************************************************
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1153,8 +1153,8 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
mBrowserWidget->setObjectName( QStringLiteral( "Browser" ) );
mBrowserWidget->setMessageBar( mInfoBar );

mTemporalControllerWidget = new QgsTemporalControllerDockWidget( tr( "Temporal VCR" ), this );
mTemporalControllerWidget->setObjectName( QStringLiteral( "Temporal VCR" ) );
mTemporalControllerWidget = new QgsTemporalControllerDockWidget( tr( "Temporal Controller" ), this );
mTemporalControllerWidget->setObjectName( QStringLiteral( "Temporal Controller" ) );
addDockWidget( Qt::BottomDockWidgetArea, mTemporalControllerWidget );
mTemporalControllerWidget->hide();

Expand Down
7 changes: 4 additions & 3 deletions src/app/qgsprojectproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2540,9 +2540,10 @@ void QgsProjectProperties::calculateFromLayersButton_clicked()
mStartDateTimeEdit->setDateTime( minDate );
mEndDateTimeEdit->setDateTime( maxDate );

mCurrentRangeLabel->setText( tr( "Current range: %1 to %2" ).arg(
mStartDateTimeEdit->dateTime().toString( "yyyy-MM-dd hh:mm:ss" ),
mEndDateTimeEdit->dateTime().toString( "yyyy-MM-dd hh:mm:ss" ) ) );
QLocale locale;
mCurrentRangeLabel->setText( tr( "Current selected range: %1 to %2" ).arg(
mStartDateTimeEdit->dateTime().toString( locale.dateTimeFormat() ),
mEndDateTimeEdit->dateTime().toString( locale.dateTimeFormat() ) ) );
}

QListWidgetItem *QgsProjectProperties::addScaleToScaleList( const QString &newScale )
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgsmaplayertemporalproperties.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ class CORE_EXPORT QgsMapLayerTemporalProperties : public QgsTemporalProperty
*/
enum TemporalSource
{
Layer, //! Defined from layer .
Project//! Defined from project time settings;
Layer = 0, //! Defined from layer .
Project = 1//! Defined from project time settings;
};

/**
Expand Down
3 changes: 2 additions & 1 deletion src/core/qgstemporalcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "qgstemporalcontroller.h"

QgsTemporalController::QgsTemporalController( )
QgsTemporalController::QgsTemporalController( QObject *parent )
: QObject( parent )
{
}
4 changes: 1 addition & 3 deletions src/core/qgstemporalcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ class CORE_EXPORT QgsTemporalController : public QObject
* Constructor for QgsTemporalController.
*
*/
QgsTemporalController();

virtual ~QgsTemporalController() = default;
QgsTemporalController( QObject *parent = nullptr );

signals:

Expand Down
40 changes: 24 additions & 16 deletions src/core/qgstemporalnavigationobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,44 +19,54 @@
#include "qgis.h"

QgsTemporalNavigationObject::QgsTemporalNavigationObject( QObject *parent )
: QObject( parent )
: QgsTemporalController( parent )
{
mNewFrameTimer = new QTimer( this );

connect( mNewFrameTimer, &QTimer::timeout,
this, qgis::overload<>::of( &QgsTemporalNavigationObject::timerTimeout ) );
this, &QgsTemporalNavigationObject::timerTimeout );
}


void QgsTemporalNavigationObject::timerTimeout()
{
if ( mPlayBackMode == PlaybackMode::Forward )
forward();
if ( mPlayBackMode == PlaybackMode::Reverse )
backward();
return;
switch ( mPlayBackMode )
{
case PlaybackMode::Forward:
forward();
break;

case PlaybackMode::Reverse:
backward();
break;

case PlaybackMode::Idle:
pause();
break;
}
}

QgsDateTimeRange QgsTemporalNavigationObject::dateTimeRangeForFrameNumber( long long frame ) const
{
QDateTime start = mTemporalExtents.begin();

long long pastFrame = frame - 1;
if ( pastFrame < 0 )
pastFrame = 0;
if ( frame < 0 )
frame = 0;
long long nextFrame = frame + 1;

QDateTime begin = start.addSecs( pastFrame * mFrameDuration.seconds() );
QDateTime end = start.addSecs( frame * mFrameDuration.seconds() );
QDateTime begin = start.addSecs( frame * mFrameDuration.seconds() );
QDateTime end = start.addSecs( nextFrame * mFrameDuration.seconds() );

if ( end <= mTemporalExtents.end() )
return QgsDateTimeRange( begin, end );

return mTemporalExtents;
return QgsDateTimeRange( begin, mTemporalExtents.end() );
}

void QgsTemporalNavigationObject::setTemporalExtents( QgsDateTimeRange temporalExtents )
{
mTemporalExtents = temporalExtents;
setCurrentFrameNumber( 0 );
}

QgsDateTimeRange QgsTemporalNavigationObject::temporalExtents() const
Expand All @@ -68,10 +78,7 @@ void QgsTemporalNavigationObject::setCurrentFrameNumber( long long frameNumber )
{
if ( frameNumber < 0 ||
frameNumber >= totalFrameCount() )
{
pause();
return;
}

if ( mCurrentFrameNumber != frameNumber )
{
Expand All @@ -89,6 +96,7 @@ long long QgsTemporalNavigationObject::currentFrameNumber() const
void QgsTemporalNavigationObject::setFrameDuration( QgsInterval frameDuration )
{
mFrameDuration = frameDuration;
setCurrentFrameNumber( 0 );
}

QgsInterval QgsTemporalNavigationObject::frameDuration() const
Expand Down
Loading

0 comments on commit bbb1e7c

Please sign in to comment.