aboutsummaryrefslogtreecommitdiffstats
path: root/stats
diff options
context:
space:
mode:
Diffstat (limited to 'stats')
-rw-r--r--stats/statsgrid.cpp23
-rw-r--r--stats/statsgrid.h11
-rw-r--r--stats/statsview.cpp2
3 files changed, 17 insertions, 19 deletions
diff --git a/stats/statsgrid.cpp b/stats/statsgrid.cpp
index 66c720c33..f8ad22c14 100644
--- a/stats/statsgrid.cpp
+++ b/stats/statsgrid.cpp
@@ -1,17 +1,15 @@
// SPDX-License-Identifier: GPL-2.0
#include "statsgrid.h"
+#include "chartitem.h"
#include "statsaxis.h"
#include "statscolors.h"
-#include "statshelper.h"
+#include "statsview.h"
#include "zvalues.h"
-#include <QGraphicsLineItem>
-
static const double gridWidth = 1.0;
-static const Qt::PenStyle gridStyle = Qt::SolidLine;
-StatsGrid::StatsGrid(QGraphicsScene *scene, const StatsAxis &xAxis, const StatsAxis &yAxis)
- : scene(scene), xAxis(xAxis), yAxis(yAxis)
+StatsGrid::StatsGrid(StatsView &view, const StatsAxis &xAxis, const StatsAxis &yAxis)
+ : view(view), xAxis(xAxis), yAxis(yAxis)
{
}
@@ -19,18 +17,19 @@ void StatsGrid::updatePositions()
{
std::vector<double> xtics = xAxis.ticksPositions();
std::vector<double> ytics = yAxis.ticksPositions();
+
+ // We probably should be smarter and reuse existing lines.
+ // For now, this does it.
lines.clear();
if (xtics.empty() || ytics.empty())
return;
for (double x: xtics) {
- lines.emplace_back(createItem<QGraphicsLineItem>(scene, x, ytics.front(), x, ytics.back()));
- lines.back()->setPen(QPen(gridColor, gridWidth, gridStyle));
- lines.back()->setZValue(ZValues::grid);
+ lines.push_back(view.createChartItem<ChartLineItem>(ChartZValue::Grid, gridColor, gridWidth));
+ lines.back()->setLine(QPointF(x, ytics.front()), QPointF(x, ytics.back()));
}
for (double y: ytics) {
- lines.emplace_back(createItem<QGraphicsLineItem>(scene, xtics.front(), y, xtics.back(), y));
- lines.back()->setPen(QPen(gridColor, gridWidth, gridStyle));
- lines.back()->setZValue(ZValues::grid);
+ lines.push_back(view.createChartItem<ChartLineItem>(ChartZValue::Grid, gridColor, gridWidth));
+ lines.back()->setLine(QPointF(xtics.front(), y), QPointF(xtics.back(), y));
}
}
diff --git a/stats/statsgrid.h b/stats/statsgrid.h
index 47b48b3ac..ab1b0a513 100644
--- a/stats/statsgrid.h
+++ b/stats/statsgrid.h
@@ -3,18 +3,17 @@
#include <memory>
#include <vector>
-#include <QVector>
-#include <QGraphicsLineItem>
class StatsAxis;
-class QGraphicsScene;
+class StatsView;
+class ChartLineItem;
class StatsGrid {
public:
- StatsGrid(QGraphicsScene *scene, const StatsAxis &xAxis, const StatsAxis &yAxis);
+ StatsGrid(StatsView &view, const StatsAxis &xAxis, const StatsAxis &yAxis);
void updatePositions();
private:
- QGraphicsScene *scene;
+ StatsView &view;
const StatsAxis &xAxis, &yAxis;
- std::vector<std::unique_ptr<QGraphicsLineItem>> lines;
+ std::vector<std::unique_ptr<ChartLineItem>> lines;
};
diff --git a/stats/statsview.cpp b/stats/statsview.cpp
index 29ee2d990..83a586456 100644
--- a/stats/statsview.cpp
+++ b/stats/statsview.cpp
@@ -317,7 +317,7 @@ void StatsView::setAxes(StatsAxis *x, StatsAxis *y)
xAxis = x;
yAxis = y;
if (x && y)
- grid = std::make_unique<StatsGrid>(&scene, *x, *y);
+ grid = std::make_unique<StatsGrid>(*this, *x, *y);
}
void StatsView::reset()