aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Joakim Bygdell <j.bygdell@gmail.com>2016-02-09 19:52:02 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2016-02-09 12:10:36 -0800
commit9c5b97e6cfe738fe2ac9f2b3f72ed624230aef0a (patch)
tree1f6c7c46fd27b99b4abc62ad48ae1dad5451f81c
parentbc84d280b863c4cd67c8986357e55bcffc674e13 (diff)
downloadsubsurface-9c5b97e6cfe738fe2ac9f2b3f72ed624230aef0a.tar.gz
Add helper to parse pressure strings.
Signed-off-by: Joakim Bygdell <j.bygdell@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--subsurface-core/helpers.h1
-rw-r--r--subsurface-core/qthelper.cpp21
2 files changed, 22 insertions, 0 deletions
diff --git a/subsurface-core/helpers.h b/subsurface-core/helpers.h
index b88230c67..7537818f2 100644
--- a/subsurface-core/helpers.h
+++ b/subsurface-core/helpers.h
@@ -35,6 +35,7 @@ int gettimezoneoffset(timestamp_t when = 0);
int parseLengthToMm(const QString &text);
int parseTemperatureToMkelvin(const QString &text);
int parseWeightToGrams(const QString &text);
+int parsePressureToMbar(const QString &text);
QString get_dive_duration_string(timestamp_t when, QString hourText, QString minutesText);
QString get_dive_date_string(timestamp_t when);
QString get_short_dive_date_string(timestamp_t when);
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;