From 87db35de3cb1771cdbb16eab87bede282a49c407 Mon Sep 17 00:00:00 2001 From: Jan Mulder Date: Sun, 22 Oct 2017 14:43:55 +0200 Subject: Fix broken multi selected dive to trip See referenced issue number. It leads back to an ancient (3 year old) commit 512c42e. Not sure this issue is introduced there, but that's not relevant. Key in reproducing this is the location where the context menu is requested (using the right mouse button). When it is the row next to the trip, the add-to-trip succeeds correctly, otherwise it is a no-op. The solution is rather trivial (in hindsight). Just loop over the selected dives, and try to find the trip we want to add to. Fixes: #522 Signed-off-by: Jan Mulder --- desktop-widgets/divelistview.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'desktop-widgets') diff --git a/desktop-widgets/divelistview.cpp b/desktop-widgets/divelistview.cpp index 906563d7e..5e6bfd5f0 100644 --- a/desktop-widgets/divelistview.cpp +++ b/desktop-widgets/divelistview.cpp @@ -718,11 +718,20 @@ void DiveListView::addToTripAbove() void DiveListView::addToTrip(int delta) { - // if there is a trip above / below, then it's a sibling at the same - // level as this dive. So let's take a look + // d points to the row that has (mouse-)pointer focus, and there are nr rows selected struct dive *d = (struct dive *)contextMenuIndex.data(DiveTripModel::DIVE_ROLE).value(); - QModelIndex t = contextMenuIndex.sibling(contextMenuIndex.row() + delta, 0); - dive_trip_t *trip = (dive_trip_t *)t.data(DiveTripModel::TRIP_ROLE).value(); + int nr = selectionModel()->selectedRows().count(); + QModelIndex t; + dive_trip_t *trip = NULL; + + // now look for the trip to add to, for this, loop over the selected dives and + // check if its sibling is a trip. + for (int i = 1; i <= nr; i++) { + t = contextMenuIndex.sibling(contextMenuIndex.row() + (delta > 0 ? i: i * -1), 0); + trip = (dive_trip_t *)t.data(DiveTripModel::TRIP_ROLE).value(); + if (trip) + break; + } if (!trip || !d) // no dive, no trip? get me out of here -- cgit v1.2.3-70-g09d2