Skip to content
Permalink
Browse files
[temporal] Default to a time range of the last 24 hours, in 1 hour
increments, instead of a confusing "zero length" range

Fixes #40868
  • Loading branch information
nyalldawson committed Jun 14, 2021
1 parent a1f47a4 commit 5f5a3a7e46fac5a4939d90f2eaf57a8b61008789
Showing with 11 additions and 4 deletions.
  1. +11 −4 src/gui/qgstemporalcontrollerwidget.cpp
@@ -482,10 +482,17 @@ void QgsTemporalControllerWidget::onProjectCleared()
mNavigationObject->setNavigationMode( QgsTemporalNavigationObject::NavigationOff );
setWidgetStateFromNavigationMode( QgsTemporalNavigationObject::NavigationOff );

whileBlocking( mStartDateTime )->setDateTime( QDateTime( QDate::currentDate(), QTime( 0, 0, 0 ), Qt::UTC ) );
whileBlocking( mEndDateTime )->setDateTime( mStartDateTime->dateTime() );
whileBlocking( mFixedRangeStartDateTime )->setDateTime( QDateTime( QDate::currentDate(), QTime( 0, 0, 0 ), Qt::UTC ) );
whileBlocking( mFixedRangeEndDateTime )->setDateTime( mStartDateTime->dateTime() );
// default to showing the last 24 hours, ending at the current date's hour, in one hour blocks...
// it's COMPLETELY arbitrary, but better than starting with a "zero length" duration!
const QTime startOfCurrentHour = QTime( QTime::currentTime().hour(), 0, 0 );
const QDateTime end = QDateTime( QDate::currentDate(), startOfCurrentHour, Qt::UTC );
const QDateTime start = end.addSecs( -24 * 60 * 60 );

whileBlocking( mStartDateTime )->setDateTime( start );
whileBlocking( mEndDateTime )->setDateTime( end );
whileBlocking( mFixedRangeStartDateTime )->setDateTime( start );
whileBlocking( mFixedRangeEndDateTime )->setDateTime( end );

updateTemporalExtent();
mTimeStepsComboBox->setCurrentIndex( mTimeStepsComboBox->findData( QgsUnitTypes::TemporalHours ) );
mStepSpinBox->setValue( 1 );

0 comments on commit 5f5a3a7

Please sign in to comment.