summaryrefslogtreecommitdiffstats
path: root/desktop-widgets/command_private.cpp
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-06-23 11:13:41 +0200
committerGravatar bstoeger <32835590+bstoeger@users.noreply.github.com>2019-06-23 20:08:46 +0200
commite1abf9485cf59f1b8cb79d827fa386af48f095a4 (patch)
tree6e4c7d0fd30402622f3264c7e6e57de279d11f2e /desktop-widgets/command_private.cpp
parent27944a52b1c2a1c68ccfe88c4a84d3f74fb8b512 (diff)
downloadsubsurface-e1abf9485cf59f1b8cb79d827fa386af48f095a4.tar.gz
Undo: unify selection behavior in dive-list commands
Some commands tried to retain the current selection on undo/redo, others set the selection to the modified dives. The latter was introduced because it was easier in some cases, but it is probably more user-friendly because the user gets feedback on the change. Therefore, unify to always select the affected dives on undo()/redo(). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets/command_private.cpp')
-rw-r--r--desktop-widgets/command_private.cpp20
1 files changed, 9 insertions, 11 deletions
diff --git a/desktop-widgets/command_private.cpp b/desktop-widgets/command_private.cpp
index 7e604dfc9..6dac645b5 100644
--- a/desktop-widgets/command_private.cpp
+++ b/desktop-widgets/command_private.cpp
@@ -47,12 +47,13 @@ bool setSelection(const std::vector<dive *> &selection, dive *currentDive)
// To do so, generate vectors of dives to be selected and deselected.
// We send signals batched by trip, so keep track of trip/dive pairs.
QVector<dive *> divesToSelect;
- QVector<dive *> divesToDeselect;
+ divesToSelect.reserve(selection.size());
// TODO: We might want to keep track of selected dives in a more efficient way!
int i;
dive *d;
amount_selected = 0; // We recalculate amount_selected
+ bool selectionChanged = false;
for_each_dive(i, d) {
// We only modify dives that are currently visible.
if (d->hidden_by_filter) {
@@ -65,24 +66,21 @@ bool setSelection(const std::vector<dive *> &selection, dive *currentDive)
// TODO: By sorting the list in the same way as the backend, this could be made more efficient.
bool newState = std::find(selection.begin(), selection.end(), d) != selection.end();
+ if (newState) {
+ ++amount_selected;
+ divesToSelect.push_back(d);
+ }
// TODO: Instead of using select_dive() and deselect_dive(), we set selected directly.
// The reason is that deselect() automatically sets a new current dive, which we
// don't want, as we set it later anyway.
// There is other parts of the C++ code that touches the innards directly, but
// ultimately this should be pushed down to C.
- if (newState && !d->selected) {
- d->selected = true;
- ++amount_selected;
- divesToSelect.push_back(d);
- } else if (!newState && d->selected) {
- d->selected = false;
- divesToDeselect.push_back(d);
- }
+ selectionChanged |= d->selected != newState;
+ d->selected = newState;
}
// Send the select and deselect signals
emit diveListNotifier.divesSelected(divesToSelect);
- emit diveListNotifier.divesDeselected(divesToDeselect);
bool currentDiveChanged = false;
if (!currentDive) {
@@ -105,7 +103,7 @@ bool setSelection(const std::vector<dive *> &selection, dive *currentDive)
}
// return true if selection of current dive changed
- return !divesToSelect.empty() || !divesToDeselect.empty() || currentDiveChanged;
+ return selectionChanged || currentDiveChanged;
}
// Turn current selection into a vector.