mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Add a helper function to calculate weight display string
Add a helper function to unify the calculation of the weight display string, instead of having the same calculation in two places in the code. Signed-off-by: Benjamin Fogel <nystire@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
f63605e02e
commit
ae713763c7
4 changed files with 27 additions and 17 deletions
11
qt-gui.cpp
11
qt-gui.cpp
|
@ -216,14 +216,13 @@ QString get_depth_unit()
|
|||
|
||||
QString get_weight_string(weight_t weight, bool showunit)
|
||||
{
|
||||
if (prefs.units.weight == units::KG) {
|
||||
int gr = weight.grams % 1000;
|
||||
int kg = weight.grams / 1000;
|
||||
return QString("%1.%2%3").arg(kg).arg((unsigned)(gr) / 100).arg(showunit ? _("kg") : "");
|
||||
QString str = weight_string (weight.grams);
|
||||
if (get_units()->weight == units::KG) {
|
||||
str = QString ("%1%2").arg(str).arg(showunit ? _("kg") : "");
|
||||
} else {
|
||||
double lbs = grams_to_lbs(weight.grams);
|
||||
return QString("%1%2").arg(lbs, 0, 'f', lbs >= 40.0 ? 0 : 1 ).arg(showunit ? _("lbs") : "");
|
||||
str = QString ("%1%2").arg(str).arg(showunit ? _("lbs") : "");
|
||||
}
|
||||
return (str);
|
||||
}
|
||||
|
||||
QString get_weight_unit()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue