Skip to content
Permalink
Browse files

enable cumulative temporal controller range setting

  • Loading branch information
Samweli authored and nyalldawson committed May 9, 2020
1 parent 5bf120a commit ac0249e8bc9057eb742ffd25e2f0ea4da25b57f5
@@ -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:
@@ -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();
@@ -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;
}
@@ -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;
}
@@ -126,3 +128,12 @@ double QgsProjectTimeSettings::framesPerSecond() const
return mFrameRate;
}

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

@@ -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:

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


@@ -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 );

@@ -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 );
@@ -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.
*/
@@ -258,6 +272,8 @@ class CORE_EXPORT QgsTemporalNavigationObject : public QgsTemporalController, pu

bool mLoopAnimation = false;

bool mCumulativeTemporalRange = false;

};

#endif // QGSTEMPORALNAVIGATIONOBJECT_H
@@ -151,6 +151,7 @@ void QgsTemporalControllerWidget::setWidgetStateFromProject()
updateFrameDuration();

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

void QgsTemporalControllerWidget::onLayersAdded()
@@ -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 );
}

@@ -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()
@@ -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
@@ -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
@@ -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>
@@ -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">
@@ -78,6 +90,7 @@
<class>QgsPanelWidget</class>
<extends>QWidget</extends>
<header>qgspanelwidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
@@ -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 );

@@ -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()
@@ -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()
@@ -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()
@@ -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__':

0 comments on commit ac0249e

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