diff options
author | Lubomir I. Ivanov <neolit123@gmail.com> | 2013-10-03 17:50:38 +0300 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-10-03 09:38:13 -0700 |
commit | 50e74f45657415f9bde9280aabd078e963f2094a (patch) | |
tree | c670b7ff5d95a5dff153cf195e22accbf1a1354b /qt-gui.cpp | |
parent | c478ea30cb5862b1c21b63050837c282632b7ea8 (diff) | |
download | subsurface-50e74f45657415f9bde9280aabd078e963f2094a.tar.gz |
Helpers: add get_cylinder_used_gas_string()
get_cylinder_used_gas_string() retrieves used gas per cylinder
with optional units display.
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-gui.cpp')
-rw-r--r-- | qt-gui.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/qt-gui.cpp b/qt-gui.cpp index 41a6617e1..64a125dcb 100644 --- a/qt-gui.cpp +++ b/qt-gui.cpp @@ -233,6 +233,37 @@ QString get_weight_unit() return "lbs"; } +/* these methods retrieve used gas per cylinder */ +static unsigned start_pressure(cylinder_t *cyl) +{ + return cyl->start.mbar ? : cyl->sample_start.mbar; +} + +static unsigned end_pressure(cylinder_t *cyl) +{ + return cyl->end.mbar ? : cyl->sample_end.mbar; +} + +QString get_cylinder_used_gas_string(cylinder_t *cyl, bool showunit) +{ + int decimals; + const char *unit; + double gas_usage; + /* Get the cylinder gas use in mbar */ + gas_usage = start_pressure(cyl) - end_pressure(cyl); + /* Can we turn it into a volume? */ + if (cyl->type.size.mliter) { + gas_usage = bar_to_atm(gas_usage / 1000); + gas_usage *= cyl->type.size.mliter; + gas_usage = get_volume_units(gas_usage, &decimals, &unit); + } else { + gas_usage = get_pressure_units(gas_usage, &unit); + decimals = 0; + } + // tr("%.*f %s" + return QString("%1 %2").arg(gas_usage, 0, 'f', decimals).arg(showunit ? unit : ""); +} + QString get_temperature_string(temperature_t temp, bool showunit) { if (prefs.units.temperature == units::CELSIUS) { |