diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2021-02-07 14:33:48 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2021-02-13 13:02:54 -0800 |
commit | 06a091643e63e4c0eb1d3bda61871be1b44b93a9 (patch) | |
tree | 702cb83aa4814a1241360d6b66acf60f8c3b79a6 /stats/barseries.cpp | |
parent | d63d4cd3c357a4294e4810ad320acf519b37882d (diff) | |
download | subsurface-06a091643e63e4c0eb1d3bda61871be1b44b93a9.tar.gz |
statistics: highlight selected bar
When all items of a bar in a bar chart are selected, highlight them
by overlaying with a checkerboard pattern. A gray checkerboard seems to
work reasonably well, regardless of base color.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'stats/barseries.cpp')
-rw-r--r-- | stats/barseries.cpp | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/stats/barseries.cpp b/stats/barseries.cpp index 58c6511a6..facdcae6c 100644 --- a/stats/barseries.cpp +++ b/stats/barseries.cpp @@ -6,6 +6,7 @@ #include "statstranslations.h" #include "statsview.h" #include "zvalues.h" +#include "core/dive.h" #include "core/selection.h" #include <math.h> // for lrint() @@ -183,11 +184,14 @@ void BarSeries::Item::highlight(int subitem, bool highlight, int binCount) subitems[subitem].highlight(highlight, binCount); } +// For single-bin charts, selected items are marked with a special fill and border color. +// For multi-bin charts, they are marked by a differend border color and border width. void BarSeries::SubItem::highlight(bool highlight, int binCount) { fill = highlight ? highlightedColor : binColor(bin_nr, binCount); QColor border = highlight ? highlightedBorderColor : ::borderColor; item->setColor(fill, border); + item->setSelected(selected); if (label) label->highlight(highlight, bin_nr, binCount, fill); } @@ -243,9 +247,10 @@ std::vector<BarSeries::SubItem> BarSeries::makeSubItems(std::vector<SubItemDesc> int bin_nr = 0; for (auto &[v, dives, label]: items) { if (v > 0.0) { + bool selected = std::all_of(dives.begin(), dives.end(), [] (const dive *d) { return d->selected; }); res.push_back({ view.createChartItem<ChartBarItem>(ChartZValue::Series, barBorderWidth, horizontal), std::move(dives), - {}, from, from + v, bin_nr }); + {}, from, from + v, bin_nr, selected }); if (!label.empty()) res.back().label = std::make_unique<BarLabel>(view, label, bin_nr, binCount()); } @@ -418,3 +423,19 @@ bool BarSeries::selectItemsUnderMouse(const QPointF &pos, bool) setSelection(dives, dives.empty() ? nullptr : dives.front()); return true; } + +void BarSeries::divesSelected(const QVector<dive *> &) +{ + for (Item &item: items) { + for (SubItem &subitem: item.subitems) { + bool selected = std::all_of(subitem.dives.begin(), subitem.dives.end(), [] (const dive *d) { return d->selected; }); + if (subitem.selected != selected) { + subitem.selected = selected; + + Index idx(&item - &items[0], &subitem - &item.subitems[0]); + bool highlight = idx == highlighted; + item.highlight(idx.subitem, highlight, binCount()); + } + } + } +} |