request for comment

Dirk Hohndel dirk at hohndel.org
Sat May 24 15:05:32 PDT 2014


I'm trying to figure out why the entirely broken code is SelectDives is
there. Here's how I would implement this - with the added advantage that
my code actually appears to work and to do what it appears the function is
intended to do...

The existing dive messes up our selection correlation, it always unselects
all other dives (which it is not supposed to do if you look at the only
caller of this code in globe.cpp) and is all in all ugly as hell.

Comments? Tomaz? You wrote that...

/D


diff --git a/qt-ui/divelistview.cpp b/qt-ui/divelistview.cpp
index 77a51343b7ce..97fa966c013d 100644
--- a/qt-ui/divelistview.cpp
+++ b/qt-ui/divelistview.cpp
@@ -241,6 +241,21 @@ void DiveListView::selectDives(const QList<int> &newDiveSelection)
 	if (!newDiveSelection.count())
 		return;
 
+	// select the dives, highest index first - this way the oldest of the dives
+	// becomes the selected_dive that we scroll to
+	QList<int> sortedSelection = newDiveSelection;
+	qSort(sortedSelection.begin(), sortedSelection.end());
+	while (!sortedSelection.isEmpty())
+		selectDive(sortedSelection.takeLast());
+
+	QSortFilterProxyModel *m = qobject_cast<QSortFilterProxyModel *>(model());
+	QModelIndex idx = m->match(m->index(0, 0), DiveTripModel::DIVE_IDX, selected_dive, 2, Qt::MatchRecursive).first();
+	if (idx.parent().isValid())
+		scrollTo(idx.parent());
+	scrollTo(idx);
+
+	return;
+#if 0
 	disconnect(selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
 		   this, SLOT(selectionChanged(QItemSelection, QItemSelection)));
 	disconnect(selectionModel(), SIGNAL(currentChanged(QModelIndex, QModelIndex)),
@@ -289,6 +304,7 @@ void DiveListView::selectDives(const QList<int> &newDiveSelection)
 	if (idx.parent().isValid())
 		scrollTo(idx.parent());
 	scrollTo(idx);
+#endif
 }
 
 void DiveListView::showSearchEdit()


More information about the subsurface mailing list