diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2021-01-20 23:13:54 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2021-01-21 13:42:14 -0800 |
commit | 54ff31f5c19f4a6a7408a66e2ad33678896de529 (patch) | |
tree | 30695880e48b137635c583392d3740798ccb4aba /stats | |
parent | 913bed19bbbd43c5934b6d26d94e3f260a1a76d3 (diff) | |
download | subsurface-54ff31f5c19f4a6a7408a66e2ad33678896de529.tar.gz |
statistics: do resizing in UI thread, not render thread
The updatePaintNode() function, which is run on the render
thread detected a geometry change and initiated recalculation
of the chart layout.
This means that plotAreaChanged() was called in two different
thread contexts, which is questionable. Instead, hook into
the geometryChanged() function and recalculate the chart items
there.
This fixes a rendering bug, because the old code would first
delete unneeded items and then rerender the chart. Thus, old
grid and tick items were still visible.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'stats')
-rw-r--r-- | stats/statsview.cpp | 21 | ||||
-rw-r--r-- | stats/statsview.h | 4 |
2 files changed, 17 insertions, 8 deletions
diff --git a/stats/statsview.cpp b/stats/statsview.cpp index 6560360cc..eb51810f8 100644 --- a/stats/statsview.cpp +++ b/stats/statsview.cpp @@ -31,6 +31,7 @@ static const double sceneBorder = 5.0; // Border between scene edges and stati static const double titleBorder = 2.0; // Border between title and chart StatsView::StatsView(QQuickItem *parent) : QQuickItem(parent), + backgroundDirty(true), highlightedSeries(nullptr), xAxis(nullptr), yAxis(nullptr), @@ -125,11 +126,9 @@ QSGNode *StatsView::updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNod } deletedItems.clear(); - QRectF rect = boundingRect(); - if (plotRect != rect) { - plotRect = rect; - rootNode->backgroundNode->setRect(rect); - plotAreaChanged(plotRect.size()); + if (backgroundDirty) { + rootNode->backgroundNode->setRect(plotRect); + backgroundDirty = false; } for (ChartItem *item = dirtyItems.first; item; item = item->next) { @@ -232,6 +231,16 @@ QRectF StatsView::plotArea() const return plotRect; } +void StatsView::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) +{ + plotRect = QRectF(QPointF(0.0, 0.0), newGeometry.size()); + backgroundDirty = true; + plotAreaChanged(plotRect.size()); + + // Do we need to call the base-class' version of geometryChanged? Probably for QML? + QQuickItem::geometryChanged(newGeometry, oldGeometry); +} + void StatsView::plotAreaChanged(const QSizeF &s) { double left = sceneBorder; @@ -393,7 +402,7 @@ void StatsView::plot(const StatsState &stateIn) state = stateIn; plotChart(); updateFeatures(); // Show / hide chart features, such as legend, etc. - plotAreaChanged(boundingRect().size()); + plotAreaChanged(plotRect.size()); update(); } diff --git a/stats/statsview.h b/stats/statsview.h index 0af91b382..3623c01eb 100644 --- a/stats/statsview.h +++ b/stats/statsview.h @@ -64,12 +64,12 @@ public: private slots: void replotIfVisible(); private: - bool resetChart; - // QtQuick related things + bool backgroundDirty; QRectF plotRect; QSGNode *updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *updatePaintNodeData) override; + void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override; void plotAreaChanged(const QSizeF &size); void reset(); // clears all series and axes void setAxes(StatsAxis *x, StatsAxis *y); |