mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
statistics: remove QSceneGraph
All items are now painted with QSG. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
51f67c6350
commit
9d3de1801e
3 changed files with 10 additions and 52 deletions
|
@ -1,29 +1,12 @@
|
|||
// SPDX-License-Identifier: GPL-2.0
|
||||
// Helper functions to render the stats. Currently only
|
||||
// contains a small template to create scene-items. This
|
||||
// is for historical reasons to ease transition from QtCharts
|
||||
// and might be removed.
|
||||
// Helper functions to render the stats. Currently contains
|
||||
// QSGNode template jugglery to overcome API flaws.
|
||||
#ifndef STATSHELPER_H
|
||||
#define STATSHELPER_H
|
||||
|
||||
#include <memory>
|
||||
#include <QGraphicsScene>
|
||||
#include <QSGNode>
|
||||
|
||||
template <typename T, class... Args>
|
||||
T *createItem(QGraphicsScene *scene, Args&&... args)
|
||||
{
|
||||
T *res = new T(std::forward<Args>(args)...);
|
||||
scene->addItem(res);
|
||||
return res;
|
||||
}
|
||||
|
||||
template <typename T, class... Args>
|
||||
std::unique_ptr<T> createItemPtr(QGraphicsScene *scene, Args&&... args)
|
||||
{
|
||||
return std::unique_ptr<T>(createItem<T>(scene, std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
// In general, we want chart items to be hideable. For example to show/hide
|
||||
// labels on demand. Very sadly, the QSG API is absolutely terrible with
|
||||
// respect to temporarily disabling. Instead of simply having a flag,
|
||||
|
|
|
@ -20,8 +20,6 @@
|
|||
#include "core/subsurface-qt/divelistnotifier.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <QGraphicsScene>
|
||||
#include <QGraphicsSimpleTextItem>
|
||||
#include <QQuickItem>
|
||||
#include <QQuickWindow>
|
||||
#include <QSGImageNode>
|
||||
|
@ -88,10 +86,9 @@ class RootNode : public QSGNode
|
|||
{
|
||||
public:
|
||||
RootNode(QQuickWindow *w);
|
||||
QSGRectangleNode *backgroundNode; // solid background
|
||||
QSGImageNode *imageNode; // imageNode to plot QGRaphicsScene on. Remove in due course.
|
||||
std::unique_ptr<QSGRectangleNode> backgroundNode; // solid background
|
||||
// We entertain one node per Z-level.
|
||||
std::array<QSGNode *, (size_t)ChartZValue::Count> zNodes;
|
||||
std::array<std::unique_ptr<QSGNode>, (size_t)ChartZValue::Count> zNodes;
|
||||
};
|
||||
|
||||
RootNode::RootNode(QQuickWindow *w)
|
||||
|
@ -99,16 +96,14 @@ RootNode::RootNode(QQuickWindow *w)
|
|||
// Add a background rectangle with a solid color. This could
|
||||
// also be done on the widget level, but would have to be done
|
||||
// separately for desktop and mobile, so do it here.
|
||||
backgroundNode = w->createRectangleNode();
|
||||
backgroundNode.reset(w->createRectangleNode());
|
||||
backgroundNode->setColor(backgroundColor);
|
||||
appendChildNode(backgroundNode);
|
||||
appendChildNode(backgroundNode.get());
|
||||
|
||||
for (QSGNode *&zNode: zNodes) {
|
||||
zNode = new QSGNode;
|
||||
appendChildNode(zNode);
|
||||
for (auto &zNode: zNodes) {
|
||||
zNode.reset(new QSGNode);
|
||||
appendChildNode(zNode.get());
|
||||
}
|
||||
imageNode = w->createImageNode();
|
||||
zNodes[(int)ChartZValue::Series]->appendChildNode(imageNode);
|
||||
}
|
||||
|
||||
QSGNode *StatsView::updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *)
|
||||
|
@ -133,11 +128,6 @@ QSGNode *StatsView::updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNod
|
|||
item->dirtyPrev = nullptr;
|
||||
}
|
||||
|
||||
img->fill(Qt::transparent);
|
||||
scene.render(painter.get());
|
||||
texture.reset(window()->createTextureFromImage(*img, QQuickWindow::TextureHasAlphaChannel));
|
||||
n->imageNode->setTexture(texture.get());
|
||||
n->imageNode->setRect(rect);
|
||||
return n;
|
||||
}
|
||||
|
||||
|
@ -194,16 +184,6 @@ QRectF StatsView::plotArea() const
|
|||
|
||||
void StatsView::plotAreaChanged(const QSizeF &s)
|
||||
{
|
||||
// Make sure that image is at least one pixel wide / high, otherwise
|
||||
// the painter starts acting up.
|
||||
int w = std::max(1, static_cast<int>(floor(s.width())));
|
||||
int h = std::max(1, static_cast<int>(floor(s.height())));
|
||||
scene.setSceneRect(QRectF(0, 0, static_cast<double>(w), static_cast<double>(h)));
|
||||
painter.reset();
|
||||
img.reset(new QImage(w, h, QImage::Format_ARGB32));
|
||||
painter.reset(new QPainter(img.get()));
|
||||
painter->setRenderHint(QPainter::Antialiasing);
|
||||
|
||||
double left = sceneBorder;
|
||||
double top = sceneBorder;
|
||||
double right = s.width() - sceneBorder;
|
||||
|
@ -363,7 +343,7 @@ void StatsView::plot(const StatsState &stateIn)
|
|||
{
|
||||
state = stateIn;
|
||||
plotChart();
|
||||
plotAreaChanged(scene.sceneRect().size());
|
||||
plotAreaChanged(boundingRect().size());
|
||||
update();
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
#include "statsstate.h"
|
||||
#include <memory>
|
||||
#include <QFont>
|
||||
#include <QGraphicsScene>
|
||||
#include <QImage>
|
||||
#include <QPainter>
|
||||
#include <QQuickItem>
|
||||
|
@ -58,10 +57,6 @@ private:
|
|||
// QtQuick related things
|
||||
QRectF plotRect;
|
||||
QSGNode *updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *updatePaintNodeData) override;
|
||||
std::unique_ptr<QImage> img;
|
||||
std::unique_ptr<QPainter> painter;
|
||||
QGraphicsScene scene;
|
||||
std::unique_ptr<QSGTexture> texture;
|
||||
|
||||
void plotAreaChanged(const QSizeF &size);
|
||||
void reset(); // clears all series and axes
|
||||
|
|
Loading…
Reference in a new issue