Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
enable cumulative temporal controller range setting
  • Loading branch information
Samweli authored and nyalldawson committed May 10, 2020
1 parent 5bf120a commit ac0249e
Show file tree
Hide file tree
Showing 12 changed files with 163 additions and 14 deletions.
14 changes: 14 additions & 0 deletions python/core/auto_generated/qgsprojecttimesettings.sip.in
Expand Up @@ -135,6 +135,20 @@ Sets the project's default animation frame ``rate``, in frames per second.
Returns the project's default animation frame rate, in frames per second.

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

void setIsTemporalRangeCumulative( bool state );
%Docstring
Sets the project's temporal range as cumulative in animation settings.

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

bool isTemporalRangeCumulative() const;
%Docstring
Returns the value of cumulative temporal range in animation settings.

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

signals:
Expand Down
14 changes: 14 additions & 0 deletions python/core/auto_generated/qgstemporalnavigationobject.sip.in
Expand Up @@ -132,6 +132,20 @@ This setting controls the overall playback speed of the animation, i.e. how quic
a playing animation will advance to the next frame.

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

void setTemporalRangeCumulative( bool state );
%Docstring
Sets the animation temporal range as cumulative.

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

bool temporalRangeCumulative() const;
%Docstring
Returns the animation temporal range cumulative settings.

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

long long totalFrameCount();
Expand Down
11 changes: 11 additions & 0 deletions src/core/qgsprojecttimesettings.cpp
Expand Up @@ -63,6 +63,7 @@ bool QgsProjectTimeSettings::readXml( const QDomElement &element, const QgsReadW
mTimeStepUnit = QgsUnitTypes::decodeTemporalUnit( element.attribute( QStringLiteral( "timeStepUnit" ), QgsUnitTypes::encodeUnit( QgsUnitTypes::TemporalHours ) ) );
mTimeStep = element.attribute( QStringLiteral( "timeStep" ), "1" ).toDouble();
mFrameRate = element.attribute( QStringLiteral( "frameRate" ), "1" ).toDouble();
mCumulativeTemporalRange = element.attribute( QStringLiteral( "cumulativeTemporalRange" ), "0" ).toInt() == 1 ? true : false;

return true;
}
Expand Down Expand Up @@ -92,6 +93,7 @@ QDomElement QgsProjectTimeSettings::writeXml( QDomDocument &document, const QgsR
element.setAttribute( QStringLiteral( "timeStepUnit" ), QgsUnitTypes::encodeUnit( mTimeStepUnit ) );
element.setAttribute( QStringLiteral( "timeStep" ), qgsDoubleToString( mTimeStep ) );
element.setAttribute( QStringLiteral( "frameRate" ), qgsDoubleToString( mFrameRate ) );
element.setAttribute( QStringLiteral( "cumulativeTemporalRange" ), mCumulativeTemporalRange ? 1 : 0 );

return element;
}
Expand Down Expand Up @@ -126,3 +128,12 @@ double QgsProjectTimeSettings::framesPerSecond() const
return mFrameRate;
}

void QgsProjectTimeSettings::setIsTemporalRangeCumulative( bool state )
{
mCumulativeTemporalRange = state;
}
bool QgsProjectTimeSettings::isTemporalRangeCumulative() const
{
return mCumulativeTemporalRange;
}

15 changes: 15 additions & 0 deletions src/core/qgsprojecttimesettings.h
Expand Up @@ -141,6 +141,20 @@ class CORE_EXPORT QgsProjectTimeSettings : public QObject
*/
double framesPerSecond() const;

/**
* Sets the project's temporal range as cumulative in animation settings.
*
* \see isTemporalRangeCumulative()
*/
void setIsTemporalRangeCumulative( bool state );

/**
* Returns the value of cumulative temporal range in animation settings.
*
* \see setIsTemporalRangeCumulative()
*/
bool isTemporalRangeCumulative() const;

signals:

/**
Expand All @@ -157,6 +171,7 @@ class CORE_EXPORT QgsProjectTimeSettings : public QObject
QgsUnitTypes::TemporalUnit mTimeStepUnit = QgsUnitTypes::TemporalHours;
double mTimeStep = 1;
double mFrameRate = 1;
bool mCumulativeTemporalRange = false;
};


Expand Down
13 changes: 13 additions & 0 deletions src/core/qgstemporalnavigationobject.cpp
Expand Up @@ -93,6 +93,9 @@ QgsDateTimeRange QgsTemporalNavigationObject::dateTimeRangeForFrameNumber( long
const QDateTime begin = start.addSecs( frame * mFrameDuration.seconds() );
const QDateTime end = start.addSecs( nextFrame * mFrameDuration.seconds() );

if ( mCumulativeTemporalRange )
return QgsDateTimeRange( start, begin, true, false );

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

Expand Down Expand Up @@ -156,6 +159,16 @@ double QgsTemporalNavigationObject::framesPerSecond() const
return mFramesPerSecond;
}

void QgsTemporalNavigationObject::setTemporalRangeCumulative( bool state )
{
mCumulativeTemporalRange = state;
}

bool QgsTemporalNavigationObject::temporalRangeCumulative() const
{
return mCumulativeTemporalRange;
}

void QgsTemporalNavigationObject::play()
{
mNewFrameTimer->start( ( 1.0 / mFramesPerSecond ) * 1000 );
Expand Down
16 changes: 16 additions & 0 deletions src/core/qgstemporalnavigationobject.h
Expand Up @@ -148,6 +148,20 @@ class CORE_EXPORT QgsTemporalNavigationObject : public QgsTemporalController, pu
*/
double framesPerSecond() const;

/**
* Sets the animation temporal range as cumulative.
*
* \see temporalRangeCumulative()
*/
void setTemporalRangeCumulative( bool state );

/**
* Returns the animation temporal range cumulative settings.
*
* \see setTemporalRangeCumulative()
*/
bool temporalRangeCumulative() const;

/**
* Returns the total number of frames for the navigation.
*/
Expand Down Expand Up @@ -258,6 +272,8 @@ class CORE_EXPORT QgsTemporalNavigationObject : public QgsTemporalController, pu

bool mLoopAnimation = false;

bool mCumulativeTemporalRange = false;

};

#endif // QGSTEMPORALNAVIGATIONOBJECT_H
9 changes: 9 additions & 0 deletions src/gui/qgstemporalcontrollerwidget.cpp
Expand Up @@ -151,6 +151,7 @@ void QgsTemporalControllerWidget::setWidgetStateFromProject()
updateFrameDuration();

mNavigationObject->setFramesPerSecond( QgsProject::instance()->timeSettings()->framesPerSecond() );
mNavigationObject->setTemporalRangeCumulative( QgsProject::instance()->timeSettings()->isTemporalRangeCumulative() );
}

void QgsTemporalControllerWidget::onLayersAdded()
Expand Down Expand Up @@ -214,13 +215,21 @@ void QgsTemporalControllerWidget::settings_clicked()
{
QgsTemporalMapSettingsWidget *settingsWidget = new QgsTemporalMapSettingsWidget( this );
settingsWidget->setFrameRateValue( mNavigationObject->framesPerSecond() );
settingsWidget->setIsTemporalRangeCumulative( mNavigationObject->temporalRangeCumulative() );

connect( settingsWidget, &QgsTemporalMapSettingsWidget::frameRateChanged, this, [ = ]( double rate )
{
// save new settings into project
QgsProject::instance()->timeSettings()->setFramesPerSecond( rate );
mNavigationObject->setFramesPerSecond( rate );
} );

connect( settingsWidget, &QgsTemporalMapSettingsWidget::temporalRangeCumulativeChanged, this, [ = ]( bool state )
{
// save new settings into project
QgsProject::instance()->timeSettings()->setIsTemporalRangeCumulative( state );
mNavigationObject->setTemporalRangeCumulative( state );
} );
openPanel( settingsWidget );
}

Expand Down
11 changes: 11 additions & 0 deletions src/gui/qgstemporalmapsettingswidget.cpp
Expand Up @@ -29,6 +29,7 @@ QgsTemporalMapSettingsWidget::QgsTemporalMapSettingsWidget( QWidget *parent )
mFrameSpinBox->setClearValue( 1 );

connect( mFrameSpinBox, qgis::overload<double>::of( &QDoubleSpinBox::valueChanged ), this, &QgsTemporalMapSettingsWidget::frameRateChanged );
connect( mCumulativeTemporalRange, &QCheckBox::toggled, this, &QgsTemporalMapSettingsWidget::temporalRangeCumulativeChanged );
}

double QgsTemporalMapSettingsWidget::frameRateValue()
Expand All @@ -41,4 +42,14 @@ void QgsTemporalMapSettingsWidget::setFrameRateValue( double value )
mFrameSpinBox->setValue( value );
}

void QgsTemporalMapSettingsWidget::setIsTemporalRangeCumulative( bool state )
{
mCumulativeTemporalRange->setChecked( state );
}

bool QgsTemporalMapSettingsWidget::isTemporalRangeCumulative()
{
return mCumulativeTemporalRange->isChecked();
}

///@endcond
16 changes: 16 additions & 0 deletions src/gui/qgstemporalmapsettingswidget.h
Expand Up @@ -47,13 +47,29 @@ class GUI_EXPORT QgsTemporalMapSettingsWidget : public QgsPanelWidget, private U
*/
void setFrameRateValue( double value );

/**
* Returns the cumulative range option state from vcr widget.
*
* \see setIsTemporalRangeCumulative()
*/
bool isTemporalRangeCumulative();

/**
* Sets the cumulative range option state from vcr widget.
*
* \see isTemporalRangeCumulative(
*/
void setIsTemporalRangeCumulative( bool state );

signals:

/**
* Emitted when frame \a rate value on the spin box has changed.
*/
void frameRateChanged( double rate );

void temporalRangeCumulativeChanged( bool state );


};
///@endcond
Expand Down
39 changes: 26 additions & 13 deletions src/ui/qgstemporalmapsettingswidgetbase.ui
Expand Up @@ -7,25 +7,13 @@
<x>0</x>
<y>0</y>
<width>409</width>
<height>63</height>
<height>82</height>
</rect>
</property>
<property name="windowTitle">
<string notr="true">Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
Expand Down Expand Up @@ -53,6 +41,30 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QCheckBox" name="mCumulativeTemporalRange">
<property name="text">
<string>Cumulative range</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
Expand All @@ -78,6 +90,7 @@
<class>QgsPanelWidget</class>
<extends>QWidget</extends>
<header>qgspanelwidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
Expand Down
15 changes: 14 additions & 1 deletion tests/src/core/testqgstemporalnavigationobject.cpp
Expand Up @@ -145,8 +145,16 @@ void TestQgsTemporalNavigationObject::frameSettings()

QgsDateTimeRange range = QgsDateTimeRange(
QDateTime( QDate( 2020, 1, 1 ), QTime( 8, 0, 0 ) ),
QDateTime( QDate( 2020, 1, 1 ), QTime( 12, 0, 0 ) )
QDateTime( QDate( 2020, 1, 1 ), QTime( 12, 0, 0 ) ),
true,
false
);
QgsDateTimeRange lastRange = QgsDateTimeRange(
QDateTime( QDate( 2020, 1, 1 ), QTime( 12, 0, 0 ) ),
QDateTime( QDate( 2020, 1, 1 ), QTime( 12, 0, 0 ) ),
true,
false
);
navigationObject->setTemporalExtents( range );
QCOMPARE( temporalRangeSignal.count(), 1 );

Expand All @@ -163,6 +171,11 @@ void TestQgsTemporalNavigationObject::frameSettings()
navigationObject->setFramesPerSecond( 1 );
QCOMPARE( navigationObject->framesPerSecond(), 1.0 );

QCOMPARE( navigationObject->dateTimeRangeForFrameNumber( 4 ), lastRange );

navigationObject->setTemporalRangeCumulative( true );
QCOMPARE( navigationObject->dateTimeRangeForFrameNumber( 4 ), range );

}

void TestQgsTemporalNavigationObject::expressionContext()
Expand Down
4 changes: 4 additions & 0 deletions tests/src/python/test_qgsprojecttimesettings.py
Expand Up @@ -67,6 +67,8 @@ def testGettersSetters(self):
self.assertEqual(p.timeStepUnit(), QgsUnitTypes.TemporalDecades)
p.setFramesPerSecond(90)
self.assertEqual(p.framesPerSecond(), 90)
p.setIsTemporalRangeCumulative(True)
self.assertTrue(p.isTemporalRangeCumulative())

def testReadWrite(self):
p = QgsProjectTimeSettings()
Expand All @@ -88,6 +90,7 @@ def testReadWrite(self):
p.setTimeStep(4.8)
p.setTimeStepUnit(QgsUnitTypes.TemporalDecades)
p.setFramesPerSecond(90)
p.setIsTemporalRangeCumulative(True)
elem = p.writeXml(doc, QgsReadWriteContext())

p2 = QgsProjectTimeSettings()
Expand All @@ -98,6 +101,7 @@ def testReadWrite(self):
self.assertEqual(p2.timeStep(), 4.8)
self.assertEqual(p2.timeStepUnit(), QgsUnitTypes.TemporalDecades)
self.assertEqual(p2.framesPerSecond(), 90)
self.assertTrue(p.isTemporalRangeCumulative())


if __name__ == '__main__':
Expand Down

0 comments on commit ac0249e

Please sign in to comment.