diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2014-01-08 14:24:35 +0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-01-08 16:38:43 +0800 |
commit | 19b982d3dff0a942bccba9813bc3234e5cceb57f (patch) | |
tree | 53c010d8d9f4da31282204a047b057201dc9d755 /qt-ui/models.cpp | |
parent | 88fdf1b138afaead559456d1734eae88b4778f83 (diff) | |
download | subsurface-19b982d3dff0a942bccba9813bc3234e5cceb57f.tar.gz |
Make 'string_to_grams()' use proper type safe types
Make it use 'weight_t' and hide the "grams" part inside the type. That
was the whole point of the weight_t type, after all. Returning a
"double" was always bogus, since we internally always do integer grams
(and the function actually used "rint()" to get all the rounding right
anyway).
As a result, it's now called "string_to_weight()".
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/models.cpp')
-rw-r--r-- | qt-ui/models.cpp | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp index c2b324f97..7f5764779 100644 --- a/qt-ui/models.cpp +++ b/qt-ui/models.cpp @@ -464,13 +464,14 @@ void WeightModel::passInData(const QModelIndex& index, const QVariant& value) } } -double string_to_grams(char *str) +weight_t string_to_weight(char *str) { char *end; double value = strtod_flags(str, &end, 0); QString rest = QString(end).trimmed(); QString local_kg = WeightModel::tr("kg"); QString local_lbs = WeightModel::tr("lbs"); + weight_t weight; if (rest.startsWith("kg") || rest.startsWith(local_kg)) goto kg; @@ -480,9 +481,11 @@ double string_to_grams(char *str) if (prefs.units.weight == prefs.units.LBS) goto lbs; kg: - return rint(value * 1000); + weight.grams = rint(value * 1000); + return weight; lbs: - return lbs_to_grams(value); + weight.grams = lbs_to_grams(value); + return weight; } bool WeightModel::setData(const QModelIndex& index, const QVariant& value, int role) @@ -509,7 +512,7 @@ bool WeightModel::setData(const QModelIndex& index, const QVariant& value, int r break; case WEIGHT: if (CHANGED(data, "", "")) { - ws->weight.grams = string_to_grams(vString.toUtf8().data()); + ws->weight = string_to_weight(vString.toUtf8().data()); // now update the ws_info changed = true; WSInfoModel *wsim = WSInfoModel::instance(); |