summaryrefslogtreecommitdiffstats
path: root/stats/barseries.cpp
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2021-02-10 20:59:34 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2021-02-13 13:02:54 -0800
commit2943b1cbde1a60ef00f1878a27f811246d9b2bc3 (patch)
treed205caca81c2b4fe4fabed06c9f6d747617a4a30 /stats/barseries.cpp
parent43b0ccca3e8db081378d0924de257b4185b90464 (diff)
downloadsubsurface-2943b1cbde1a60ef00f1878a27f811246d9b2bc3.tar.gz
statistics: implement shift-selection of ranges
For all the series but the scatter series (which supports lasso selection), implement a range-selection using shift. The code is fairly similar for all series and one might think about factoring it out. But why bother? Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'stats/barseries.cpp')
-rw-r--r--stats/barseries.cpp33
1 files changed, 32 insertions, 1 deletions
diff --git a/stats/barseries.cpp b/stats/barseries.cpp
index 95b02111e..698a87738 100644
--- a/stats/barseries.cpp
+++ b/stats/barseries.cpp
@@ -31,6 +31,21 @@ bool BarSeries::Index::operator==(const Index &i2) const
return std::tie(bar, subitem) == std::tie(i2.bar, i2.subitem);
}
+// Note: only defined for valid indices.
+bool BarSeries::Index::operator<=(const Index &i2) const
+{
+ return std::tie(bar, subitem) <= std::tie(i2.bar, i2.subitem);
+}
+
+// Note: only defined for valid indices.
+void BarSeries::inc(Index &index)
+{
+ if (++index.subitem < binCount())
+ return;
+ ++index.bar;
+ index.subitem = 0;
+}
+
BarSeries::BarSeries(StatsView &view, StatsAxis *xAxis, StatsAxis *yAxis,
bool horizontal, bool stacked, const QString &categoryName,
const StatsVariable *valueVariable, std::vector<QString> valueBinNames) :
@@ -415,9 +430,25 @@ bool BarSeries::selectItemsUnderMouse(const QPointF &pos, SelectionModifier modi
{
Index index = getItemUnderMouse(pos);
+ if (modifier.shift && index.bar < 0)
+ return false;
+
+ if (!modifier.shift || lastClicked.bar < 0)
+ lastClicked = index;
+
std::vector<dive *> divesUnderMouse;
- if (index.bar >= 0)
+ if (modifier.shift && lastClicked.bar >= 0 && index.bar >= 0) {
+ Index first = lastClicked;
+ Index last = index;
+ if (last <= first)
+ std::swap(first, last);
+ for (Index idx = first; idx <= last; inc(idx)) {
+ const std::vector<dive *> &dives = items[idx.bar].subitems[idx.subitem].dives;
+ divesUnderMouse.insert(divesUnderMouse.end(), dives.begin(), dives.end());
+ }
+ } else if (index.bar >= 0) {
divesUnderMouse = items[index.bar].subitems[index.subitem].dives;
+ }
processSelection(std::move(divesUnderMouse), modifier);
return index.bar >= 0;