From 9c5b97e6cfe738fe2ac9f2b3f72ed624230aef0a Mon Sep 17 00:00:00 2001 From: Joakim Bygdell Date: Tue, 9 Feb 2016 19:52:02 +0100 Subject: Add helper to parse pressure strings. Signed-off-by: Joakim Bygdell Signed-off-by: Dirk Hohndel --- subsurface-core/qthelper.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'subsurface-core/qthelper.cpp') diff --git a/subsurface-core/qthelper.cpp b/subsurface-core/qthelper.cpp index 6adb06bfb..f2fc7e879 100644 --- a/subsurface-core/qthelper.cpp +++ b/subsurface-core/qthelper.cpp @@ -850,6 +850,27 @@ int parseWeightToGrams(const QString &text) return grams; } +int parsePressureToMbar(const QString &text) +{ + int mbar; + 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: + mbar = rint(number * 1000); + break; + case units::PSI: + mbar = psi_to_mbar(number); + break; + default: + mbar = 0; + } + return mbar; +} + QString get_dive_duration_string(timestamp_t when, QString hourText, QString minutesText) { int hrs, mins; -- cgit v1.2.3-70-g09d2