diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2021-01-14 08:48:56 +0100 |
---|---|---|
committer | bstoeger <32835590+bstoeger@users.noreply.github.com> | 2021-01-20 08:47:18 +0100 |
commit | 790d2b2ddb36fd39fe8f002290288603ba1f0065 (patch) | |
tree | 95382527bd02bb60be9ebf8c22e577d74b41d8c7 /stats/chartitem.h | |
parent | b1c0d424081530161c1637a1a24ff07a4b021097 (diff) | |
download | subsurface-790d2b2ddb36fd39fe8f002290288603ba1f0065.tar.gz |
statistics: convert QuartileMarkers to QSGNodes
Slowly converting the QGraphicsScene items to QSGNodes to
avoid full replot of the scene.
This adds a new abstraction for line-nodes. Since the render()
function here is fundamentally different from the pixmap-nodes
we had so far, this has to be made virtual.
Also, move the quartile markers to their own source file,
since the StatsView source file is quite huge already.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'stats/chartitem.h')
-rw-r--r-- | stats/chartitem.h | 50 |
1 files changed, 40 insertions, 10 deletions
diff --git a/stats/chartitem.h b/stats/chartitem.h index 8cb9ef3a7..5dab8d1ea 100644 --- a/stats/chartitem.h +++ b/stats/chartitem.h @@ -7,6 +7,9 @@ #include <memory> #include <QPainter> +class QSGGeometry; +class QSGGeometryNode; +class QSGFlatColorMaterial; class QSGImageNode; class QSGTexture; class StatsView; @@ -15,31 +18,41 @@ enum class ChartZValue : int; class ChartItem { public: ChartItem(StatsView &v, ChartZValue z); - ~ChartItem(); - // Attention: The children are responsible for updating the item. None of these calls will. - void resize(QSizeF size); // Resets the canvas. Attention: image is *unitialized*. - void setPos(QPointF pos); - void render(); // Only call on render thread! + virtual ~ChartItem(); + virtual void render() = 0; // Only call on render thread! QRectF getRect() const; bool dirty; // If true, call render() when rebuilding the scene const ChartZValue zValue; protected: + QSizeF sceneSize() const; + StatsView &view; +}; + +// A chart item that blits a precalculated pixmap onto the scene. +class ChartPixmapItem : public ChartItem { +public: + ChartPixmapItem(StatsView &v, ChartZValue z); + ~ChartPixmapItem(); + + void setPos(QPointF pos); + void render() override; // Only call on render thread! + QRectF getRect() const; +protected: + void resize(QSizeF size); // Resets the canvas. Attention: image is *unitialized*. std::unique_ptr<QPainter> painter; std::unique_ptr<QImage> img; - QSizeF sceneSize() const; void setTextureDirty(); void setPositionDirty(); private: - StatsView &view; QRectF rect; - bool positionDirty; - bool textureDirty; + bool positionDirty; // true if the position changed since last render + bool textureDirty; // true if the pixmap changed since last render std::unique_ptr<QSGImageNode> node; std::unique_ptr<QSGTexture> texture; }; // Draw a rectangular background after resize. Children are responsible for calling update(). -class ChartRectItem : public ChartItem { +class ChartRectItem : public ChartPixmapItem { public: ChartRectItem(StatsView &v, ChartZValue z, const QPen &pen, const QBrush &brush, double radius); ~ChartRectItem(); @@ -50,4 +63,21 @@ private: double radius; }; +class ChartLineItem : public ChartItem { +public: + ChartLineItem(StatsView &v, ChartZValue z, QColor color, double width); + ~ChartLineItem(); + void setLine(QPointF from, QPointF to); + void render() override; // Only call on render thread! +private: + QPointF from, to; + QColor color; + double width; + bool positionDirty; + bool materialDirty; + std::unique_ptr<QSGGeometryNode> node; + std::unique_ptr<QSGFlatColorMaterial> material; + std::unique_ptr<QSGGeometry> geometry; +}; + #endif |