mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
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>
This commit is contained in:
parent
ebcfb46d8c
commit
5299d8291d
1 changed files with 8 additions and 2 deletions
|
@ -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)) {
|
||||
|
|
Loading…
Reference in a new issue