mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 06:15:26 +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);
|
||||
}
|
||||
|
||||
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;
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue