From 9b7565e81a0b62711eaeafb633047a819e149170 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Thu, 14 Jan 2021 12:37:26 +0100 Subject: statistics: turn ChartGrid into QSGNodes Turn the background grid into QSGNodes. Each grid line is represented by a QSG line item. An alternative would be drawing the grid into a QImage and blasting that onto the screen. It is unclear which one is preferred. Signed-off-by: Berthold Stoeger --- stats/statsgrid.cpp | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'stats/statsgrid.cpp') 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 - 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 xtics = xAxis.ticksPositions(); std::vector 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(scene, x, ytics.front(), x, ytics.back())); - lines.back()->setPen(QPen(gridColor, gridWidth, gridStyle)); - lines.back()->setZValue(ZValues::grid); + lines.push_back(view.createChartItem(ChartZValue::Grid, gridColor, gridWidth)); + lines.back()->setLine(QPointF(x, ytics.front()), QPointF(x, ytics.back())); } for (double y: ytics) { - lines.emplace_back(createItem(scene, xtics.front(), y, xtics.back(), y)); - lines.back()->setPen(QPen(gridColor, gridWidth, gridStyle)); - lines.back()->setZValue(ZValues::grid); + lines.push_back(view.createChartItem(ChartZValue::Grid, gridColor, gridWidth)); + lines.back()->setLine(QPointF(xtics.front(), y), QPointF(xtics.back(), y)); } } -- cgit v1.2.3-70-g09d2