summaryrefslogtreecommitdiffstats
path: root/stats
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2021-01-13 14:56:48 +0100
committerGravatar bstoeger <32835590+bstoeger@users.noreply.github.com>2021-01-20 08:47:18 +0100
commitd7878dad36e176ef0e2e1c54db891e115d29b489 (patch)
treec20493a14d868131b0a373d90ee8927ffd44336a /stats
parent1a869833d8896b01d04b49a58e08914658e038e9 (diff)
downloadsubsurface-d7878dad36e176ef0e2e1c54db891e115d29b489.tar.gz
statistics: pass view to series
The series were passed a pointer to the QGraphicsScene to add their item. In the future these items will be replaced by QSGNodes. To add these, the series need a reference to the StatsView. Therefore pass it in the constructor. Once everything is replaces by QSGNodes, remove the QGraphicsScene member. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'stats')
-rw-r--r--stats/barseries.cpp16
-rw-r--r--stats/barseries.h8
-rw-r--r--stats/boxseries.cpp4
-rw-r--r--stats/boxseries.h2
-rw-r--r--stats/pieseries.cpp4
-rw-r--r--stats/pieseries.h2
-rw-r--r--stats/scatterseries.cpp4
-rw-r--r--stats/scatterseries.h2
-rw-r--r--stats/statsseries.cpp4
-rw-r--r--stats/statsseries.h4
-rw-r--r--stats/statsview.cpp2
11 files changed, 27 insertions, 25 deletions
diff --git a/stats/barseries.cpp b/stats/barseries.cpp
index 49170bf80..91ab1c941 100644
--- a/stats/barseries.cpp
+++ b/stats/barseries.cpp
@@ -27,19 +27,19 @@ bool BarSeries::Index::operator==(const Index &i2) const
return std::tie(bar, subitem) == std::tie(i2.bar, i2.subitem);
}
-BarSeries::BarSeries(QGraphicsScene *scene, StatsAxis *xAxis, StatsAxis *yAxis,
+BarSeries::BarSeries(QGraphicsScene *scene, StatsView &view, StatsAxis *xAxis, StatsAxis *yAxis,
bool horizontal, bool stacked, const QString &categoryName,
const StatsVariable *valueVariable, std::vector<QString> valueBinNames) :
- StatsSeries(scene, xAxis, yAxis),
+ StatsSeries(scene, view, xAxis, yAxis),
horizontal(horizontal), stacked(stacked), categoryName(categoryName),
valueVariable(valueVariable), valueBinNames(std::move(valueBinNames))
{
}
-BarSeries::BarSeries(QGraphicsScene *scene, StatsAxis *xAxis, StatsAxis *yAxis,
+BarSeries::BarSeries(QGraphicsScene *scene, StatsView &view, StatsAxis *xAxis, StatsAxis *yAxis,
bool horizontal, const QString &categoryName,
const std::vector<CountItem> &items) :
- BarSeries(scene, xAxis, yAxis, horizontal, false, categoryName, nullptr, std::vector<QString>())
+ BarSeries(scene, view, xAxis, yAxis, horizontal, false, categoryName, nullptr, std::vector<QString>())
{
for (const CountItem &item: items) {
StatsOperationResults res;
@@ -50,10 +50,10 @@ BarSeries::BarSeries(QGraphicsScene *scene, StatsAxis *xAxis, StatsAxis *yAxis,
}
}
-BarSeries::BarSeries(QGraphicsScene *scene, StatsAxis *xAxis, StatsAxis *yAxis,
+BarSeries::BarSeries(QGraphicsScene *scene, StatsView &view, StatsAxis *xAxis, StatsAxis *yAxis,
bool horizontal, const QString &categoryName, const StatsVariable *valueVariable,
const std::vector<ValueItem> &items) :
- BarSeries(scene, xAxis, yAxis, horizontal, false, categoryName, valueVariable, std::vector<QString>())
+ BarSeries(scene, view, xAxis, yAxis, horizontal, false, categoryName, valueVariable, std::vector<QString>())
{
for (const ValueItem &item: items) {
add_item(item.lowerBound, item.upperBound, makeSubItems(item.value, item.label),
@@ -61,11 +61,11 @@ BarSeries::BarSeries(QGraphicsScene *scene, StatsAxis *xAxis, StatsAxis *yAxis,
}
}
-BarSeries::BarSeries(QGraphicsScene *scene, StatsAxis *xAxis, StatsAxis *yAxis,
+BarSeries::BarSeries(QGraphicsScene *scene, StatsView &view, StatsAxis *xAxis, StatsAxis *yAxis,
bool horizontal, bool stacked, const QString &categoryName, const StatsVariable *valueVariable,
std::vector<QString> valueBinNames,
const std::vector<MultiItem> &items) :
- BarSeries(scene, xAxis, yAxis, horizontal, stacked, categoryName, valueVariable, std::move(valueBinNames))
+ BarSeries(scene, view, xAxis, yAxis, horizontal, stacked, categoryName, valueVariable, std::move(valueBinNames))
{
for (const MultiItem &item: items) {
StatsOperationResults res;
diff --git a/stats/barseries.h b/stats/barseries.h
index 0c8c34ffd..33a36395e 100644
--- a/stats/barseries.h
+++ b/stats/barseries.h
@@ -47,13 +47,13 @@ public:
// Note: this expects that all items are added with increasing pos
// and that no bar is inside another bar, i.e. lowerBound and upperBound
// are ordered identically.
- BarSeries(QGraphicsScene *scene, StatsAxis *xAxis, StatsAxis *yAxis,
+ BarSeries(QGraphicsScene *scene, StatsView &view, StatsAxis *xAxis, StatsAxis *yAxis,
bool horizontal, const QString &categoryName,
const std::vector<CountItem> &items);
- BarSeries(QGraphicsScene *scene, StatsAxis *xAxis, StatsAxis *yAxis,
+ BarSeries(QGraphicsScene *scene, StatsView &view, StatsAxis *xAxis, StatsAxis *yAxis,
bool horizontal, const QString &categoryName, const StatsVariable *valueVariable,
const std::vector<ValueItem> &items);
- BarSeries(QGraphicsScene *scene, StatsAxis *xAxis, StatsAxis *yAxis,
+ BarSeries(QGraphicsScene *scene, StatsView &view, StatsAxis *xAxis, StatsAxis *yAxis,
bool horizontal, bool stacked, const QString &categoryName, const StatsVariable *valueVariable,
std::vector<QString> valueBinNames,
const std::vector<MultiItem> &items);
@@ -63,7 +63,7 @@ public:
bool hover(QPointF pos) override;
void unhighlight() override;
private:
- BarSeries(QGraphicsScene *scene, StatsAxis *xAxis, StatsAxis *yAxis,
+ BarSeries(QGraphicsScene *scene, StatsView &view, StatsAxis *xAxis, StatsAxis *yAxis,
bool horizontal, bool stacked, const QString &categoryName, const StatsVariable *valueVariable,
std::vector<QString> valueBinNames);
diff --git a/stats/boxseries.cpp b/stats/boxseries.cpp
index 08a421205..def20477e 100644
--- a/stats/boxseries.cpp
+++ b/stats/boxseries.cpp
@@ -12,9 +12,9 @@
static const double boxWidth = 0.8; // 1.0 = full width of category
static const int boxBorderWidth = 2;
-BoxSeries::BoxSeries(QGraphicsScene *scene, StatsAxis *xAxis, StatsAxis *yAxis,
+BoxSeries::BoxSeries(QGraphicsScene *scene, StatsView &view, StatsAxis *xAxis, StatsAxis *yAxis,
const QString &variable, const QString &unit, int decimals) :
- StatsSeries(scene, xAxis, yAxis),
+ StatsSeries(scene, view, xAxis, yAxis),
variable(variable), unit(unit), decimals(decimals), highlighted(-1)
{
}
diff --git a/stats/boxseries.h b/stats/boxseries.h
index dde9014f6..c32f903ca 100644
--- a/stats/boxseries.h
+++ b/stats/boxseries.h
@@ -18,7 +18,7 @@ class QGraphicsScene;
class BoxSeries : public StatsSeries {
public:
- BoxSeries(QGraphicsScene *scene, StatsAxis *xAxis, StatsAxis *yAxis,
+ BoxSeries(QGraphicsScene *scene, StatsView &view, StatsAxis *xAxis, StatsAxis *yAxis,
const QString &variable, const QString &unit, int decimals);
~BoxSeries();
diff --git a/stats/pieseries.cpp b/stats/pieseries.cpp
index eeecac36c..85c42b93b 100644
--- a/stats/pieseries.cpp
+++ b/stats/pieseries.cpp
@@ -85,9 +85,9 @@ void PieSeries::Item::highlight(int bin_nr, bool highlight, int numBins)
}
}
-PieSeries::PieSeries(QGraphicsScene *scene, StatsAxis *xAxis, StatsAxis *yAxis, const QString &categoryName,
+PieSeries::PieSeries(QGraphicsScene *scene, StatsView &view, StatsAxis *xAxis, StatsAxis *yAxis, const QString &categoryName,
const std::vector<std::pair<QString, int>> &data, bool keepOrder, bool labels) :
- StatsSeries(scene, xAxis, yAxis),
+ StatsSeries(scene, view, xAxis, yAxis),
categoryName(categoryName),
highlighted(-1)
{
diff --git a/stats/pieseries.h b/stats/pieseries.h
index 646c4bfbe..56e56c7d6 100644
--- a/stats/pieseries.h
+++ b/stats/pieseries.h
@@ -20,7 +20,7 @@ public:
// The pie series is initialized with (name, count) pairs.
// If keepOrder is false, bins will be sorted by size, otherwise the sorting
// of the shown bins will be retained. Small bins are omitted for clarity.
- PieSeries(QGraphicsScene *scene, StatsAxis *xAxis, StatsAxis *yAxis, const QString &categoryName,
+ PieSeries(QGraphicsScene *scene, StatsView &view, StatsAxis *xAxis, StatsAxis *yAxis, const QString &categoryName,
const std::vector<std::pair<QString, int>> &data, bool keepOrder, bool labels);
~PieSeries();
diff --git a/stats/scatterseries.cpp b/stats/scatterseries.cpp
index 8e2399008..2c5cc7716 100644
--- a/stats/scatterseries.cpp
+++ b/stats/scatterseries.cpp
@@ -16,9 +16,9 @@
static const int scatterItemDiameter = 10;
static const int scatterItemBorder = 1;
-ScatterSeries::ScatterSeries(QGraphicsScene *scene, StatsAxis *xAxis, StatsAxis *yAxis,
+ScatterSeries::ScatterSeries(QGraphicsScene *scene, StatsView &view, StatsAxis *xAxis, StatsAxis *yAxis,
const StatsVariable &varX, const StatsVariable &varY) :
- StatsSeries(scene, xAxis, yAxis),
+ StatsSeries(scene, view, xAxis, yAxis),
varX(varX), varY(varY)
{
}
diff --git a/stats/scatterseries.h b/stats/scatterseries.h
index 5f8b4b2e6..a9930b797 100644
--- a/stats/scatterseries.h
+++ b/stats/scatterseries.h
@@ -18,7 +18,7 @@ struct dive;
class ScatterSeries : public StatsSeries {
public:
- ScatterSeries(QGraphicsScene *scene, StatsAxis *xAxis, StatsAxis *yAxis,
+ ScatterSeries(QGraphicsScene *scene, StatsView &view, StatsAxis *xAxis, StatsAxis *yAxis,
const StatsVariable &varX, const StatsVariable &varY);
~ScatterSeries();
diff --git a/stats/statsseries.cpp b/stats/statsseries.cpp
index 2b7a5adea..ae12c7403 100644
--- a/stats/statsseries.cpp
+++ b/stats/statsseries.cpp
@@ -2,8 +2,8 @@
#include "statsseries.h"
#include "statsaxis.h"
-StatsSeries::StatsSeries(QGraphicsScene *scene, StatsAxis *xAxis, StatsAxis *yAxis) :
- scene(scene), xAxis(xAxis), yAxis(yAxis)
+StatsSeries::StatsSeries(QGraphicsScene *scene, StatsView &view, StatsAxis *xAxis, StatsAxis *yAxis) :
+ scene(scene), view(view), xAxis(xAxis), yAxis(yAxis)
{
}
diff --git a/stats/statsseries.h b/stats/statsseries.h
index 2494569e6..b24be7a79 100644
--- a/stats/statsseries.h
+++ b/stats/statsseries.h
@@ -8,16 +8,18 @@
class QGraphicsScene;
class StatsAxis;
+class StatsView;
class StatsSeries {
public:
- StatsSeries(QGraphicsScene *scene, StatsAxis *xAxis, StatsAxis *yAxis);
+ StatsSeries(QGraphicsScene *scene, StatsView &view, StatsAxis *xAxis, StatsAxis *yAxis);
virtual ~StatsSeries();
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.
protected:
QGraphicsScene *scene;
+ StatsView &view;
StatsAxis *xAxis, *yAxis; // May be zero for charts without axes (pie charts).
QPointF toScreen(QPointF p);
};
diff --git a/stats/statsview.cpp b/stats/statsview.cpp
index 5f9f51f6d..e97510087 100644
--- a/stats/statsview.cpp
+++ b/stats/statsview.cpp
@@ -246,7 +246,7 @@ void StatsView::hoverMoveEvent(QHoverEvent *event)
template <typename T, class... Args>
T *StatsView::createSeries(Args&&... args)
{
- T *res = new T(&scene, xAxis, yAxis, std::forward<Args>(args)...);
+ T *res = new T(&scene, *this, xAxis, yAxis, std::forward<Args>(args)...);
series.emplace_back(res);
series.back()->updatePositions();
return res;