Skip to content

Commit

Permalink
[temporal] Default to a time range of the last 24 hours, in 1 hour
Browse files Browse the repository at this point in the history
increments, instead of a confusing "zero length" range

Fixes #40868
  • Loading branch information
nyalldawson committed Jun 14, 2021
1 parent a1f47a4 commit 5f5a3a7
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/gui/qgstemporalcontrollerwidget.cpp
Expand Up @@ -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 );
Expand Down

0 comments on commit 5f5a3a7

Please sign in to comment.