Skip to content

Commit ac0249e

Browse files
Samwelinyalldawson
authored andcommittedMay 10, 2020
enable cumulative temporal controller range setting
1 parent 5bf120a commit ac0249e

12 files changed

+163
-14
lines changed
 

‎python/core/auto_generated/qgsprojecttimesettings.sip.in

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,20 @@ Sets the project's default animation frame ``rate``, in frames per second.
135135
Returns the project's default animation frame rate, in frames per second.
136136

137137
.. seealso:: :py:func:`setFramesPerSecond`
138+
%End
139+
140+
void setIsTemporalRangeCumulative( bool state );
141+
%Docstring
142+
Sets the project's temporal range as cumulative in animation settings.
143+
144+
.. seealso:: :py:func:`isTemporalRangeCumulative`
145+
%End
146+
147+
bool isTemporalRangeCumulative() const;
148+
%Docstring
149+
Returns the value of cumulative temporal range in animation settings.
150+
151+
.. seealso:: :py:func:`setIsTemporalRangeCumulative`
138152
%End
139153

140154
signals:

‎python/core/auto_generated/qgstemporalnavigationobject.sip.in

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,20 @@ This setting controls the overall playback speed of the animation, i.e. how quic
132132
a playing animation will advance to the next frame.
133133

134134
.. seealso:: :py:func:`setFramesPerSecond`
135+
%End
136+
137+
void setTemporalRangeCumulative( bool state );
138+
%Docstring
139+
Sets the animation temporal range as cumulative.
140+
141+
.. seealso:: :py:func:`temporalRangeCumulative`
142+
%End
143+
144+
bool temporalRangeCumulative() const;
145+
%Docstring
146+
Returns the animation temporal range cumulative settings.
147+
148+
.. seealso:: :py:func:`setTemporalRangeCumulative`
135149
%End
136150

137151
long long totalFrameCount();

‎src/core/qgsprojecttimesettings.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ bool QgsProjectTimeSettings::readXml( const QDomElement &element, const QgsReadW
6363
mTimeStepUnit = QgsUnitTypes::decodeTemporalUnit( element.attribute( QStringLiteral( "timeStepUnit" ), QgsUnitTypes::encodeUnit( QgsUnitTypes::TemporalHours ) ) );
6464
mTimeStep = element.attribute( QStringLiteral( "timeStep" ), "1" ).toDouble();
6565
mFrameRate = element.attribute( QStringLiteral( "frameRate" ), "1" ).toDouble();
66+
mCumulativeTemporalRange = element.attribute( QStringLiteral( "cumulativeTemporalRange" ), "0" ).toInt() == 1 ? true : false;
6667

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

9698
return element;
9799
}
@@ -126,3 +128,12 @@ double QgsProjectTimeSettings::framesPerSecond() const
126128
return mFrameRate;
127129
}
128130

131+
void QgsProjectTimeSettings::setIsTemporalRangeCumulative( bool state )
132+
{
133+
mCumulativeTemporalRange = state;
134+
}
135+
bool QgsProjectTimeSettings::isTemporalRangeCumulative() const
136+
{
137+
return mCumulativeTemporalRange;
138+
}
139+

‎src/core/qgsprojecttimesettings.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,20 @@ class CORE_EXPORT QgsProjectTimeSettings : public QObject
141141
*/
142142
double framesPerSecond() const;
143143

144+
/**
145+
* Sets the project's temporal range as cumulative in animation settings.
146+
*
147+
* \see isTemporalRangeCumulative()
148+
*/
149+
void setIsTemporalRangeCumulative( bool state );
150+
151+
/**
152+
* Returns the value of cumulative temporal range in animation settings.
153+
*
154+
* \see setIsTemporalRangeCumulative()
155+
*/
156+
bool isTemporalRangeCumulative() const;
157+
144158
signals:
145159

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

162177

‎src/core/qgstemporalnavigationobject.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ QgsDateTimeRange QgsTemporalNavigationObject::dateTimeRangeForFrameNumber( long
9393
const QDateTime begin = start.addSecs( frame * mFrameDuration.seconds() );
9494
const QDateTime end = start.addSecs( nextFrame * mFrameDuration.seconds() );
9595

96+
if ( mCumulativeTemporalRange )
97+
return QgsDateTimeRange( start, begin, true, false );
98+
9699
if ( end <= mTemporalExtents.end() )
97100
return QgsDateTimeRange( begin, end, true, false );
98101

@@ -156,6 +159,16 @@ double QgsTemporalNavigationObject::framesPerSecond() const
156159
return mFramesPerSecond;
157160
}
158161

162+
void QgsTemporalNavigationObject::setTemporalRangeCumulative( bool state )
163+
{
164+
mCumulativeTemporalRange = state;
165+
}
166+
167+
bool QgsTemporalNavigationObject::temporalRangeCumulative() const
168+
{
169+
return mCumulativeTemporalRange;
170+
}
171+
159172
void QgsTemporalNavigationObject::play()
160173
{
161174
mNewFrameTimer->start( ( 1.0 / mFramesPerSecond ) * 1000 );

‎src/core/qgstemporalnavigationobject.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,20 @@ class CORE_EXPORT QgsTemporalNavigationObject : public QgsTemporalController, pu
148148
*/
149149
double framesPerSecond() const;
150150

151+
/**
152+
* Sets the animation temporal range as cumulative.
153+
*
154+
* \see temporalRangeCumulative()
155+
*/
156+
void setTemporalRangeCumulative( bool state );
157+
158+
/**
159+
* Returns the animation temporal range cumulative settings.
160+
*
161+
* \see setTemporalRangeCumulative()
162+
*/
163+
bool temporalRangeCumulative() const;
164+
151165
/**
152166
* Returns the total number of frames for the navigation.
153167
*/
@@ -258,6 +272,8 @@ class CORE_EXPORT QgsTemporalNavigationObject : public QgsTemporalController, pu
258272

259273
bool mLoopAnimation = false;
260274

275+
bool mCumulativeTemporalRange = false;
276+
261277
};
262278

263279
#endif // QGSTEMPORALNAVIGATIONOBJECT_H

‎src/gui/qgstemporalcontrollerwidget.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ void QgsTemporalControllerWidget::setWidgetStateFromProject()
151151
updateFrameDuration();
152152

153153
mNavigationObject->setFramesPerSecond( QgsProject::instance()->timeSettings()->framesPerSecond() );
154+
mNavigationObject->setTemporalRangeCumulative( QgsProject::instance()->timeSettings()->isTemporalRangeCumulative() );
154155
}
155156

156157
void QgsTemporalControllerWidget::onLayersAdded()
@@ -214,13 +215,21 @@ void QgsTemporalControllerWidget::settings_clicked()
214215
{
215216
QgsTemporalMapSettingsWidget *settingsWidget = new QgsTemporalMapSettingsWidget( this );
216217
settingsWidget->setFrameRateValue( mNavigationObject->framesPerSecond() );
218+
settingsWidget->setIsTemporalRangeCumulative( mNavigationObject->temporalRangeCumulative() );
217219

218220
connect( settingsWidget, &QgsTemporalMapSettingsWidget::frameRateChanged, this, [ = ]( double rate )
219221
{
220222
// save new settings into project
221223
QgsProject::instance()->timeSettings()->setFramesPerSecond( rate );
222224
mNavigationObject->setFramesPerSecond( rate );
223225
} );
226+
227+
connect( settingsWidget, &QgsTemporalMapSettingsWidget::temporalRangeCumulativeChanged, this, [ = ]( bool state )
228+
{
229+
// save new settings into project
230+
QgsProject::instance()->timeSettings()->setIsTemporalRangeCumulative( state );
231+
mNavigationObject->setTemporalRangeCumulative( state );
232+
} );
224233
openPanel( settingsWidget );
225234
}
226235

‎src/gui/qgstemporalmapsettingswidget.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ QgsTemporalMapSettingsWidget::QgsTemporalMapSettingsWidget( QWidget *parent )
2929
mFrameSpinBox->setClearValue( 1 );
3030

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

3435
double QgsTemporalMapSettingsWidget::frameRateValue()
@@ -41,4 +42,14 @@ void QgsTemporalMapSettingsWidget::setFrameRateValue( double value )
4142
mFrameSpinBox->setValue( value );
4243
}
4344

45+
void QgsTemporalMapSettingsWidget::setIsTemporalRangeCumulative( bool state )
46+
{
47+
mCumulativeTemporalRange->setChecked( state );
48+
}
49+
50+
bool QgsTemporalMapSettingsWidget::isTemporalRangeCumulative()
51+
{
52+
return mCumulativeTemporalRange->isChecked();
53+
}
54+
4455
///@endcond

‎src/gui/qgstemporalmapsettingswidget.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,29 @@ class GUI_EXPORT QgsTemporalMapSettingsWidget : public QgsPanelWidget, private U
4747
*/
4848
void setFrameRateValue( double value );
4949

50+
/**
51+
* Returns the cumulative range option state from vcr widget.
52+
*
53+
* \see setIsTemporalRangeCumulative()
54+
*/
55+
bool isTemporalRangeCumulative();
56+
57+
/**
58+
* Sets the cumulative range option state from vcr widget.
59+
*
60+
* \see isTemporalRangeCumulative(
61+
*/
62+
void setIsTemporalRangeCumulative( bool state );
63+
5064
signals:
5165

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

71+
void temporalRangeCumulativeChanged( bool state );
72+
5773

5874
};
5975
///@endcond

‎src/ui/qgstemporalmapsettingswidgetbase.ui

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,13 @@
77
<x>0</x>
88
<y>0</y>
99
<width>409</width>
10-
<height>63</height>
10+
<height>82</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
1414
<string notr="true">Form</string>
1515
</property>
1616
<layout class="QVBoxLayout" name="verticalLayout">
17-
<property name="leftMargin">
18-
<number>0</number>
19-
</property>
20-
<property name="topMargin">
21-
<number>0</number>
22-
</property>
23-
<property name="rightMargin">
24-
<number>0</number>
25-
</property>
26-
<property name="bottomMargin">
27-
<number>0</number>
28-
</property>
2917
<item>
3018
<layout class="QHBoxLayout" name="horizontalLayout">
3119
<item>
@@ -53,6 +41,30 @@
5341
</item>
5442
</layout>
5543
</item>
44+
<item>
45+
<layout class="QHBoxLayout" name="horizontalLayout_2">
46+
<item>
47+
<widget class="QCheckBox" name="mCumulativeTemporalRange">
48+
<property name="text">
49+
<string>Cumulative range</string>
50+
</property>
51+
</widget>
52+
</item>
53+
<item>
54+
<spacer name="horizontalSpacer_3">
55+
<property name="orientation">
56+
<enum>Qt::Horizontal</enum>
57+
</property>
58+
<property name="sizeHint" stdset="0">
59+
<size>
60+
<width>40</width>
61+
<height>20</height>
62+
</size>
63+
</property>
64+
</spacer>
65+
</item>
66+
</layout>
67+
</item>
5668
<item>
5769
<spacer name="verticalSpacer">
5870
<property name="orientation">
@@ -78,6 +90,7 @@
7890
<class>QgsPanelWidget</class>
7991
<extends>QWidget</extends>
8092
<header>qgspanelwidget.h</header>
93+
<container>1</container>
8194
</customwidget>
8295
</customwidgets>
8396
<resources/>

‎tests/src/core/testqgstemporalnavigationobject.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,16 @@ void TestQgsTemporalNavigationObject::frameSettings()
145145

146146
QgsDateTimeRange range = QgsDateTimeRange(
147147
QDateTime( QDate( 2020, 1, 1 ), QTime( 8, 0, 0 ) ),
148-
QDateTime( QDate( 2020, 1, 1 ), QTime( 12, 0, 0 ) )
148+
QDateTime( QDate( 2020, 1, 1 ), QTime( 12, 0, 0 ) ),
149+
true,
150+
false
149151
);
152+
QgsDateTimeRange lastRange = QgsDateTimeRange(
153+
QDateTime( QDate( 2020, 1, 1 ), QTime( 12, 0, 0 ) ),
154+
QDateTime( QDate( 2020, 1, 1 ), QTime( 12, 0, 0 ) ),
155+
true,
156+
false
157+
);
150158
navigationObject->setTemporalExtents( range );
151159
QCOMPARE( temporalRangeSignal.count(), 1 );
152160

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

174+
QCOMPARE( navigationObject->dateTimeRangeForFrameNumber( 4 ), lastRange );
175+
176+
navigationObject->setTemporalRangeCumulative( true );
177+
QCOMPARE( navigationObject->dateTimeRangeForFrameNumber( 4 ), range );
178+
166179
}
167180

168181
void TestQgsTemporalNavigationObject::expressionContext()

‎tests/src/python/test_qgsprojecttimesettings.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ def testGettersSetters(self):
6767
self.assertEqual(p.timeStepUnit(), QgsUnitTypes.TemporalDecades)
6868
p.setFramesPerSecond(90)
6969
self.assertEqual(p.framesPerSecond(), 90)
70+
p.setIsTemporalRangeCumulative(True)
71+
self.assertTrue(p.isTemporalRangeCumulative())
7072

7173
def testReadWrite(self):
7274
p = QgsProjectTimeSettings()
@@ -88,6 +90,7 @@ def testReadWrite(self):
8890
p.setTimeStep(4.8)
8991
p.setTimeStepUnit(QgsUnitTypes.TemporalDecades)
9092
p.setFramesPerSecond(90)
93+
p.setIsTemporalRangeCumulative(True)
9194
elem = p.writeXml(doc, QgsReadWriteContext())
9295

9396
p2 = QgsProjectTimeSettings()
@@ -98,6 +101,7 @@ def testReadWrite(self):
98101
self.assertEqual(p2.timeStep(), 4.8)
99102
self.assertEqual(p2.timeStepUnit(), QgsUnitTypes.TemporalDecades)
100103
self.assertEqual(p2.framesPerSecond(), 90)
104+
self.assertTrue(p.isTemporalRangeCumulative())
101105

102106

103107
if __name__ == '__main__':

0 commit comments

Comments
 (0)
Please sign in to comment.