Fix imperial cylinder sizes in equipment tab

Linus Torvalds torvalds at linux-foundation.org
Thu Jan 2 21:36:01 UTC 2014


The imperial cylinder sizes are not just in cubic feet: they are in
cubic feet of gas at STP. So the imperial/metric difference is not
just about converting blindly from liters to cubic feet, you also have
to take the working pressure of the cylinder into account.

This was broken by commit f9b7c5dfe9d0 ("Make units in cells
consistant in CylindersModel"), because those poor sheltered Swedish
people have never had to work with the wondrous imperial cylinder
sizing, and think that units should make _sense_. Hah.

Signed-off-by: Linus Torvalds <torvalds at linux-foundation.org>
---

This seems to fix it from quick testing. I'd love to make the "mbar"
be a proper "pressure_t" rather than an unsigned int, but setting
default values for arguments with complex types is a fairly recent
thing, so compilers don't support it or require magic compile-time
flags to enable it or at least not complain about it.

So we're passing in "unsigned int mbar" instead of "pressure_t press".
Whatever. None of the other uses care, since they actually just do a
plain unit conversion - it's just the cylinder size that is special.

On Thu, Jan 2, 2014 at 9:14 PM, Linus Torvalds
<torvalds at linux-foundation.org> wrote:
>
> I'm guessing that Anton - being Swedish - has never been exposed to
> the horrors that are imperial cylinder sizing.
-------------- next part --------------
 helpers.h        | 2 +-
 qt-gui.cpp       | 4 +++-
 qt-ui/models.cpp | 7 ++-----
 3 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/helpers.h b/helpers.h
index bfd47f0fe8e3..f7343859dd49 100644
--- a/helpers.h
+++ b/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);
+QString get_volume_string(volume_t volume, bool showunit = false, unsigned int mbar = 0);
 QString get_volume_unit();
 QString get_pressure_string(pressure_t pressure, bool showunit = false);
 QString get_pressure_unit();
diff --git a/qt-gui.cpp b/qt-gui.cpp
index fe2068ab01da..93b11d37b54f 100644
--- a/qt-gui.cpp
+++ b/qt-gui.cpp
@@ -322,13 +322,15 @@ QString get_temp_unit()
 		return QString(UTF8_DEGREE "F");
 }
 
-QString get_volume_string(volume_t volume, bool showunit)
+QString get_volume_string(volume_t volume, bool showunit, unsigned int mbar)
 {
 	if (prefs.units.volume == units::LITER) {
 		double liter = volume.mliter / 1000.0;
 		return QString("%1%2").arg(liter, 0, 'f', liter >= 40.0 ? 0 : 1 ).arg(showunit ? translate("gettextFromC","l") : "");
 	} else {
 		double cuft = ml_to_cuft(volume.mliter);
+		if (mbar)
+			cuft *= bar_to_atm(mbar / 1000.0);
 		return QString("%1%2").arg(cuft, 0, 'f', cuft >= 20.0 ? 0 : (cuft >= 2.0 ? 1 : 2)).arg(showunit ? translate("gettextFromC","cuft") : "");
 	}
 }
diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp
index 0199c9989a8c..ab501a2bdfc6 100644
--- a/qt-ui/models.cpp
+++ b/qt-ui/models.cpp
@@ -111,11 +111,8 @@ QVariant CylindersModel::data(const QModelIndex& index, int role) const
 			ret = QString(cyl->type.description);
 			break;
 		case SIZE:
-			// we can't use get_volume_string because the idiotic imperial tank
-			// sizes take working pressure into account...
-			if (cyl->type.size.mliter) {
-				ret = get_volume_string(cyl->type.size, TRUE);
-			}
+			if (cyl->type.size.mliter)
+				ret = get_volume_string(cyl->type.size, TRUE, cyl->type.workingpressure.mbar);
 			break;
 		case WORKINGPRESS:
 			if (cyl->type.workingpressure.mbar)


More information about the subsurface mailing list