Skip to content

Commit 29f6484

Browse files
committed
Code cleaning: move duplicated code to lambda
1 parent bbf6214 commit 29f6484

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/core/fieldformatter/qgsrangefieldformatter.cpp

+12-10
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ QString QgsRangeFieldFormatter::representValue( QgsVectorLayer *layer, int field
4040

4141
QString result;
4242

43+
// Prepare locale
44+
std::function<QLocale()> f_locale = [ ]
45+
{
46+
QLocale locale( QgsApplication::instance()->locale() );
47+
QLocale::NumberOptions options( locale.numberOptions() );
48+
options |= QLocale::NumberOption::OmitGroupSeparator;
49+
locale.setNumberOptions( options );
50+
return locale;
51+
};
52+
4353
const QgsField field = layer->fields().at( fieldIndex );
4454

4555
if ( field.type() == QVariant::Double &&
@@ -54,11 +64,7 @@ QString QgsRangeFieldFormatter::representValue( QgsVectorLayer *layer, int field
5464
if ( ok )
5565
{
5666
// TODO: make the format configurable!
57-
QLocale locale( QgsApplication::instance()->locale() );
58-
QLocale::NumberOptions options( locale.numberOptions() );
59-
options |= QLocale::NumberOption::OmitGroupSeparator;
60-
locale.setNumberOptions( options );
61-
result = locale.toString( val, 'f', precision );
67+
result = f_locale().toString( val, 'f', precision );
6268
}
6369
}
6470
}
@@ -69,11 +75,7 @@ QString QgsRangeFieldFormatter::representValue( QgsVectorLayer *layer, int field
6975
double val( value.toInt( &ok ) );
7076
if ( ok )
7177
{
72-
QLocale locale( QgsApplication::instance()->locale() );
73-
QLocale::NumberOptions options( locale.numberOptions() );
74-
options |= QLocale::NumberOption::OmitGroupSeparator;
75-
locale.setNumberOptions( options );
76-
result = locale.toString( val );
78+
result = f_locale().toString( val );
7779
}
7880
}
7981
else

0 commit comments

Comments
 (0)