From: Juergen Spitzmueller Date: Sat, 27 Jul 2013 09:18:16 +0000 (+0200) Subject: Fix the fix to the decimal separator problem with Qt5 X-Git-Tag: 2.1.0beta2~200 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=138bb4d14f92e347104cc41caa70fa2f7c31dc5a;p=features.git Fix the fix to the decimal separator problem with Qt5 --- diff --git a/src/frontends/qt4/qt_helpers.cpp b/src/frontends/qt4/qt_helpers.cpp index fdd12a10ff..c8160217d5 100644 --- a/src/frontends/qt4/qt_helpers.cpp +++ b/src/frontends/qt4/qt_helpers.cpp @@ -75,6 +75,23 @@ FileName imageLibFileSearch(QString & dir, QString const & name, return fn; } +namespace { + +double locstringToDouble(QString const str) +{ + QLocale loc; + bool ok; + double res = loc.toDouble(str, &ok); + if (!ok) { + // Fall back to C + QLocale c(QLocale::C); + res = c.toDouble(str); + } + return res; +} + +} // namespace anon + namespace frontend { @@ -90,7 +107,7 @@ string widgetsToLength(QLineEdit const * input, LengthCombo const * combo) Length::UNIT const unit = combo->currentLengthItem(); - return Length(length.trimmed().toDouble(), unit).asString(); + return Length(locstringToDouble(length.trimmed()), unit).asString(); } @@ -113,7 +130,7 @@ Length widgetsToLength(QLineEdit const * input, QComboBox const * combo) } } - return Length(length.trimmed().toDouble(), unit); + return Length(locstringToDouble(length.trimmed()), unit); } @@ -163,23 +180,19 @@ double widgetToDouble(QLineEdit const * input) if (text.isEmpty()) return 0.0; - return text.trimmed().toDouble(); + return locstringToDouble(text.trimmed()); } string widgetToDoubleStr(QLineEdit const * input) { - QString const text = input->text(); - if (text.isEmpty()) - return string(); - - return convert(text.trimmed().toDouble()); + return convert(widgetToDouble(input)); } void doubleToWidget(QLineEdit * input, double const & value, char f, int prec) { - QLocale loc("C"); + QLocale loc; loc.setNumberOptions(QLocale::OmitGroupSeparator); input->setText(loc.toString(value, f, prec)); }