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>
This commit is contained in:
Robert C. Helling 2021-01-17 13:34:18 +01:00 committed by Dirk Hohndel
parent 1797b59c10
commit 5c098eea29
10 changed files with 57 additions and 1 deletions

View file

@ -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());
}

View file

@ -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,

View file

@ -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());
}

View file

@ -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

View file

@ -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());
}

View file

@ -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();

View file

@ -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.

View file

@ -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.

View file

@ -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).

View file

@ -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 *)