diff options
author | Robert C. Helling <helling@atdotde.de> | 2021-01-17 13:34:18 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2021-02-13 13:02:54 -0800 |
commit | 5c098eea29fdb1cd663b78db4e430a1c76c2209a (patch) | |
tree | d084244a3dfc20739e78bc4284e0b1075bb82a8e /stats | |
parent | 1797b59c102eaa5b2091504d96616433aaf0a239 (diff) | |
download | subsurface-5c098eea29fdb1cd663b78db4e430a1c76c2209a.tar.gz |
statistics: select dives from Scatter Plot
When clicking on items in a plot, select the corresponding
dives. This can be useful for data validation.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'stats')
-rw-r--r-- | stats/barseries.cpp | 11 | ||||
-rw-r--r-- | stats/barseries.h | 2 | ||||
-rw-r--r-- | stats/boxseries.cpp | 11 | ||||
-rw-r--r-- | stats/boxseries.h | 1 | ||||
-rw-r--r-- | stats/pieseries.cpp | 11 | ||||
-rw-r--r-- | stats/pieseries.h | 1 | ||||
-rw-r--r-- | stats/scatterseries.cpp | 11 | ||||
-rw-r--r-- | stats/scatterseries.h | 1 | ||||
-rw-r--r-- | stats/statsseries.h | 2 | ||||
-rw-r--r-- | stats/statsview.cpp | 7 |
10 files changed, 57 insertions, 1 deletions
diff --git a/stats/barseries.cpp b/stats/barseries.cpp index 8767a04db..a501ddea9 100644 --- a/stats/barseries.cpp +++ b/stats/barseries.cpp @@ -6,6 +6,7 @@ #include "statstranslations.h" #include "statsview.h" #include "zvalues.h" +#include "core/selection.h" #include <math.h> // for lrint() #include <QLocale> @@ -404,3 +405,13 @@ void BarSeries::unhighlight() items[highlighted.bar].highlight(highlighted.subitem, false, binCount()); highlighted = Index(); } + +void BarSeries::selectItemsUnderMouse(const QPointF &pos) +{ + Index index = getItemUnderMouse(pos); + if (index.bar < 0) + return setSelection({}, nullptr); + + const std::vector<dive *> &dives = items[index.bar].subitems[index.subitem].dives; + setSelection(dives, dives.empty() ? nullptr : dives.front()); +} diff --git a/stats/barseries.h b/stats/barseries.h index 8c83648ea..9e0eec355 100644 --- a/stats/barseries.h +++ b/stats/barseries.h @@ -69,6 +69,8 @@ public: void updatePositions() override; bool hover(QPointF pos) override; void unhighlight() override; + void selectItemsUnderMouse(const QPointF &point) override; + private: BarSeries(StatsView &view, StatsAxis *xAxis, StatsAxis *yAxis, bool horizontal, bool stacked, const QString &categoryName, const StatsVariable *valueVariable, diff --git a/stats/boxseries.cpp b/stats/boxseries.cpp index 06aa8b095..564842001 100644 --- a/stats/boxseries.cpp +++ b/stats/boxseries.cpp @@ -7,6 +7,7 @@ #include "statstranslations.h" #include "statsview.h" #include "zvalues.h" +#include "core/selection.h" #include <QLocale> @@ -141,3 +142,13 @@ void BoxSeries::unhighlight() items[highlighted]->highlight(false); highlighted = -1; } + +void BoxSeries::selectItemsUnderMouse(const QPointF &pos) +{ + int index = getItemUnderMouse(pos); + if (index < 0) + return setSelection({}, nullptr); + + const std::vector<dive *> &dives = items[index]->q.dives; + setSelection(dives, dives.empty() ? nullptr : dives.front()); +} diff --git a/stats/boxseries.h b/stats/boxseries.h index ce48397ea..ccf8b9883 100644 --- a/stats/boxseries.h +++ b/stats/boxseries.h @@ -23,6 +23,7 @@ public: void updatePositions() override; bool hover(QPointF pos) override; void unhighlight() override; + void selectItemsUnderMouse(const QPointF &point) override; // Note: this expects that all items are added with increasing pos // and that no bar is inside another bar, i.e. lowerBound and upperBound diff --git a/stats/pieseries.cpp b/stats/pieseries.cpp index f8c5aa980..ff0690bb8 100644 --- a/stats/pieseries.cpp +++ b/stats/pieseries.cpp @@ -6,6 +6,7 @@ #include "statstranslations.h" #include "statsview.h" #include "zvalues.h" +#include "core/selection.h" #include <numeric> #include <math.h> @@ -263,3 +264,13 @@ void PieSeries::unhighlight() items[highlighted].highlight(*item, highlighted, false, (int)items.size()); highlighted = -1; } + +void PieSeries::selectItemsUnderMouse(const QPointF &pos) +{ + int index = getItemUnderMouse(pos); + if (index < 0) + return setSelection({}, nullptr); + + const std::vector<dive *> &dives = items[index].dives; + setSelection(dives, dives.empty() ? nullptr : dives.front()); +} diff --git a/stats/pieseries.h b/stats/pieseries.h index 4fbf689bd..2706fbb41 100644 --- a/stats/pieseries.h +++ b/stats/pieseries.h @@ -28,6 +28,7 @@ public: void updatePositions() override; bool hover(QPointF pos) override; void unhighlight() override; + void selectItemsUnderMouse(const QPointF &point) override; std::vector<QString> binNames(); diff --git a/stats/scatterseries.cpp b/stats/scatterseries.cpp index 03763c118..d5bf69ebb 100644 --- a/stats/scatterseries.cpp +++ b/stats/scatterseries.cpp @@ -11,6 +11,7 @@ #include "core/dive.h" #include "core/divelist.h" #include "core/qthelper.h" +#include "core/selection.h" ScatterSeries::ScatterSeries(StatsView &view, StatsAxis *xAxis, StatsAxis *yAxis, const StatsVariable &varX, const StatsVariable &varY) : @@ -72,6 +73,16 @@ std::vector<int> ScatterSeries::getItemsUnderMouse(const QPointF &point) const return res; } +void ScatterSeries::selectItemsUnderMouse(const QPointF &point) +{ + std::vector<struct dive *> selected; + + for(int idx: getItemsUnderMouse(point)) + selected.push_back(items[idx].d); + + setSelection(selected, selected.empty() ? nullptr : selected.front()); +} + static QString dataInfo(const StatsVariable &var, const dive *d) { // For "numeric" variables, we display value and unit. diff --git a/stats/scatterseries.h b/stats/scatterseries.h index e1642f4c6..a0dbcd82e 100644 --- a/stats/scatterseries.h +++ b/stats/scatterseries.h @@ -27,6 +27,7 @@ public: // Note: this expects that all items are added with increasing pos! void append(dive *d, double pos, double value); + void selectItemsUnderMouse(const QPointF &point) override; private: // Get items under mouse. diff --git a/stats/statsseries.h b/stats/statsseries.h index 360396601..5a29118fb 100644 --- a/stats/statsseries.h +++ b/stats/statsseries.h @@ -16,6 +16,8 @@ public: virtual void updatePositions() = 0; // Called if chart geometry changes. virtual bool hover(QPointF pos) = 0; // Called on mouse movement. Return true if an item of this series is highlighted. virtual void unhighlight() = 0; // Unhighlight any highlighted item. + virtual void selectItemsUnderMouse(const QPointF &pos) = 0; + protected: StatsView &view; StatsAxis *xAxis, *yAxis; // May be zero for charts without axes (pie charts). diff --git a/stats/statsview.cpp b/stats/statsview.cpp index 464339a9c..61d9db4a6 100644 --- a/stats/statsview.cpp +++ b/stats/statsview.cpp @@ -64,10 +64,11 @@ StatsView::~StatsView() void StatsView::mousePressEvent(QMouseEvent *event) { + QPointF pos = event->localPos(); + // Currently, we only support dragging of the legend. If other objects // should be made draggable, this needs to be generalized. if (legend) { - QPointF pos = event->localPos(); QRectF rect = legend->getRect(); if (legend->getRect().contains(pos)) { dragStartMouse = pos; @@ -75,8 +76,12 @@ void StatsView::mousePressEvent(QMouseEvent *event) draggedItem = &*legend; grabMouse(); setKeepMouseGrab(true); // don't allow Qt to steal the grab + return; } } + + for (auto &series: series) + series->selectItemsUnderMouse(pos); } void StatsView::mouseReleaseEvent(QMouseEvent *) |