diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2021-01-17 18:29:54 +0100 |
---|---|---|
committer | bstoeger <32835590+bstoeger@users.noreply.github.com> | 2021-01-20 08:47:18 +0100 |
commit | 5d5ebfcf3c737aa8c36192eb7bf7d7dee6b33099 (patch) | |
tree | f28e670816bc6a2676b914709419665d98b28dbd /stats/chartitem.cpp | |
parent | b42e19e36b4d80716059011581851c8600338cbb (diff) | |
download | subsurface-5d5ebfcf3c737aa8c36192eb7bf7d7dee6b33099.tar.gz |
statistics: implement showing / hiding of items in QSG
To replace the QGraphicsScene, we need the possibility of
showing and hiding items.
Turns out, the QSG API is completely insane.
Whether an item should be shown is queried by the virtual
function isSubtreeBlocked(), which is supposed to be
overriden by the derived classes.
However, the common nodes for rectangles and pixmaps are
supposed to be created by QQuickWindow, for hardware
optimization. This gives nodes that cannot be derived
from and therefore whether the item is shown or not cannot
be controlled.
There are therefore two distinct cases to consider: The
node is allocated by the code directly or indirectly by
QQuickWindow.
In the latter case, we use a proxy node with the only
purpose of having a "visible" flag and add the obtained
node as a child.
This madness is performed with template trickery to get
unified code.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'stats/chartitem.cpp')
-rw-r--r-- | stats/chartitem.cpp | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/stats/chartitem.cpp b/stats/chartitem.cpp index bb01c6e2c..ce5e6860c 100644 --- a/stats/chartitem.cpp +++ b/stats/chartitem.cpp @@ -31,7 +31,7 @@ QSizeF ChartItem::sceneSize() const return view.size(); } -ChartPixmapItem::ChartPixmapItem(StatsView &v, ChartZValue z) : ChartItem(v, z), +ChartPixmapItem::ChartPixmapItem(StatsView &v, ChartZValue z) : HideableChartItem(v, z), positionDirty(false), textureDirty(false) { } @@ -56,7 +56,7 @@ void ChartPixmapItem::setPositionDirty() void ChartPixmapItem::render() { if (!node) { - node.reset(view.w()->createImageNode()); + createNode(view.w()->createImageNode()); view.addQSGNode(node.get(), zValue); } if (!img) { @@ -65,11 +65,11 @@ void ChartPixmapItem::render() } if (textureDirty) { texture.reset(view.w()->createTextureFromImage(*img, QQuickWindow::TextureHasAlphaChannel)); - node->setTexture(texture.get()); + node->node->setTexture(texture.get()); textureDirty = false; } if (positionDirty) { - node->setRect(rect); + node->node->setRect(rect); positionDirty = false; } } @@ -151,7 +151,7 @@ void ChartTextItem::setColor(const QColor &c) setTextureDirty(); } -ChartLineItem::ChartLineItem(StatsView &v, ChartZValue z, QColor color, double width) : ChartItem(v, z), +ChartLineItem::ChartLineItem(StatsView &v, ChartZValue z, QColor color, double width) : HideableChartItem(v, z), color(color), width(width), positionDirty(false), materialDirty(false) { } @@ -172,7 +172,7 @@ void ChartLineItem::render() geometry.reset(new QSGGeometry(QSGGeometry::defaultAttributes_Point2D(), 2)); geometry->setDrawingMode(QSGGeometry::DrawLines); material.reset(new QSGFlatColorMaterial); - node.reset(new QSGGeometryNode); + createNode(); node->setGeometry(geometry.get()); node->setMaterial(material.get()); view.addQSGNode(node.get(), zValue); @@ -204,7 +204,7 @@ void ChartLineItem::setLine(QPointF fromIn, QPointF toIn) view.registerDirtyChartItem(*this); } -ChartBarItem::ChartBarItem(StatsView &v, ChartZValue z, double borderWidth, bool horizontal) : ChartItem(v, z), +ChartBarItem::ChartBarItem(StatsView &v, ChartZValue z, double borderWidth, bool horizontal) : HideableChartItem(v, z), borderWidth(borderWidth), horizontal(horizontal), positionDirty(false), colorDirty(false) { @@ -217,7 +217,7 @@ ChartBarItem::~ChartBarItem() void ChartBarItem::render() { if (!node) { - node.reset(view.w()->createRectangleNode()); + createNode(view.w()->createRectangleNode()); borderGeometry.reset(new QSGGeometry(QSGGeometry::defaultAttributes_Point2D(), 4)); borderGeometry->setDrawingMode(QSGGeometry::DrawLineLoop); @@ -227,19 +227,20 @@ void ChartBarItem::render() borderNode->setGeometry(borderGeometry.get()); borderNode->setMaterial(borderMaterial.get()); - node->appendChildNode(borderNode.get()); + node->node->appendChildNode(borderNode.get()); view.addQSGNode(node.get(), zValue); positionDirty = colorDirty = true; } if (colorDirty) { - node->setColor(color); + node->node->setColor(color); borderMaterial->setColor(borderColor); + node->node->markDirty(QSGNode::DirtyMaterial); borderNode->markDirty(QSGNode::DirtyMaterial); } if (positionDirty) { - node->setRect(rect); + node->node->setRect(rect); auto vertices = borderGeometry->vertexDataAsPoint2D(); if (horizontal) { setPoint(vertices[0], rect.topLeft()); @@ -252,6 +253,7 @@ void ChartBarItem::render() setPoint(vertices[2], rect.topRight()); setPoint(vertices[3], rect.bottomRight()); } + node->node->markDirty(QSGNode::DirtyGeometry); borderNode->markDirty(QSGNode::DirtyGeometry); } |