[PATCH 2/3] Add helper function to parse gasmix strings
Joakim Bygdell
j.bygdell at gmail.com
Sat Feb 13 09:34:30 PST 2016
Signed-off-by: Joakim Bygdell <j.bygdell at gmail.com>
---
subsurface-core/helpers.h | 2 ++
subsurface-core/qthelper.cpp | 41 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 43 insertions(+)
diff --git a/subsurface-core/helpers.h b/subsurface-core/helpers.h
index 7537818..44f25f5 100644
--- a/subsurface-core/helpers.h
+++ b/subsurface-core/helpers.h
@@ -36,6 +36,8 @@ int parseLengthToMm(const QString &text);
int parseTemperatureToMkelvin(const QString &text);
int parseWeightToGrams(const QString &text);
int parsePressureToMbar(const QString &text);
+int parseGasMixO2(const QString &text);
+int parseGasMixHE(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 07ec194..a889233 100644
--- a/subsurface-core/qthelper.cpp
+++ b/subsurface-core/qthelper.cpp
@@ -885,6 +885,47 @@ int parsePressureToMbar(const QString &text)
return mbar;
}
+int parseGasMixO2(const QString &text)
+{
+ QString gasString = text;
+ int o2, number;
+ if (gasString.contains(QObject::tr("AIR"), Qt::CaseInsensitive)) {
+ o2 = O2_IN_AIR;
+ }
+ else if (gasString.contains(QObject::tr("EAN"), Qt::CaseInsensitive)) {
+ gasString.remove(QRegExp("[^0-9]"));
+ number = gasString.toInt();
+ o2 = number * 10;
+ }
+ else if (gasString.contains("/")) {
+ QStringList gasSplit = gasString.split("/");
+ number = gasSplit[0].toInt();
+ o2 = number * 10;
+ }
+ else {
+ number = gasString.toInt();
+ o2 = number * 10;
+ }
+
+ return o2;
+}
+
+int parseGasMixHE(const QString &text)
+{
+ QString gasString = text;
+ int he, number;
+ if (gasString.contains("/")) {
+ QStringList gasSplit = gasString.split("/");
+ number = gasSplit[1].toInt();
+ he = number * 10;
+ }
+ else {
+ he = 0;
+ }
+
+ return he;
+}
+
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