Skip to content
Permalink
Browse files

Code cleaning: move duplicated code to lambda

  • Loading branch information
elpaso committed Feb 2, 2018
1 parent bbf6214 commit 29f6484dd017e19907d4cc9f15bf355f42343fbb
Showing with 12 additions and 10 deletions.
  1. +12 −10 src/core/fieldformatter/qgsrangefieldformatter.cpp
@@ -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 &&
@@ -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 );
}
}
}
@@ -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

0 comments on commit 29f6484

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