[PATCH 1/3] Add helper to parse pressure strings.

Joakim Bygdell j.bygdell at gmail.com
Tue Feb 9 09:03:23 PST 2016


Signed-off-by: Joakim Bygdell <j.bygdell at gmail.com>
---
 subsurface-core/helpers.h    |  1 +
 subsurface-core/qthelper.cpp | 21 +++++++++++++++++++++
 2 files changed, 22 insertions(+)

diff --git a/subsurface-core/helpers.h b/subsurface-core/helpers.h
index b88230c..7537818 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 6adb06b..b091109 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::KG:
+		mbar = rint(number * 1000);
+		break;
+	case units::LBS:
+		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;
-- 
2.4.9 (Apple Git-60)



More information about the subsurface mailing list