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 | |
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')
-rw-r--r-- | stats/statsgrid.cpp | 23 | ||||
-rw-r--r-- | stats/statsgrid.h | 11 | ||||
-rw-r--r-- | stats/statsview.cpp | 2 |
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() |