mirror of
https://github.com/subsurface/subsurface.git
synced 2024-12-11 03:21:29 +00:00
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:
parent
1797b59c10
commit
5c098eea29
10 changed files with 57 additions and 1 deletions
|
@ -6,6 +6,7 @@
|
||||||
#include "statstranslations.h"
|
#include "statstranslations.h"
|
||||||
#include "statsview.h"
|
#include "statsview.h"
|
||||||
#include "zvalues.h"
|
#include "zvalues.h"
|
||||||
|
#include "core/selection.h"
|
||||||
|
|
||||||
#include <math.h> // for lrint()
|
#include <math.h> // for lrint()
|
||||||
#include <QLocale>
|
#include <QLocale>
|
||||||
|
@ -404,3 +405,13 @@ void BarSeries::unhighlight()
|
||||||
items[highlighted.bar].highlight(highlighted.subitem, false, binCount());
|
items[highlighted.bar].highlight(highlighted.subitem, false, binCount());
|
||||||
highlighted = Index();
|
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());
|
||||||
|
}
|
||||||
|
|
|
@ -69,6 +69,8 @@ public:
|
||||||
void updatePositions() override;
|
void updatePositions() override;
|
||||||
bool hover(QPointF pos) override;
|
bool hover(QPointF pos) override;
|
||||||
void unhighlight() override;
|
void unhighlight() override;
|
||||||
|
void selectItemsUnderMouse(const QPointF &point) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BarSeries(StatsView &view, StatsAxis *xAxis, StatsAxis *yAxis,
|
BarSeries(StatsView &view, StatsAxis *xAxis, StatsAxis *yAxis,
|
||||||
bool horizontal, bool stacked, const QString &categoryName, const StatsVariable *valueVariable,
|
bool horizontal, bool stacked, const QString &categoryName, const StatsVariable *valueVariable,
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include "statstranslations.h"
|
#include "statstranslations.h"
|
||||||
#include "statsview.h"
|
#include "statsview.h"
|
||||||
#include "zvalues.h"
|
#include "zvalues.h"
|
||||||
|
#include "core/selection.h"
|
||||||
|
|
||||||
#include <QLocale>
|
#include <QLocale>
|
||||||
|
|
||||||
|
@ -141,3 +142,13 @@ void BoxSeries::unhighlight()
|
||||||
items[highlighted]->highlight(false);
|
items[highlighted]->highlight(false);
|
||||||
highlighted = -1;
|
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());
|
||||||
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ public:
|
||||||
void updatePositions() override;
|
void updatePositions() override;
|
||||||
bool hover(QPointF pos) override;
|
bool hover(QPointF pos) override;
|
||||||
void unhighlight() override;
|
void unhighlight() override;
|
||||||
|
void selectItemsUnderMouse(const QPointF &point) override;
|
||||||
|
|
||||||
// Note: this expects that all items are added with increasing pos
|
// Note: this expects that all items are added with increasing pos
|
||||||
// and that no bar is inside another bar, i.e. lowerBound and upperBound
|
// and that no bar is inside another bar, i.e. lowerBound and upperBound
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include "statstranslations.h"
|
#include "statstranslations.h"
|
||||||
#include "statsview.h"
|
#include "statsview.h"
|
||||||
#include "zvalues.h"
|
#include "zvalues.h"
|
||||||
|
#include "core/selection.h"
|
||||||
|
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
@ -263,3 +264,13 @@ void PieSeries::unhighlight()
|
||||||
items[highlighted].highlight(*item, highlighted, false, (int)items.size());
|
items[highlighted].highlight(*item, highlighted, false, (int)items.size());
|
||||||
highlighted = -1;
|
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());
|
||||||
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ public:
|
||||||
void updatePositions() override;
|
void updatePositions() override;
|
||||||
bool hover(QPointF pos) override;
|
bool hover(QPointF pos) override;
|
||||||
void unhighlight() override;
|
void unhighlight() override;
|
||||||
|
void selectItemsUnderMouse(const QPointF &point) override;
|
||||||
|
|
||||||
std::vector<QString> binNames();
|
std::vector<QString> binNames();
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include "core/dive.h"
|
#include "core/dive.h"
|
||||||
#include "core/divelist.h"
|
#include "core/divelist.h"
|
||||||
#include "core/qthelper.h"
|
#include "core/qthelper.h"
|
||||||
|
#include "core/selection.h"
|
||||||
|
|
||||||
ScatterSeries::ScatterSeries(StatsView &view, StatsAxis *xAxis, StatsAxis *yAxis,
|
ScatterSeries::ScatterSeries(StatsView &view, StatsAxis *xAxis, StatsAxis *yAxis,
|
||||||
const StatsVariable &varX, const StatsVariable &varY) :
|
const StatsVariable &varX, const StatsVariable &varY) :
|
||||||
|
@ -72,6 +73,16 @@ std::vector<int> ScatterSeries::getItemsUnderMouse(const QPointF &point) const
|
||||||
return res;
|
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)
|
static QString dataInfo(const StatsVariable &var, const dive *d)
|
||||||
{
|
{
|
||||||
// For "numeric" variables, we display value and unit.
|
// For "numeric" variables, we display value and unit.
|
||||||
|
|
|
@ -27,6 +27,7 @@ public:
|
||||||
|
|
||||||
// Note: this expects that all items are added with increasing pos!
|
// Note: this expects that all items are added with increasing pos!
|
||||||
void append(dive *d, double pos, double value);
|
void append(dive *d, double pos, double value);
|
||||||
|
void selectItemsUnderMouse(const QPointF &point) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Get items under mouse.
|
// Get items under mouse.
|
||||||
|
|
|
@ -16,6 +16,8 @@ public:
|
||||||
virtual void updatePositions() = 0; // Called if chart geometry changes.
|
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 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 unhighlight() = 0; // Unhighlight any highlighted item.
|
||||||
|
virtual void selectItemsUnderMouse(const QPointF &pos) = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
StatsView &view;
|
StatsView &view;
|
||||||
StatsAxis *xAxis, *yAxis; // May be zero for charts without axes (pie charts).
|
StatsAxis *xAxis, *yAxis; // May be zero for charts without axes (pie charts).
|
||||||
|
|
|
@ -64,10 +64,11 @@ StatsView::~StatsView()
|
||||||
|
|
||||||
void StatsView::mousePressEvent(QMouseEvent *event)
|
void StatsView::mousePressEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
|
QPointF pos = event->localPos();
|
||||||
|
|
||||||
// Currently, we only support dragging of the legend. If other objects
|
// Currently, we only support dragging of the legend. If other objects
|
||||||
// should be made draggable, this needs to be generalized.
|
// should be made draggable, this needs to be generalized.
|
||||||
if (legend) {
|
if (legend) {
|
||||||
QPointF pos = event->localPos();
|
|
||||||
QRectF rect = legend->getRect();
|
QRectF rect = legend->getRect();
|
||||||
if (legend->getRect().contains(pos)) {
|
if (legend->getRect().contains(pos)) {
|
||||||
dragStartMouse = pos;
|
dragStartMouse = pos;
|
||||||
|
@ -75,8 +76,12 @@ void StatsView::mousePressEvent(QMouseEvent *event)
|
||||||
draggedItem = &*legend;
|
draggedItem = &*legend;
|
||||||
grabMouse();
|
grabMouse();
|
||||||
setKeepMouseGrab(true); // don't allow Qt to steal the grab
|
setKeepMouseGrab(true); // don't allow Qt to steal the grab
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (auto &series: series)
|
||||||
|
series->selectItemsUnderMouse(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
void StatsView::mouseReleaseEvent(QMouseEvent *)
|
void StatsView::mouseReleaseEvent(QMouseEvent *)
|
||||||
|
|
Loading…
Reference in a new issue