aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--stats/barseries.cpp4
-rw-r--r--stats/boxseries.cpp23
-rw-r--r--stats/boxseries.h2
-rw-r--r--stats/statshelper.cpp7
-rw-r--r--stats/statshelper.h6
5 files changed, 37 insertions, 5 deletions
diff --git a/stats/barseries.cpp b/stats/barseries.cpp
index 2779a59c2..3220bbd1a 100644
--- a/stats/barseries.cpp
+++ b/stats/barseries.cpp
@@ -247,7 +247,7 @@ 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; });
+ bool selected = allDivesSelected(dives);
res.push_back({ view.createChartItem<ChartBarItem>(ChartZValue::Series, barBorderWidth),
std::move(dives),
{}, from, from + v, bin_nr, selected });
@@ -428,7 +428,7 @@ 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; });
+ bool selected = allDivesSelected(subitem.dives);
if (subitem.selected != selected) {
subitem.selected = selected;
diff --git a/stats/boxseries.cpp b/stats/boxseries.cpp
index 5362aa7af..78a3d258f 100644
--- a/stats/boxseries.cpp
+++ b/stats/boxseries.cpp
@@ -27,9 +27,10 @@ BoxSeries::~BoxSeries()
}
BoxSeries::Item::Item(StatsView &view, BoxSeries *series, double lowerBound, double upperBound,
- const StatsQuartiles &q, const QString &binName) :
- lowerBound(lowerBound), upperBound(upperBound), q(q),
- binName(binName)
+ const StatsQuartiles &qIn, const QString &binName) :
+ lowerBound(lowerBound), upperBound(upperBound), q(qIn),
+ binName(binName),
+ selected(allDivesSelected(q.dives))
{
item = view.createChartItem<ChartBoxItem>(ChartZValue::Series, boxBorderWidth);
highlight(false);
@@ -44,6 +45,8 @@ void BoxSeries::Item::highlight(bool highlight)
{
if (highlight)
item->setColor(highlightedColor, highlightedBorderColor);
+ else if (selected)
+ item->setColor(selectedColor, selectedBorderColor);
else
item->setColor(fillColor, ::borderColor);
}
@@ -155,3 +158,17 @@ bool BoxSeries::selectItemsUnderMouse(const QPointF &pos, bool)
setSelection(dives, dives.empty() ? nullptr : dives.front());
return true;
}
+
+void BoxSeries::divesSelected(const QVector<dive *> &)
+{
+ for (auto &item: items) {
+ bool selected = allDivesSelected(item->q.dives);
+ if (item->selected != selected) {
+ item->selected = selected;
+
+ int idx = &item - &items[0];
+ bool highlight = idx == highlighted;
+ item->highlight(highlight);
+ }
+ }
+}
diff --git a/stats/boxseries.h b/stats/boxseries.h
index 2285e11c5..cd54ea86b 100644
--- a/stats/boxseries.h
+++ b/stats/boxseries.h
@@ -39,6 +39,7 @@ private:
double lowerBound, upperBound;
StatsQuartiles q;
QString binName;
+ bool selected;
Item(StatsView &view, BoxSeries *series, double lowerBound, double upperBound, const StatsQuartiles &q, const QString &binName);
~Item();
void updatePosition(BoxSeries *series);
@@ -52,6 +53,7 @@ private:
ChartItemPtr<InformationBox> information;
std::vector<std::unique_ptr<Item>> items;
int highlighted; // -1: no item highlighted
+ void divesSelected(const QVector<dive *> &) override;
};
#endif
diff --git a/stats/statshelper.cpp b/stats/statshelper.cpp
index d84ce20cf..b08c12077 100644
--- a/stats/statshelper.cpp
+++ b/stats/statshelper.cpp
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0
#include "statshelper.h"
+#include "core/dive.h"
#include <cmath>
@@ -8,3 +9,9 @@ QPointF roundPos(const QPointF &p)
{
return QPointF(round(p.x()), round(p.y()));
}
+
+bool allDivesSelected(const std::vector<dive *> &dives)
+{
+ return std::all_of(dives.begin(), dives.end(),
+ [] (const dive *d) { return d->selected; });
+}
diff --git a/stats/statshelper.h b/stats/statshelper.h
index 45d58d022..bc3eb57a3 100644
--- a/stats/statshelper.h
+++ b/stats/statshelper.h
@@ -5,12 +5,18 @@
#define STATSHELPER_H
#include <memory>
+#include <vector>
#include <QPointF>
#include <QSGNode>
+struct dive;
+
// Round positions to integer values to avoid ugly artifacts
QPointF roundPos(const QPointF &p);
+// Are all dives in this vector selected?
+bool allDivesSelected(const std::vector<dive *> &dives);
+
// A stupid pointer class that initializes to null and can be copy
// assigned. This is for historical reasons: unique_ptrs to ChartItems
// were replaced by plain pointers. Instead of nulling the plain pointers