From 018be753c35d450eb1ac0169d10f3ac3a1895d20 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sun, 28 Aug 2022 09:47:37 +0200 Subject: [PATCH] selection: avoid recursion in divelist selection code When manually selecting a trip, the selectionChanged() virtual function was manually selecting the dives of the trip and thus ultimately recurse into itself. So far this seems to work OK, but better to avoid this recursion by setting the programmaticalSelectionChange flag. I'd like to send the selection-changed signal directly from selectionChanged() and this recursion would lead to double signals. Signed-off-by: Berthold Stoeger --- desktop-widgets/divelistview.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/desktop-widgets/divelistview.cpp b/desktop-widgets/divelistview.cpp index 57da7e2c3..0d563028a 100644 --- a/desktop-widgets/divelistview.cpp +++ b/desktop-widgets/divelistview.cpp @@ -534,6 +534,12 @@ void DiveListView::selectionChanged(const QItemSelection &selected, const QItemS return; } + // Avoid recursion: if later we decide to select all dives of a trip, + // this function is called again. Avoid this by setting the + // programmaticalSelectionChange flag. Note that the recursion never + // was a problem, but it just feels correct to avoid this recursion. + programmaticalSelectionChange = true; + // This is a manual selection change. This means that the core does not yet know // of the new selection. Update the core-structures accordingly and select/deselect // all dives of a trip if a trip is selected/deselected. @@ -587,6 +593,8 @@ void DiveListView::selectionChanged(const QItemSelection &selected, const QItemS // Display the new, processed, selection QTreeView::selectionChanged(selectionModel()->selection(), newDeselected); + + programmaticalSelectionChange = false; } enum asked_user {NOTYET, MERGE, DONTMERGE};