aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Joakim Bygdell <j.bygdell@gmail.com>2016-02-12 21:12:23 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2016-02-13 10:03:50 -0800
commit6252d0cd3bda32256d284aec09230c9bf1f8291b (patch)
treed2cb8528c90fbf721bb2cd8d4f656f25721ef278
parenta91d4164b4e64fcf02dc32c1e3379b3cc15af307 (diff)
downloadsubsurface-6252d0cd3bda32256d284aec09230c9bf1f8291b.tar.gz
While parsing weight and pressure we should not change the users settings.
Now it is possible to enter a specific unit that is different from the unit stored in the preferences. If only numbers are inputed the unit will be the same as specified by the users preferences. Signed-off-by: Joakim Bygdell <j.bygdell@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--qt-mobile/qmlmanager.cpp8
-rw-r--r--subsurface-core/qthelper.cpp42
2 files changed, 28 insertions, 22 deletions
diff --git a/qt-mobile/qmlmanager.cpp b/qt-mobile/qmlmanager.cpp
index a772e0926..cd45d304a 100644
--- a/qt-mobile/qmlmanager.cpp
+++ b/qt-mobile/qmlmanager.cpp
@@ -505,20 +505,12 @@ QString QMLManager::commitChanges(QString diveId, QString date, QString location
if (weightsystem_none((void *)&d->weightsystem[1])) {
if (get_weight_string(d->weightsystem[0].weight, true) != weight) {
diveChanged = true;
- if (weight.contains(tr("kg")))
- prefs.units.weight = units::KG;
- else if (weight.contains(tr("lbs")))
- prefs.units.weight = units::LBS;
d->weightsystem[0].weight.grams = parseWeightToGrams(weight);
}
}
// start and end pressures for first cylinder only
if (get_pressure_string(d->cylinder[0].start, true) != startpressure || get_pressure_string(d->cylinder[0].end, true) != endpressure) {
diveChanged = true;
- if (startpressure.contains(tr("bar")) || endpressure.contains(tr("bar")))
- prefs.units.pressure = units::BAR;
- else if (startpressure.contains(tr("psi")) || endpressure.contains(tr("psi")))
- prefs.units.pressure = units::PSI;
d->cylinder[0].start.mbar = parsePressureToMbar(startpressure);
d->cylinder[0].end.mbar = parsePressureToMbar(endpressure);
}
diff --git a/subsurface-core/qthelper.cpp b/subsurface-core/qthelper.cpp
index f2fc7e879..07ec19486 100644
--- a/subsurface-core/qthelper.cpp
+++ b/subsurface-core/qthelper.cpp
@@ -832,20 +832,27 @@ int parseTemperatureToMkelvin(const QString &text)
int parseWeightToGrams(const QString &text)
{
int grams;
+ QString kg_or_lbs = text;
QString numOnly = text;
numOnly.replace(",", ".").remove(QRegExp("[^0-9.]"));
if (numOnly.isEmpty())
return 0;
double number = numOnly.toDouble();
- switch (prefs.units.weight) {
- case units::KG:
+ if (kg_or_lbs.contains(QObject::tr("kg")))
grams = rint(number * 1000);
- break;
- case units::LBS:
+ else if (kg_or_lbs.contains(QObject::tr("lbs")))
grams = lbs_to_grams(number);
- break;
- default:
- grams = 0;
+ else {
+ switch (prefs.units.weight) {
+ case units::KG:
+ grams = rint(number * 1000);
+ break;
+ case units::LBS:
+ grams = lbs_to_grams(number);
+ break;
+ default:
+ grams = 0;
+ }
}
return grams;
}
@@ -853,20 +860,27 @@ int parseWeightToGrams(const QString &text)
int parsePressureToMbar(const QString &text)
{
int mbar;
+ QString psi_or_bar = text;
QString numOnly = text;
numOnly.replace(",", ".").remove(QRegExp("[^0-9.]"));
if (numOnly.isEmpty())
return 0;
double number = numOnly.toDouble();
- switch (prefs.units.pressure) {
- case units::BAR:
+ if (psi_or_bar.contains(QObject::tr("bar")))
mbar = rint(number * 1000);
- break;
- case units::PSI:
+ else if (psi_or_bar.contains(QObject::tr("psi")))
mbar = psi_to_mbar(number);
- break;
- default:
- mbar = 0;
+ else {
+ switch (prefs.units.pressure) {
+ case units::BAR:
+ mbar = rint(number * 1000);
+ break;
+ case units::PSI:
+ mbar = psi_to_mbar(number);
+ break;
+ default:
+ mbar = 0;
+ }
}
return mbar;
}