[PATCH 1/4] Helpers: add get_cylinder_used_gas_string()

Lubomir I. Ivanov neolit123 at gmail.com
Thu Oct 3 07:50:38 UTC 2013


From: "Lubomir I. Ivanov" <neolit123 at gmail.com>

get_cylinder_used_gas_string() retrieves used gas per cylinder
with optional units display.

Signed-off-by: Lubomir I. Ivanov <neolit123 at gmail.com>
---
 helpers.h  |  1 +
 qt-gui.cpp | 31 +++++++++++++++++++++++++++++++
 2 files changed, 32 insertions(+)

diff --git a/helpers.h b/helpers.h
index 80dc001..c9e7053 100644
--- a/helpers.h
+++ b/helpers.h
@@ -16,6 +16,7 @@ QString get_depth_string(int mm, bool showunit = false, bool showdecimal = true)
 QString get_depth_unit();
 QString get_weight_string(weight_t weight, bool showunit = false);
 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);
diff --git a/qt-gui.cpp b/qt-gui.cpp
index 41a6617..64a125d 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) {
-- 
1.7.11.msysgit.0



More information about the subsurface mailing list