mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-07 20:53:25 +00:00
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>
This commit is contained in:
parent
1a869833d8
commit
d7878dad36
11 changed files with 27 additions and 25 deletions
|
@ -27,19 +27,19 @@ bool BarSeries::Index::operator==(const Index &i2) const
|
||||||
return std::tie(bar, subitem) == std::tie(i2.bar, i2.subitem);
|
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,
|
bool horizontal, bool stacked, const QString &categoryName,
|
||||||
const StatsVariable *valueVariable, std::vector<QString> valueBinNames) :
|
const StatsVariable *valueVariable, std::vector<QString> valueBinNames) :
|
||||||
StatsSeries(scene, xAxis, yAxis),
|
StatsSeries(scene, view, xAxis, yAxis),
|
||||||
horizontal(horizontal), stacked(stacked), categoryName(categoryName),
|
horizontal(horizontal), stacked(stacked), categoryName(categoryName),
|
||||||
valueVariable(valueVariable), valueBinNames(std::move(valueBinNames))
|
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,
|
bool horizontal, const QString &categoryName,
|
||||||
const std::vector<CountItem> &items) :
|
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) {
|
for (const CountItem &item: items) {
|
||||||
StatsOperationResults res;
|
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,
|
bool horizontal, const QString &categoryName, const StatsVariable *valueVariable,
|
||||||
const std::vector<ValueItem> &items) :
|
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) {
|
for (const ValueItem &item: items) {
|
||||||
add_item(item.lowerBound, item.upperBound, makeSubItems(item.value, item.label),
|
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,
|
bool horizontal, bool stacked, const QString &categoryName, const StatsVariable *valueVariable,
|
||||||
std::vector<QString> valueBinNames,
|
std::vector<QString> valueBinNames,
|
||||||
const std::vector<MultiItem> &items) :
|
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) {
|
for (const MultiItem &item: items) {
|
||||||
StatsOperationResults res;
|
StatsOperationResults res;
|
||||||
|
|
|
@ -47,13 +47,13 @@ public:
|
||||||
// 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
|
||||||
// are ordered identically.
|
// are ordered identically.
|
||||||
BarSeries(QGraphicsScene *scene, StatsAxis *xAxis, StatsAxis *yAxis,
|
BarSeries(QGraphicsScene *scene, StatsView &view, StatsAxis *xAxis, StatsAxis *yAxis,
|
||||||
bool horizontal, const QString &categoryName,
|
bool horizontal, const QString &categoryName,
|
||||||
const std::vector<CountItem> &items);
|
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,
|
bool horizontal, const QString &categoryName, const StatsVariable *valueVariable,
|
||||||
const std::vector<ValueItem> &items);
|
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,
|
bool horizontal, bool stacked, const QString &categoryName, const StatsVariable *valueVariable,
|
||||||
std::vector<QString> valueBinNames,
|
std::vector<QString> valueBinNames,
|
||||||
const std::vector<MultiItem> &items);
|
const std::vector<MultiItem> &items);
|
||||||
|
@ -63,7 +63,7 @@ public:
|
||||||
bool hover(QPointF pos) override;
|
bool hover(QPointF pos) override;
|
||||||
void unhighlight() override;
|
void unhighlight() override;
|
||||||
private:
|
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,
|
bool horizontal, bool stacked, const QString &categoryName, const StatsVariable *valueVariable,
|
||||||
std::vector<QString> valueBinNames);
|
std::vector<QString> valueBinNames);
|
||||||
|
|
||||||
|
|
|
@ -12,9 +12,9 @@
|
||||||
static const double boxWidth = 0.8; // 1.0 = full width of category
|
static const double boxWidth = 0.8; // 1.0 = full width of category
|
||||||
static const int boxBorderWidth = 2;
|
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) :
|
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)
|
variable(variable), unit(unit), decimals(decimals), highlighted(-1)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ class QGraphicsScene;
|
||||||
|
|
||||||
class BoxSeries : public StatsSeries {
|
class BoxSeries : public StatsSeries {
|
||||||
public:
|
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);
|
const QString &variable, const QString &unit, int decimals);
|
||||||
~BoxSeries();
|
~BoxSeries();
|
||||||
|
|
||||||
|
|
|
@ -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) :
|
const std::vector<std::pair<QString, int>> &data, bool keepOrder, bool labels) :
|
||||||
StatsSeries(scene, xAxis, yAxis),
|
StatsSeries(scene, view, xAxis, yAxis),
|
||||||
categoryName(categoryName),
|
categoryName(categoryName),
|
||||||
highlighted(-1)
|
highlighted(-1)
|
||||||
{
|
{
|
||||||
|
|
|
@ -20,7 +20,7 @@ public:
|
||||||
// The pie series is initialized with (name, count) pairs.
|
// The pie series is initialized with (name, count) pairs.
|
||||||
// If keepOrder is false, bins will be sorted by size, otherwise the sorting
|
// 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.
|
// 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);
|
const std::vector<std::pair<QString, int>> &data, bool keepOrder, bool labels);
|
||||||
~PieSeries();
|
~PieSeries();
|
||||||
|
|
||||||
|
|
|
@ -16,9 +16,9 @@
|
||||||
static const int scatterItemDiameter = 10;
|
static const int scatterItemDiameter = 10;
|
||||||
static const int scatterItemBorder = 1;
|
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) :
|
const StatsVariable &varX, const StatsVariable &varY) :
|
||||||
StatsSeries(scene, xAxis, yAxis),
|
StatsSeries(scene, view, xAxis, yAxis),
|
||||||
varX(varX), varY(varY)
|
varX(varX), varY(varY)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ struct dive;
|
||||||
|
|
||||||
class ScatterSeries : public StatsSeries {
|
class ScatterSeries : public StatsSeries {
|
||||||
public:
|
public:
|
||||||
ScatterSeries(QGraphicsScene *scene, StatsAxis *xAxis, StatsAxis *yAxis,
|
ScatterSeries(QGraphicsScene *scene, StatsView &view, StatsAxis *xAxis, StatsAxis *yAxis,
|
||||||
const StatsVariable &varX, const StatsVariable &varY);
|
const StatsVariable &varX, const StatsVariable &varY);
|
||||||
~ScatterSeries();
|
~ScatterSeries();
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
#include "statsseries.h"
|
#include "statsseries.h"
|
||||||
#include "statsaxis.h"
|
#include "statsaxis.h"
|
||||||
|
|
||||||
StatsSeries::StatsSeries(QGraphicsScene *scene, StatsAxis *xAxis, StatsAxis *yAxis) :
|
StatsSeries::StatsSeries(QGraphicsScene *scene, StatsView &view, StatsAxis *xAxis, StatsAxis *yAxis) :
|
||||||
scene(scene), xAxis(xAxis), yAxis(yAxis)
|
scene(scene), view(view), xAxis(xAxis), yAxis(yAxis)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,16 +8,18 @@
|
||||||
|
|
||||||
class QGraphicsScene;
|
class QGraphicsScene;
|
||||||
class StatsAxis;
|
class StatsAxis;
|
||||||
|
class StatsView;
|
||||||
|
|
||||||
class StatsSeries {
|
class StatsSeries {
|
||||||
public:
|
public:
|
||||||
StatsSeries(QGraphicsScene *scene, StatsAxis *xAxis, StatsAxis *yAxis);
|
StatsSeries(QGraphicsScene *scene, StatsView &view, StatsAxis *xAxis, StatsAxis *yAxis);
|
||||||
virtual ~StatsSeries();
|
virtual ~StatsSeries();
|
||||||
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.
|
||||||
protected:
|
protected:
|
||||||
QGraphicsScene *scene;
|
QGraphicsScene *scene;
|
||||||
|
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).
|
||||||
QPointF toScreen(QPointF p);
|
QPointF toScreen(QPointF p);
|
||||||
};
|
};
|
||||||
|
|
|
@ -246,7 +246,7 @@ void StatsView::hoverMoveEvent(QHoverEvent *event)
|
||||||
template <typename T, class... Args>
|
template <typename T, class... Args>
|
||||||
T *StatsView::createSeries(Args&&... 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.emplace_back(res);
|
||||||
series.back()->updatePositions();
|
series.back()->updatePositions();
|
||||||
return res;
|
return res;
|
||||||
|
|
Loading…
Add table
Reference in a new issue