[PATCH] Show cylinders up to and including the last valid

Anton Lundin glance at acc.umu.se
Wed Nov 27 13:59:16 UTC 2013


Previous code aborted at the first invalid cylinder. This instead finds
the last valid and prints all the ones up until that one.

Fixes #295

Signed-off-by: Anton Lundin <glance at acc.umu.se>
---
 qt-ui/models.cpp | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp
index 8dfdb5c..76ad6e1 100644
--- a/qt-ui/models.cpp
+++ b/qt-ui/models.cpp
@@ -353,19 +353,16 @@ void CylindersModel::setDive(dive* d)
 		clear();
 	if (!d)
 		return;
-	int amount = MAX_CYLINDERS;
+	rows = 0;
 	for(int i = 0; i < MAX_CYLINDERS; i++) {
-		cylinder_t *cylinder = &d->cylinder[i];
-		if (cylinder_none(cylinder)) {
-			amount = i;
-			break;
+		if (!cylinder_none(&d->cylinder[i])) {
+			rows = i+1;
 		}
 	}
-	rows = amount;
 	current = d;
 	changed = false;
-	if (amount > 0) {
-		beginInsertRows(QModelIndex(), 0, amount - 1);
+	if (rows > 0) {
+		beginInsertRows(QModelIndex(), 0, rows-1);
 		endInsertRows();
 	}
 }
-- 
1.8.3.2



More information about the subsurface mailing list