Skip to content

Commit

Permalink
Code cleaning: move duplicated code to lambda
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso committed Feb 2, 2018
1 parent bbf6214 commit 29f6484
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/core/fieldformatter/qgsrangefieldformatter.cpp
Expand Up @@ -40,6 +40,16 @@ QString QgsRangeFieldFormatter::representValue( QgsVectorLayer *layer, int field

QString result;

// Prepare locale
std::function<QLocale()> f_locale = [ ]
{
QLocale locale( QgsApplication::instance()->locale() );
QLocale::NumberOptions options( locale.numberOptions() );
options |= QLocale::NumberOption::OmitGroupSeparator;
locale.setNumberOptions( options );
return locale;
};

const QgsField field = layer->fields().at( fieldIndex );

if ( field.type() == QVariant::Double &&
Expand All @@ -54,11 +64,7 @@ QString QgsRangeFieldFormatter::representValue( QgsVectorLayer *layer, int field
if ( ok )
{
// TODO: make the format configurable!
QLocale locale( QgsApplication::instance()->locale() );
QLocale::NumberOptions options( locale.numberOptions() );
options |= QLocale::NumberOption::OmitGroupSeparator;
locale.setNumberOptions( options );
result = locale.toString( val, 'f', precision );
result = f_locale().toString( val, 'f', precision );
}
}
}
Expand All @@ -69,11 +75,7 @@ QString QgsRangeFieldFormatter::representValue( QgsVectorLayer *layer, int field
double val( value.toInt( &ok ) );
if ( ok )
{
QLocale locale( QgsApplication::instance()->locale() );
QLocale::NumberOptions options( locale.numberOptions() );
options |= QLocale::NumberOption::OmitGroupSeparator;
locale.setNumberOptions( options );
result = locale.toString( val );
result = f_locale().toString( val );
}
}
else
Expand Down

0 comments on commit 29f6484

Please sign in to comment.