Skip to content
Snippets Groups Projects
Commit ded2bb11 authored by Victor Poughon's avatar Victor Poughon
Browse files

BUG: fix spinbox locale issue (force C locale)

parent 44005a23
Branches
Tags
No related merge requests found
...@@ -103,7 +103,8 @@ void QtWidgetSpinBox::SetValueNoSignal(int value) ...@@ -103,7 +103,8 @@ void QtWidgetSpinBox::SetValueNoSignal(int value)
int QtWidgetSpinBox::valueFromText(const QString &text) const int QtWidgetSpinBox::valueFromText(const QString &text) const
{ {
bool ok; bool ok;
int result = QLocale::system().toInt(text, &ok); // Force C locale because OTB gui is not i18n
int result = QLocale::c().toInt(text, &ok);
if (ok) if (ok)
{ {
return result; return result;
...@@ -162,7 +163,8 @@ void QtWidgetDoubleSpinBox::SetValueNoSignal(double value) ...@@ -162,7 +163,8 @@ void QtWidgetDoubleSpinBox::SetValueNoSignal(double value)
double QtWidgetDoubleSpinBox::valueFromText(const QString &text) const double QtWidgetDoubleSpinBox::valueFromText(const QString &text) const
{ {
bool ok; bool ok;
double result = QLocale::system().toDouble(text, &ok); // Force C locale because OTB gui is not i18n
double result = QLocale::c().toDouble(text, &ok);
if (ok) if (ok)
{ {
return result; return result;
...@@ -180,7 +182,9 @@ QString QtWidgetDoubleSpinBox::textFromValue(double value) const ...@@ -180,7 +182,9 @@ QString QtWidgetDoubleSpinBox::textFromValue(double value) const
// which leads to ugly trailing zeros for small values (e.g 1.50000) // which leads to ugly trailing zeros for small values (e.g 1.50000)
// We use std::ostringstream because QString::arg formatting support is too limited // We use std::ostringstream because QString::arg formatting support is too limited
std::ostringstream oss; std::ostringstream oss;
oss.imbue(std::locale("")); // use system's locale for formatting
// Force C locale because OTB gui is not i18n
oss.imbue(std::locale::classic());
// Set precision to the number of decimal digits that can be represented without change. // Set precision to the number of decimal digits that can be represented without change.
// Use float precision because OTB parameter is float // Use float precision because OTB parameter is float
...@@ -190,9 +194,8 @@ QString QtWidgetDoubleSpinBox::textFromValue(double value) const ...@@ -190,9 +194,8 @@ QString QtWidgetDoubleSpinBox::textFromValue(double value) const
// Add a trailing dot if the number is integer, // Add a trailing dot if the number is integer,
// so that int and float parameters are more visually different. // so that int and float parameters are more visually different.
// For now this is done for all locales, even though not all locales use this // This is an ok convention as long as we stay in C or english locale
// convention for formatting decimals... const char dot = std::use_facet<std::numpunct<char>>(std::locale::classic()).decimal_point();
const char dot = std::use_facet<std::numpunct<char>>(std::locale("")).decimal_point();
if (oss.str().find(dot) == std::string::npos) if (oss.str().find(dot) == std::string::npos)
{ {
oss << dot; oss << dot;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment