From ada5e8a49d7f0944dc3ff5ee49960298c3af9535 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Thu, 14 Jan 2021 23:22:24 +0100 Subject: statistics: turn axes into QSGNode Render the labels and the title into a pixmap and render the ticks and the base line using individual QSGNodes. Attempting to render the ticks likewise into the pixmap gave horrible results, because (quite obviously) rendering with QPainter and the QSG shader gives non-matching ticks and grid lines. The memory management had to be changed a bit: The ChartItems were collected in the root QSGNode. However, the axes are added before the first plotting, so this node might not exist. Therefore, store the axes in the StatsView object. Signed-off-by: Berthold Stoeger --- stats/statsaxis.h | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) (limited to 'stats/statsaxis.h') diff --git a/stats/statsaxis.h b/stats/statsaxis.h index 9d46f753a..89c9edbe2 100644 --- a/stats/statsaxis.h +++ b/stats/statsaxis.h @@ -2,15 +2,19 @@ #ifndef STATS_AXIS_H #define STATS_AXIS_H +#include "chartitem.h" + #include #include #include -#include -#include -class QGraphicsScene; +class StatsView; +class ChartLineItem; +class QFontMetrics; -class StatsAxis : public QGraphicsLineItem { +// The labels and the title of the axis are rendered into a pixmap. +// The ticks and the baseline are realized as individual ChartLineItems. +class StatsAxis : public ChartPixmapItem { public: virtual ~StatsAxis(); // Returns minimum and maximum of shown range, not of data points. @@ -30,22 +34,25 @@ public: std::vector ticksPositions() const; // Positions in screen coordinates protected: - StatsAxis(const QString &title, bool horizontal, bool labelsBetweenTicks); + StatsAxis(StatsView &view, const QString &title, bool horizontal, bool labelsBetweenTicks); + + std::unique_ptr line; + QString title; + double titleWidth; struct Label { - std::unique_ptr label; + QString label; + int width; double pos; - Label(const QString &name, double pos, QGraphicsScene *scene, const QFont &font); }; std::vector