summaryrefslogtreecommitdiffstats
path: root/core/qthelper.cpp
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2020-08-15 13:46:16 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-08-16 16:23:19 -0700
commit5299d8291de3b0ab2522ede6b1b7ee1e1f81f864 (patch)
tree2fc097f2ed4ebc634374dcdadb73f822be6a0ee9 /core/qthelper.cpp
parentebcfb46d8cec3adcb330cef32b4ff2f1c2d9b8a3 (diff)
downloadsubsurface-5299d8291de3b0ab2522ede6b1b7ee1e1f81f864.tar.gz
core/localized-parsing: correctly handle group and decimal separator
We are usually showing pressures with localized group separator. And we made a total mess out of things when then re-parsing those values. This caused us to ignore start and end pressures in Subsurface-mobile when those were entered in psi and included a group separator: 2,900psi was turned into 2.900psi which we then rounded to 0 mbar. This fixes the problem by asking Qt to do the right thing instead of doing stupid separator magic. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'core/qthelper.cpp')
-rw-r--r--core/qthelper.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/core/qthelper.cpp b/core/qthelper.cpp
index 656640755..0de3e6002 100644
--- a/core/qthelper.cpp
+++ b/core/qthelper.cpp
@@ -829,10 +829,16 @@ int parsePressureToMbar(const QString &text)
{
int mbar;
QString numOnly = text;
- numOnly.replace(",", ".").remove(QRegExp("[^0-9.]"));
+ // different locales use different symbols as group separator or decimal separator
+ // (I think it's usually '.' and ',' - but maybe there are others?)
+ // let's use Qt's help to get the parsing right
+ QString validNumberCharacters("0-9");
+ validNumberCharacters += loc.decimalPoint();
+ validNumberCharacters += loc.groupSeparator();
+ numOnly.remove(QRegExp(QString("[^%1]").arg(validNumberCharacters)));
if (numOnly.isEmpty())
return 0;
- double number = numOnly.toDouble();
+ double number = loc.toDouble(numOnly);
if (text.contains(gettextFromC::tr("bar"), Qt::CaseInsensitive)) {
mbar = lrint(number * 1000);
} else if (text.contains(gettextFromC::tr("psi"), Qt::CaseInsensitive)) {