diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2021-01-14 12:37:26 +0100 |
---|---|---|
committer | bstoeger <32835590+bstoeger@users.noreply.github.com> | 2021-01-20 08:47:18 +0100 |
commit | 9b7565e81a0b62711eaeafb633047a819e149170 (patch) | |
tree | 6f4b2fff445f6bccd17236566d49ca10dc54528e /stats/statsgrid.cpp | |
parent | c74975632e4ed6a63773b893b164055e4b17920f (diff) | |
download | subsurface-9b7565e81a0b62711eaeafb633047a819e149170.tar.gz |
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 <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'stats/statsgrid.cpp')
-rw-r--r-- | stats/statsgrid.cpp | 23 |
1 files changed, 11 insertions, 12 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)); } } |