mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Don't use "get_volume_string()" for cylinder size string
We had two totally different usage cases for "get_volume_string()": one that did the obvious "show this volume as a string", and one that tried to show a cylinder size. The function used a magic third argument (the working pressure of the cylinder) to distinguish between the two cases, but it still got it wrong. A metric cylinder doesn't necessarily have a working pressure at all, and the size is a wet size in liters. We'd pass in zero as the working pressure, and if the volume units were set to cubic feet, the logic in "get_volume_string()" would happily convert the metric wet size into the wet size in cubic feet. But that's completely wrong. An imperial cylinder size simply isn't a wet size. If you don't have a working pressure, you cannot convert the cylinder size to cubic feet. End of story. So instead of having "get_volume_string()" have magical behavior depending on working pressure, and getting it wrong anyway, just make get_volume_string do a pure volume conversion, and create a whole new function for showing the size of a cylinder. Now, if the cylinder doesn't have a working pressure, we just show the metric size, even if the user had asked for cubic feet. [Dirk Hohndel: added call to translation functions for the units] Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
7ebc31c1ec
commit
288aff9dbb
4 changed files with 30 additions and 12 deletions
|
@ -23,6 +23,32 @@ CylindersModel *CylindersModel::instance()
|
|||
return self.data();
|
||||
}
|
||||
|
||||
static QString get_cylinder_string(cylinder_t *cyl)
|
||||
{
|
||||
QString unit;
|
||||
int decimals;
|
||||
unsigned int ml = cyl->type.size.mliter;
|
||||
pressure_t wp = cyl->type.workingpressure;
|
||||
double value;
|
||||
|
||||
// We cannot use "get_volume_units()", because even when
|
||||
// using imperial units we may need to show the size in
|
||||
// liters: if we don't have a working pressure, we cannot
|
||||
// convert the cylinder size to cuft.
|
||||
if (wp.mbar && prefs.units.volume == units::CUFT) {
|
||||
value = ml_to_cuft(ml) * bar_to_atm(wp.mbar / 1000.0);
|
||||
decimals = (value > 20.0) ? 0 : (value > 2.0) ? 1 : 2;
|
||||
unit = CylindersModel::tr("cuft");
|
||||
} else {
|
||||
value = ml / 1000.0;
|
||||
decimals = 1;
|
||||
unit = CylindersModel::tr("ℓ");
|
||||
}
|
||||
|
||||
return QString("%1").arg(value, 0, 'f', decimals) + unit;
|
||||
}
|
||||
|
||||
|
||||
static QVariant percent_string(fraction_t fraction)
|
||||
{
|
||||
int permille = fraction.permille;
|
||||
|
@ -78,7 +104,7 @@ QVariant CylindersModel::data(const QModelIndex &index, int role) const
|
|||
break;
|
||||
case SIZE:
|
||||
if (cyl->type.size.mliter)
|
||||
ret = get_volume_string(cyl->type.size, true, cyl->type.workingpressure.mbar);
|
||||
ret = get_cylinder_string(cyl);
|
||||
break;
|
||||
case WORKINGPRESS:
|
||||
if (cyl->type.workingpressure.mbar)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue