diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2016-02-05 22:51:46 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2016-02-05 22:51:46 -0800 |
commit | 587456190f57815f2de44b9f003a3d88d622788a (patch) | |
tree | a2390cc3d7e5c110e815e860f33a41bc079537be | |
parent | 8facdc62fd5a5a81c01a31c8df5d8a4bb3fbcdca (diff) | |
download | subsurface-587456190f57815f2de44b9f003a3d88d622788a.tar.gz |
Add helper function to parse weight strings
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | subsurface-core/helpers.h | 1 | ||||
-rw-r--r-- | subsurface-core/qthelper.cpp | 21 |
2 files changed, 22 insertions, 0 deletions
diff --git a/subsurface-core/helpers.h b/subsurface-core/helpers.h index 5856c624f..b88230c67 100644 --- a/subsurface-core/helpers.h +++ b/subsurface-core/helpers.h @@ -34,6 +34,7 @@ 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); +int parseWeightToGrams(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 e5cb2cec9..6adb06bfb 100644 --- a/subsurface-core/qthelper.cpp +++ b/subsurface-core/qthelper.cpp @@ -829,6 +829,27 @@ int parseTemperatureToMkelvin(const QString &text) return mkelvin; } +int parseWeightToGrams(const QString &text) +{ + int grams; + QString numOnly = text; + numOnly.replace(",", ".").remove(QRegExp("[^0-9.]")); + if (numOnly.isEmpty()) + return 0; + double number = numOnly.toDouble(); + switch (prefs.units.weight) { + case units::KG: + grams = rint(number * 1000); + break; + case units::LBS: + grams = lbs_to_grams(number); + break; + default: + grams = 0; + } + return grams; +} + QString get_dive_duration_string(timestamp_t when, QString hourText, QString minutesText) { int hrs, mins; |