From a0aa27e86471ec94e00acfd874ca7cdd9c793308 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Fri, 1 Jan 2016 00:32:30 -0800 Subject: QML UI: handle editing of depth Getting closer to being able to really edit / add dives in the mobile UI. This works for manually added dives - needs a bit more thought for dives downloaded from dive computers as we don't necessarily want to change the maxdepth in conflict with the samples. Signed-off-by: Dirk Hohndel --- subsurface-core/helpers.h | 1 + subsurface-core/qthelper.cpp | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) (limited to 'subsurface-core') diff --git a/subsurface-core/helpers.h b/subsurface-core/helpers.h index b5c119870..5856c624f 100644 --- a/subsurface-core/helpers.h +++ b/subsurface-core/helpers.h @@ -32,6 +32,7 @@ QString getPrintingTemplatePathBundle(); void copyPath(QString src, QString dst); extern const QString get_dc_nickname(const char *model, uint32_t deviceid); int gettimezoneoffset(timestamp_t when = 0); +int parseLengthToMm(const QString &text); int parseTemperatureToMkelvin(const QString &text); QString get_dive_duration_string(timestamp_t when, QString hourText, QString minutesText); QString get_dive_date_string(timestamp_t when); diff --git a/subsurface-core/qthelper.cpp b/subsurface-core/qthelper.cpp index 25d5b4233..bddfd7608 100644 --- a/subsurface-core/qthelper.cpp +++ b/subsurface-core/qthelper.cpp @@ -1119,6 +1119,28 @@ int gettimezoneoffset(timestamp_t when) return dt2.secsTo(dt1); } +int parseLengthToMm(const QString &text) +{ + int mm; + QString numOnly = text; + numOnly.replace(",", ".").remove(QRegExp("[^-0-9.]")); + if (numOnly.isEmpty()) + return 0; + double number = numOnly.toDouble(); + switch (prefs.units.length) { + case units::FEET: + mm = feet_to_mm(number); + break; + case units::METERS: + mm = number * 1000; + break; + default: + mm = 0; + } + return mm; + +} + int parseTemperatureToMkelvin(const QString &text) { int mkelvin; -- cgit v1.2.3-70-g09d2