Skip to content
Permalink
Browse files

fix timestep ui handling in temporal controller widget

  • Loading branch information
Samweli authored and nyalldawson committed Jan 10, 2021
1 parent c6f5e31 commit 64a86238e6a0777bd2d3ac7c519052ce01437fe0
Showing with 7 additions and 35 deletions.
  1. +7 −35 src/gui/qgstemporalcontrollerwidget.cpp
@@ -538,43 +538,15 @@ void QgsTemporalControllerWidget::setTimeStep( const QgsInterval &timeStep )
if ( ! timeStep.isValid() || timeStep.seconds() <= 0 )
return;

// Search the time unit the most appropriate :
// the one that gives the smallest time step value for double spin box with round value (if possible) and/or the less signifiant digits

int selectedUnit = -1;
int stringSize = std::numeric_limits<int>::max();
int precision = mStepSpinBox->decimals();
double selectedValue = std::numeric_limits<double>::max();
for ( int i = 0; i < mTimeStepsComboBox->count(); ++i )
{
QgsUnitTypes::TemporalUnit unit = static_cast<QgsUnitTypes::TemporalUnit>( mTimeStepsComboBox->itemData( i ).toInt() );
double value = timeStep.seconds() * QgsUnitTypes::fromUnitToUnitFactor( QgsUnitTypes::TemporalSeconds, unit );
QString string = QString::number( value, 'f', precision );
string.remove( QRegExp( "0+$" ) ); //remove trailing zero
string.remove( QRegExp( "[.]+$" ) ); //remove last point if present

if ( value >= 1
&& string.size() <= stringSize // less significant digit than currently selected
&& value < selectedValue ) // less than currently selected
{
selectedUnit = i;
selectedValue = value;
stringSize = string.size();
}
else if ( string != '0'
&& string.size() < precision + 2 //round value (ex: 0.xx with precision=3)
&& string.size() < stringSize ) //less significant digit than currently selected
{
selectedUnit = i ;
selectedValue = value ;
stringSize = string.size();
}
}
// Only update ui when the intervals are different
if ( timeStep == QgsInterval( mStepSpinBox->value(),
static_cast< QgsUnitTypes::TemporalUnit>( mTimeStepsComboBox->currentData().toInt() ) ) )
return;

if ( selectedUnit >= 0 )
if ( timeStep.originalUnit() != QgsUnitTypes::TemporalUnknownUnit )
{
mStepSpinBox->setValue( selectedValue );
mTimeStepsComboBox->setCurrentIndex( selectedUnit );
mStepSpinBox->setValue( timeStep.originalDuration() );
mTimeStepsComboBox->setCurrentIndex( timeStep.originalUnit() );
}

updateFrameDuration();

0 comments on commit 64a8623

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