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
18
qthelper.cpp
18
qthelper.cpp
|
|
@ -76,3 +76,21 @@ void DiveComputerList::rmDC(QString m, uint32_t d)
|
|||
const DiveComputerNode *existNode = this->getExact(m, d);
|
||||
dcMap.remove(m, *existNode);
|
||||
}
|
||||
|
||||
QString weight_string(int weight_in_grams)
|
||||
{
|
||||
QString str;
|
||||
if (get_units()->weight == units::KG) {
|
||||
int gr = weight_in_grams % 1000;
|
||||
int kg = weight_in_grams / 1000;
|
||||
if (kg >= 20.0) {
|
||||
str = QString("0");
|
||||
} else {
|
||||
str = QString("%1.%2").arg(kg).arg((unsigned)(gr) / 100);
|
||||
}
|
||||
} else {
|
||||
double lbs = grams_to_lbs(weight_in_grams);
|
||||
str = QString("%1").arg(lbs, 0, 'f', lbs >= 40.0 ? 0 : 1 );
|
||||
}
|
||||
return (str);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue