[PATCH 8/4] Tweak the "display_unused_tanks" preferences logic

Linus Torvalds torvalds at linux-foundation.org
Sun Jul 30 21:19:53 PDT 2017


From: Linus Torvalds <torvalds at linux-foundation.org>
Date: Sun, 30 Jul 2017 21:09:24 -0700
Subject: [PATCH 8/4] Tweak the "display_unused_tanks" preferences logic

This is really unrelated to my recent "multiple gas pressures" work, but
the test case from Gaetan Bisson showed that the logic for which
cylinders to show in the equipment tab was less than optimal.

We basically used to show only cylinders that were actively used, unless
you had the "display_unused_tanks" preference option set.  That comes
from some dive computers reporting a *lot* of cylinders that the diver
really doesn't even have with him on the dive.  And showing those extra
dummy cylinders gets pretty annoying after a time, which is why we
default to not showing unused tanks.

However, in Gaetan's case, he had a total of four cylinders on the dive:
the O2 and diluent bottle for the rebreather dive, and then bailout
bottles (both air and deco).  And while the bailout bottles weren't
actually used, Gaetan had actually filled in all the pressure details
etc for them, and so you'd really expect them to show up.  These were
*not* just some extraneous default cylinder filled in by an over-eager
dive computer.

But because the bailout wasn't used, the manual pressures at the end
were the same as at the beginning, and the "unused cylinder" logic
triggered anyway.

So tweak the logic a bit, and say that you show cylinder equipment not
only if it has been used on the dive, but also if it has any pressure
information for it.

So the o nly cylinders we don't show are the ones that really have no
interesting information at all, except for possibly the cylinder tank
type itself (which is exactly what the over-eager dive computer case
might fill in, usually in the form of a default cylinder type).

Signed-off-by: Linus Torvalds <torvalds at linux-foundation.org>
---
 qt-models/cylindermodel.cpp | 30 +++++++++++++++++++++++-------
 1 file changed, 23 insertions(+), 7 deletions(-)

diff --git a/qt-models/cylindermodel.cpp b/qt-models/cylindermodel.cpp
index 5da0d42a..594df658 100644
--- a/qt-models/cylindermodel.cpp
+++ b/qt-models/cylindermodel.cpp
@@ -484,15 +484,33 @@ void CylindersModel::clear()
 	}
 }
 
+static bool show_cylinder(struct dive *dive, int i)
+{
+	cylinder_t *cyl = dive->cylinder + i;
+
+	if (is_cylinder_used(dive, i))
+		return true;
+	if (cylinder_none(cyl))
+		return false;
+	if (cyl->start.mbar || cyl->sample_start.mbar ||
+	    cyl->end.mbar || cyl->sample_end.mbar)
+		return true;
+	if (cyl->manually_added)
+		return true;
+
+	/*
+	 * The cylinder has some data, but none of it is very interesting,
+	 * it has no pressures and no gas switches. Do we want to show it?
+	 */
+	return prefs.display_unused_tanks;
+}
+
 void CylindersModel::updateDive()
 {
 	clear();
 	rows = 0;
 	for (int i = 0; i < MAX_CYLINDERS; i++) {
-		if (!cylinder_none(&displayed_dive.cylinder[i]) &&
-				(prefs.display_unused_tanks ||
-				 is_cylinder_used(&displayed_dive, i) ||
-				 displayed_dive.cylinder[i].manually_added))
+		if (show_cylinder(&displayed_dive, i))
 			rows = i + 1;
 	}
 	if (rows > 0) {
@@ -507,10 +525,8 @@ void CylindersModel::copyFromDive(dive *d)
 		return;
 	rows = 0;
 	for (int i = 0; i < MAX_CYLINDERS; i++) {
-		if (!cylinder_none(&d->cylinder[i]) &&
-				(is_cylinder_used(d, i) || prefs.display_unused_tanks)) {
+		if (show_cylinder(d, i))
 			rows = i + 1;
-		}
 	}
 	if (rows > 0) {
 		beginInsertRows(QModelIndex(), 0, rows - 1);
-- 
2.14.0.rc1.2.g4c8247ec3



More information about the subsurface mailing list