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 <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2022-08-28 09:47:37 +02:00 committed by bstoeger
parent 8581e213ed
commit 018be753c3

View file

@ -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};