diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2021-02-10 12:15:14 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2021-02-13 13:02:54 -0800 |
commit | 43b0ccca3e8db081378d0924de257b4185b90464 (patch) | |
tree | 1bebf8867bb6515bac6dd7d596c726b6e4729a1d /stats/statsselection.cpp | |
parent | 64b82b16a26bcaa624cc35e775b821e33133bdbb (diff) | |
download | subsurface-43b0ccca3e8db081378d0924de257b4185b90464.tar.gz |
statistics: support ctrl-selection for all series
Multiple selection using ctrl was only supported for
scatter series. Factor out the corresponding code and
use it in all series.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'stats/statsselection.cpp')
-rw-r--r-- | stats/statsselection.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/stats/statsselection.cpp b/stats/statsselection.cpp index 38bbd7f8b..82652ee68 100644 --- a/stats/statsselection.cpp +++ b/stats/statsselection.cpp @@ -1,2 +1,42 @@ // SPDX-License-Identifier: GPL-2.0 #include "statsselection.h" +#include "core/dive.h" +#include "core/selection.h" + +#include <algorithm> + +void processSelection(std::vector<dive *> dives, SelectionModifier modifier) +{ + std::vector<dive *> selected; + + if (modifier.ctrl) { + // When shift is pressed, add the items under the mouse to the selection + // or, if all items under the mouse are selected, remove them. + selected = getDiveSelection(); + bool allSelected = std::all_of(dives.begin(), dives.end(), + [] (const dive *d) { return d->selected; }); + if (allSelected) { + // Remove items under cursor from selection. This could be made more efficient. + for (const dive *d: dives) { + auto it = std::find(selected.begin(), selected.end(), d); + if (it != selected.end()) { + // Move last element to deselected element. If this already was + // the last element, this is a no-op. Then, chop off last element. + *it = selected.back(); + selected.pop_back(); + } + } + } else { + // Add items under cursor to selection + selected.reserve(dives.size() + selected.size()); + for (dive *d: dives) { + if (std::find(selected.begin(), selected.end(), d) == selected.end()) + selected.push_back(d); + } + } + } else { + selected = std::move(dives); + } + + setSelection(selected, selected.empty() ? nullptr : selected.front()); +} |