diff options
-rw-r--r-- | qt-models/cylindermodel.cpp | 28 | ||||
-rw-r--r-- | subsurface-core/helpers.h | 2 | ||||
-rw-r--r-- | subsurface-core/qthelper.cpp | 10 | ||||
-rw-r--r-- | subsurface-core/subsurface-qt/DiveObjectHelper.cpp | 2 |
4 files changed, 30 insertions, 12 deletions
diff --git a/qt-models/cylindermodel.cpp b/qt-models/cylindermodel.cpp index 8341d3608..f5eb764db 100644 --- a/qt-models/cylindermodel.cpp +++ b/qt-models/cylindermodel.cpp @@ -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) diff --git a/subsurface-core/helpers.h b/subsurface-core/helpers.h index 44f25f5fa..f88da015c 100644 --- a/subsurface-core/helpers.h +++ b/subsurface-core/helpers.h @@ -19,7 +19,7 @@ QString get_weight_unit(); QString get_cylinder_used_gas_string(cylinder_t *cyl, bool showunit = false); QString get_temperature_string(temperature_t temp, bool showunit = false); QString get_temp_unit(); -QString get_volume_string(volume_t volume, bool showunit = false, int mbar = 0); +QString get_volume_string(volume_t volume, bool showunit = false); QString get_volume_unit(); QString get_pressure_string(pressure_t pressure, bool showunit = false); QString get_pressure_unit(); diff --git a/subsurface-core/qthelper.cpp b/subsurface-core/qthelper.cpp index bfc7fc57b..d1c6a8826 100644 --- a/subsurface-core/qthelper.cpp +++ b/subsurface-core/qthelper.cpp @@ -678,19 +678,11 @@ QString get_temp_unit() return QString(UTF8_DEGREE "F"); } -QString get_volume_string(volume_t volume, bool showunit, int mbar) +QString get_volume_string(volume_t volume, bool showunit) { const char *unit; int decimals; double value = get_volume_units(volume.mliter, &decimals, &unit); - if (mbar) { - // we are showing a tank size - // fix the weird imperial way of denominating size and provide - // reasonable number of decimals - if (prefs.units.volume == units::CUFT) - value *= bar_to_atm(mbar / 1000.0); - decimals = (value > 20.0) ? 0 : (value > 2.0) ? 1 : 2; - } return QString("%1%2").arg(value, 0, 'f', decimals).arg(showunit ? unit : ""); } diff --git a/subsurface-core/subsurface-qt/DiveObjectHelper.cpp b/subsurface-core/subsurface-qt/DiveObjectHelper.cpp index 376380b8c..bea9556b2 100644 --- a/subsurface-core/subsurface-qt/DiveObjectHelper.cpp +++ b/subsurface-core/subsurface-qt/DiveObjectHelper.cpp @@ -26,7 +26,7 @@ static QString getFormattedCylinder(struct dive *dive, unsigned int idx) if (!desc && idx > 0) return QString(EMPTY_DIVE_STRING); QString fmt = desc ? QString(desc) : QObject::tr("unknown"); - fmt += ", " + get_volume_string(cyl->type.size, true, 0); + fmt += ", " + get_volume_string(cyl->type.size, true); fmt += ", " + get_pressure_string(cyl->type.workingpressure, true); fmt += ", " + get_pressure_string(cyl->start, false) + " - " + get_pressure_string(cyl->end, true); fmt += ", " + get_gas_string(cyl->gasmix); |