selection: avoid select_dive() and deselect_dive calls in dive list

Each of these calls recalculates the current dive and divecomputer.
Instead, collect the dives to be selected/deselected and (de)select
them at once.

This needs some code refactoring in the core, because we need a
function that
1) doesn't send a signal by itself.
2) doesn't clear the trip-selection.

This contains some reorganization of the selection functions
signatures: The filter code is the only caller that keeps the
selected dive and the only caller that cares about whether the
current dive changed. So let only the function that keeps the
selected dive return whether the current dive changed.

It's all very fragile.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2022-05-21 20:38:17 +02:00 committed by bstoeger
parent 6df1c62dfc
commit 487974ea91
6 changed files with 76 additions and 57 deletions

View file

@ -40,18 +40,24 @@ extern void dump_selection(void);
#ifdef __cplusplus
#include <vector>
#include <QVector>
// Reset the selection to the dives of the "selection" vector and send the appropriate signals.
// Set the current dive to "currentDive" and the current dive computer to "currentDc".
// "currentDive" must be an element of "selection" (or null if "seletion" is empty).
// If "currentDc" is negative, an attempt will be made to keep the current computer number.
// Returns the list of selected dives
QVector<dive *> setSelectionCore(const std::vector<dive *> &selection, dive *currentDive, int currentDc);
// As above, but sends a signal to inform the frontend of the changed selection.
// Returns true if the current dive changed.
bool setSelection(const std::vector<dive *> &selection, dive *currentDive, int currentDc);
void setSelection(const std::vector<dive *> &selection, dive *currentDive, int currentDc);
// Set selection, but try to keep the current dive. If current dive is not in selection,
// find the nearest current dive in the selection
// Returns true if the current dive changed.
bool setSelection(const std::vector<dive *> &selection);
// Does not send a signal.
bool setSelectionKeepCurrent(const std::vector<dive *> &selection);
// Get currently selected dives
std::vector<dive *> getDiveSelection();