statistics: remove QGraphicsView from StatSeries

All series are converted to QSG. Thus, the pointer to the
QGraphicsView can be removed from the common base class.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2021-01-18 12:35:22 +01:00 committed by bstoeger
parent b068b2b0e7
commit 2480d3b7e0
11 changed files with 25 additions and 31 deletions

View file

@ -29,19 +29,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, StatsView &view, StatsAxis *xAxis, StatsAxis *yAxis, BarSeries::BarSeries(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, view, xAxis, yAxis), StatsSeries(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, StatsView &view, StatsAxis *xAxis, StatsAxis *yAxis, BarSeries::BarSeries(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, view, xAxis, yAxis, horizontal, false, categoryName, nullptr, std::vector<QString>()) BarSeries(view, xAxis, yAxis, horizontal, false, categoryName, nullptr, std::vector<QString>())
{ {
for (const CountItem &item: items) { for (const CountItem &item: items) {
StatsOperationResults res; StatsOperationResults res;
@ -52,10 +52,10 @@ BarSeries::BarSeries(QGraphicsScene *scene, StatsView &view, StatsAxis *xAxis, S
} }
} }
BarSeries::BarSeries(QGraphicsScene *scene, StatsView &view, StatsAxis *xAxis, StatsAxis *yAxis, BarSeries::BarSeries(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, view, xAxis, yAxis, horizontal, false, categoryName, valueVariable, std::vector<QString>()) BarSeries(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),
@ -63,11 +63,11 @@ BarSeries::BarSeries(QGraphicsScene *scene, StatsView &view, StatsAxis *xAxis, S
} }
} }
BarSeries::BarSeries(QGraphicsScene *scene, StatsView &view, StatsAxis *xAxis, StatsAxis *yAxis, BarSeries::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,
std::vector<QString> valueBinNames, std::vector<QString> valueBinNames,
const std::vector<MultiItem> &items) : const std::vector<MultiItem> &items) :
BarSeries(scene, view, xAxis, yAxis, horizontal, stacked, categoryName, valueVariable, std::move(valueBinNames)) BarSeries(view, xAxis, yAxis, horizontal, stacked, categoryName, valueVariable, std::move(valueBinNames))
{ {
for (const MultiItem &item: items) { for (const MultiItem &item: items) {
StatsOperationResults res; StatsOperationResults res;

View file

@ -12,7 +12,6 @@
#include <vector> #include <vector>
#include <QRectF> #include <QRectF>
class QGraphicsScene;
class ChartBarItem; class ChartBarItem;
class ChartTextItem; class ChartTextItem;
struct InformationBox; struct InformationBox;
@ -49,13 +48,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, StatsView &view, StatsAxis *xAxis, StatsAxis *yAxis, BarSeries(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, StatsView &view, StatsAxis *xAxis, StatsAxis *yAxis, BarSeries(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, 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,
std::vector<QString> valueBinNames, std::vector<QString> valueBinNames,
const std::vector<MultiItem> &items); const std::vector<MultiItem> &items);
@ -65,7 +64,7 @@ public:
bool hover(QPointF pos) override; bool hover(QPointF pos) override;
void unhighlight() override; void unhighlight() override;
private: private:
BarSeries(QGraphicsScene *scene, 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,
std::vector<QString> valueBinNames); std::vector<QString> valueBinNames);

View file

@ -14,9 +14,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.0; static const int boxBorderWidth = 2.0;
BoxSeries::BoxSeries(QGraphicsScene *scene, StatsView &view, StatsAxis *xAxis, StatsAxis *yAxis, BoxSeries::BoxSeries(StatsView &view, StatsAxis *xAxis, StatsAxis *yAxis,
const QString &variable, const QString &unit, int decimals) : const QString &variable, const QString &unit, int decimals) :
StatsSeries(scene, view, xAxis, yAxis), StatsSeries(view, xAxis, yAxis),
variable(variable), unit(unit), decimals(decimals), highlighted(-1) variable(variable), unit(unit), decimals(decimals), highlighted(-1)
{ {
} }

View file

@ -13,11 +13,10 @@
#include <vector> #include <vector>
struct InformationBox; struct InformationBox;
class QGraphicsScene;
class BoxSeries : public StatsSeries { class BoxSeries : public StatsSeries {
public: public:
BoxSeries(QGraphicsScene *scene, StatsView &view, StatsAxis *xAxis, StatsAxis *yAxis, BoxSeries(StatsView &view, StatsAxis *xAxis, StatsAxis *yAxis,
const QString &variable, const QString &unit, int decimals); const QString &variable, const QString &unit, int decimals);
~BoxSeries(); ~BoxSeries();

View file

@ -74,9 +74,9 @@ void PieSeries::Item::highlight(ChartPieItem &item, int bin_nr, bool highlight,
highlight ? highlightedBorderColor : ::borderColor); highlight ? highlightedBorderColor : ::borderColor);
} }
PieSeries::PieSeries(QGraphicsScene *scene, StatsView &view, StatsAxis *xAxis, StatsAxis *yAxis, const QString &categoryName, PieSeries::PieSeries(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, view, xAxis, yAxis), StatsSeries(view, xAxis, yAxis),
item(view.createChartItem<ChartPieItem>(ChartZValue::Series, pieBorderWidth)), item(view.createChartItem<ChartPieItem>(ChartZValue::Series, pieBorderWidth)),
categoryName(categoryName), categoryName(categoryName),
highlighted(-1) highlighted(-1)

View file

@ -12,7 +12,6 @@
struct InformationBox; struct InformationBox;
struct ChartPieItem; struct ChartPieItem;
struct ChartTextItem; struct ChartTextItem;
class QGraphicsScene;
class QRectF; class QRectF;
class PieSeries : public StatsSeries { class PieSeries : public StatsSeries {
@ -20,7 +19,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, StatsView &view, StatsAxis *xAxis, StatsAxis *yAxis, const QString &categoryName, PieSeries(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();

View file

@ -12,9 +12,9 @@
#include "core/divelist.h" #include "core/divelist.h"
#include "core/qthelper.h" #include "core/qthelper.h"
ScatterSeries::ScatterSeries(QGraphicsScene *scene, 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) :
StatsSeries(scene, view, xAxis, yAxis), StatsSeries(view, xAxis, yAxis),
varX(varX), varY(varY) varX(varX), varY(varY)
{ {
} }

View file

@ -9,7 +9,6 @@
#include <memory> #include <memory>
#include <vector> #include <vector>
class QGraphicsScene;
class ChartScatterItem; class ChartScatterItem;
struct InformationBox; struct InformationBox;
struct StatsVariable; struct StatsVariable;
@ -17,7 +16,7 @@ struct dive;
class ScatterSeries : public StatsSeries { class ScatterSeries : public StatsSeries {
public: public:
ScatterSeries(QGraphicsScene *scene, StatsView &view, StatsAxis *xAxis, StatsAxis *yAxis, ScatterSeries(StatsView &view, StatsAxis *xAxis, StatsAxis *yAxis,
const StatsVariable &varX, const StatsVariable &varY); const StatsVariable &varX, const StatsVariable &varY);
~ScatterSeries(); ~ScatterSeries();

View file

@ -2,8 +2,8 @@
#include "statsseries.h" #include "statsseries.h"
#include "statsaxis.h" #include "statsaxis.h"
StatsSeries::StatsSeries(QGraphicsScene *scene, StatsView &view, StatsAxis *xAxis, StatsAxis *yAxis) : StatsSeries::StatsSeries(StatsView &view, StatsAxis *xAxis, StatsAxis *yAxis) :
scene(scene), view(view), xAxis(xAxis), yAxis(yAxis) view(view), xAxis(xAxis), yAxis(yAxis)
{ {
} }

View file

@ -6,19 +6,17 @@
#include <QPointF> #include <QPointF>
class QGraphicsScene;
class StatsAxis; class StatsAxis;
class StatsView; class StatsView;
class StatsSeries { class StatsSeries {
public: public:
StatsSeries(QGraphicsScene *scene, StatsView &view, StatsAxis *xAxis, StatsAxis *yAxis); StatsSeries(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;
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).
QPointF toScreen(QPointF p); QPointF toScreen(QPointF p);

View file

@ -298,7 +298,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, *this, xAxis, yAxis, std::forward<Args>(args)...); T *res = new T(*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;