From 403206ca06cf87d64b75cafa8629956ea7cf282b Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Fri, 3 May 2019 22:17:03 +0200 Subject: Selection: automatically unselect old selection in selectDives() DiveListView::selectDives() would only select new dives but not clear the old selection. Thus, callers would have to clear the selection first. That would lead to two selection-changed signals. Move the unselectDives() call into DiveListView::selectDives(). The DiveListView has an internal flag to prevent double signals. Signed-off-by: Berthold Stoeger --- desktop-widgets/divelistview.cpp | 11 +++++++---- desktop-widgets/mapwidget.cpp | 6 +----- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/desktop-widgets/divelistview.cpp b/desktop-widgets/divelistview.cpp index 86da4ba1a..c98338061 100644 --- a/desktop-widgets/divelistview.cpp +++ b/desktop-widgets/divelistview.cpp @@ -277,9 +277,7 @@ void DiveListView::restoreSelection() return; selectionSaved = false; - dontEmitDiveChangedSignal = true; - unselectDives(); - dontEmitDiveChangedSignal = false; + QList divesToSelect; Q_FOREACH (dive_trip_t *trip, selectedDives.keys()) { QList divesOnTrip = getDivesInTrip(trip); QList selectedDivesOnTrip = selectedDives.values(trip); @@ -289,8 +287,9 @@ void DiveListView::restoreSelection() selectTrip(trip); selectedDivesOnTrip.removeAll(-1); } - selectDives(selectedDivesOnTrip); + divesToSelect += selectedDivesOnTrip; } + selectDives(divesToSelect); } // This is a bit ugly: we hook directly into the tripChanged signal to @@ -417,6 +416,10 @@ void DiveListView::selectDives(const QList &newDiveSelection) return; dontEmitDiveChangedSignal = true; + + // First, clear the old selection + unselectDives(); + // select the dives, highest index first - this way the oldest of the dives // becomes the selected_dive that we scroll to QList sortedSelection = newDiveSelection; diff --git a/desktop-widgets/mapwidget.cpp b/desktop-widgets/mapwidget.cpp index 81f9f9419..11e6425b1 100644 --- a/desktop-widgets/mapwidget.cpp +++ b/desktop-widgets/mapwidget.cpp @@ -105,11 +105,7 @@ void MapWidget::prepareForGetDiveCoordinates(struct dive_site *ds) void MapWidget::selectedDivesChanged(const QList &list) { CHECK_IS_READY_RETURN_VOID(); - skipReload = true; - MainWindow::instance()->diveList->unselectDives(); - if (!list.empty()) - MainWindow::instance()->diveList->selectDives(list); - skipReload = false; + MainWindow::instance()->diveList->selectDives(list); } void MapWidget::coordinatesChanged(struct dive_site *ds, const location_t &location) -- cgit v1.2.3-70-g09d2