[PATCH] When scrolling to dive, scroll to trip first

Linus Torvalds torvalds at linux-foundation.org
Mon Apr 28 10:57:58 PDT 2014


From: Linus Torvalds <torvalds at linux-foundation.org>
Date: Mon, 28 Apr 2014 10:39:06 -0700
Subject: [PATCH] When scrolling to dive, scroll to trip first

The behavior at startup is actually very annoying: we select the latest
dive, and expand the trip it is in, but since we use "scrollTo()" on
just the dive, and it's not initially visible, the startup will make the
first dive be at the top of the list view.

Which means that the actual _trip_ detail is not visible at all, since
it will have been scrolled off the list view entirely.

Fix this by first scrolling to the trip, and only then scrolling to the
actual dive (using the default "EnsureVisible" policy).  Obviously, if
it's a trip with lots of dives, scrolling to the dive may end up
scrolling away from the trip header again, but at least that never
happens at startup, and at that point you have to scroll away from the
trip just to show the dive.

Do this same dance when changing the dive selection (mainly noticeable
when picking dives on the globe view).

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

I'm not sure this is optimal (when scrolling to multiple dives - which 
happens easily in the map view - maybe it could try harder to keep as many 
of them visible as possible), but this is a lot less annoying than the 
existing behavior, imnsho.

 qt-ui/divelistview.cpp | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/qt-ui/divelistview.cpp b/qt-ui/divelistview.cpp
index 28ed09f2c74f..d8e66d0c611e 100644
--- a/qt-ui/divelistview.cpp
+++ b/qt-ui/divelistview.cpp
@@ -218,6 +218,8 @@ void DiveListView::selectDive(int i, bool scrollto, bool toggle)
 	if (idx.parent().isValid()) {
 		setAnimated(false);
 		expand(idx.parent());
+		if (scrollto)
+			scrollTo(idx.parent());
 		setAnimated(true);
 	}
 	if (scrollto)
@@ -274,6 +276,8 @@ void DiveListView::selectDives(const QList<int> &newDiveSelection)
 		this, SLOT(currentChanged(QModelIndex, QModelIndex)));
 	Q_EMIT currentDiveChanged(selected_dive);
 	const 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);
 }
 
@@ -371,6 +375,7 @@ void DiveListView::reload(DiveTripModel::Layout layout, bool forceSort)
 		if (!isExpanded(curr)) {
 			setAnimated(false);
 			expand(curr);
+			scrollTo(curr);
 			setAnimated(true);
 		}
 	}
-- 
2.0.0.rc1



More information about the subsurface mailing list