Skip to content

Commit

Permalink
Unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Sep 21, 2018
1 parent c406ec3 commit ee8389a
Show file tree
Hide file tree
Showing 2 changed files with 345 additions and 32 deletions.
66 changes: 34 additions & 32 deletions src/gui/processing/qgsprocessingwidgetwrapperimpl.cpp
Expand Up @@ -493,44 +493,46 @@ QWidget *QgsProcessingNumericWidgetWrapper::createWidget()
}
spinBox->setSpecialValueText( tr( "Not set" ) );
}

if ( numberDef->defaultValue().isValid() )
else
{
// if default value for parameter, we clear to that
bool ok = false;
if ( mDoubleSpinBox )
if ( numberDef->defaultValue().isValid() )
{
double defaultVal = numberDef->defaultValue().toDouble( &ok );
if ( ok )
mDoubleSpinBox->setClearValue( defaultVal );
// if default value for parameter, we clear to that
bool ok = false;
if ( mDoubleSpinBox )
{
double defaultVal = numberDef->defaultValue().toDouble( &ok );
if ( ok )
mDoubleSpinBox->setClearValue( defaultVal );
}
else
{
int intVal = numberDef->defaultValue().toInt( &ok );
if ( ok )
mSpinBox->setClearValue( intVal );
}
}
else
else if ( !qgsDoubleNear( numberDef->minimum(), std::numeric_limits<double>::lowest() ) )
{
int intVal = numberDef->defaultValue().toInt( &ok );
if ( ok )
mSpinBox->setClearValue( intVal );
}
}
else if ( !qgsDoubleNear( numberDef->minimum(), std::numeric_limits<double>::lowest() ) && !mAllowingNull )
{
// otherwise we clear to the minimum, if it's set
if ( mDoubleSpinBox )
mDoubleSpinBox->setClearValue( numberDef->minimum() );
else
mSpinBox->setClearValue( static_cast< int >( numberDef->minimum() ) );
}
else if ( !mAllowingNull )
{
// last resort, we clear to 0
if ( mDoubleSpinBox )
{
mDoubleSpinBox->setValue( 0 );
mDoubleSpinBox->setClearValue( 0 );
// otherwise we clear to the minimum, if it's set
if ( mDoubleSpinBox )
mDoubleSpinBox->setClearValue( numberDef->minimum() );
else
mSpinBox->setClearValue( static_cast< int >( numberDef->minimum() ) );
}
else
{
mSpinBox->setValue( 0 );
mSpinBox->setClearValue( 0 );
// last resort, we clear to 0
if ( mDoubleSpinBox )
{
mDoubleSpinBox->setValue( 0 );
mDoubleSpinBox->setClearValue( 0 );
}
else
{
mSpinBox->setValue( 0 );
mSpinBox->setClearValue( 0 );
}
}
}

Expand Down Expand Up @@ -615,7 +617,7 @@ double QgsProcessingNumericWidgetWrapper::calculateStep( const double minimum, c
{
const double step = valueRange / 10.0;
// round to 1 significant figure
return qgsRound( step, std::floor( std::log( step ) ) );
return qgsRound( step, -std::floor( std::log( step ) ) );
}
else
{
Expand Down

0 comments on commit ee8389a

Please sign in to comment.