Skip to content
Permalink
Browse files

Unit tests

  • Loading branch information
nyalldawson committed Sep 21, 2018
1 parent c406ec3 commit ee8389afee5081dafa8f695fe8d1fb01e98cd286
Showing with 345 additions and 32 deletions.
  1. +34 −32 src/gui/processing/qgsprocessingwidgetwrapperimpl.cpp
  2. +311 −0 tests/src/gui/testprocessinggui.cpp
@@ -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 );
}
}
}

@@ -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
{

0 comments on commit ee8389a

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