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
|
// SPDX-License-Identifier: GPL-2.0
|
||||||
// Helper functions to render the stats. Currently only
|
// Helper functions to render the stats. Currently contains
|
||||||
// contains a small template to create scene-items. This
|
// QSGNode template jugglery to overcome API flaws.
|
||||||
// is for historical reasons to ease transition from QtCharts
|
|
||||||
// and might be removed.
|
|
||||||
#ifndef STATSHELPER_H
|
#ifndef STATSHELPER_H
|
||||||
#define STATSHELPER_H
|
#define STATSHELPER_H
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <QGraphicsScene>
|
|
||||||
#include <QSGNode>
|
#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
|
// 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
|
// labels on demand. Very sadly, the QSG API is absolutely terrible with
|
||||||
// respect to temporarily disabling. Instead of simply having a flag,
|
// respect to temporarily disabling. Instead of simply having a flag,
|
||||||
|
|
|
@ -20,8 +20,6 @@
|
||||||
#include "core/subsurface-qt/divelistnotifier.h"
|
#include "core/subsurface-qt/divelistnotifier.h"
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <QGraphicsScene>
|
|
||||||
#include <QGraphicsSimpleTextItem>
|
|
||||||
#include <QQuickItem>
|
#include <QQuickItem>
|
||||||
#include <QQuickWindow>
|
#include <QQuickWindow>
|
||||||
#include <QSGImageNode>
|
#include <QSGImageNode>
|
||||||
|
@ -88,10 +86,9 @@ class RootNode : public QSGNode
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RootNode(QQuickWindow *w);
|
RootNode(QQuickWindow *w);
|
||||||
QSGRectangleNode *backgroundNode; // solid background
|
std::unique_ptr<QSGRectangleNode> backgroundNode; // solid background
|
||||||
QSGImageNode *imageNode; // imageNode to plot QGRaphicsScene on. Remove in due course.
|
|
||||||
// We entertain one node per Z-level.
|
// 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)
|
RootNode::RootNode(QQuickWindow *w)
|
||||||
|
@ -99,16 +96,14 @@ RootNode::RootNode(QQuickWindow *w)
|
||||||
// Add a background rectangle with a solid color. This could
|
// Add a background rectangle with a solid color. This could
|
||||||
// also be done on the widget level, but would have to be done
|
// also be done on the widget level, but would have to be done
|
||||||
// separately for desktop and mobile, so do it here.
|
// separately for desktop and mobile, so do it here.
|
||||||
backgroundNode = w->createRectangleNode();
|
backgroundNode.reset(w->createRectangleNode());
|
||||||
backgroundNode->setColor(backgroundColor);
|
backgroundNode->setColor(backgroundColor);
|
||||||
appendChildNode(backgroundNode);
|
appendChildNode(backgroundNode.get());
|
||||||
|
|
||||||
for (QSGNode *&zNode: zNodes) {
|
for (auto &zNode: zNodes) {
|
||||||
zNode = new QSGNode;
|
zNode.reset(new QSGNode);
|
||||||
appendChildNode(zNode);
|
appendChildNode(zNode.get());
|
||||||
}
|
}
|
||||||
imageNode = w->createImageNode();
|
|
||||||
zNodes[(int)ChartZValue::Series]->appendChildNode(imageNode);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QSGNode *StatsView::updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *)
|
QSGNode *StatsView::updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *)
|
||||||
|
@ -133,11 +128,6 @@ QSGNode *StatsView::updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNod
|
||||||
item->dirtyPrev = nullptr;
|
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;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,16 +184,6 @@ QRectF StatsView::plotArea() const
|
||||||
|
|
||||||
void StatsView::plotAreaChanged(const QSizeF &s)
|
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 left = sceneBorder;
|
||||||
double top = sceneBorder;
|
double top = sceneBorder;
|
||||||
double right = s.width() - sceneBorder;
|
double right = s.width() - sceneBorder;
|
||||||
|
@ -363,7 +343,7 @@ void StatsView::plot(const StatsState &stateIn)
|
||||||
{
|
{
|
||||||
state = stateIn;
|
state = stateIn;
|
||||||
plotChart();
|
plotChart();
|
||||||
plotAreaChanged(scene.sceneRect().size());
|
plotAreaChanged(boundingRect().size());
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
#include "statsstate.h"
|
#include "statsstate.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <QFont>
|
#include <QFont>
|
||||||
#include <QGraphicsScene>
|
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QQuickItem>
|
#include <QQuickItem>
|
||||||
|
@ -58,10 +57,6 @@ private:
|
||||||
// QtQuick related things
|
// QtQuick related things
|
||||||
QRectF plotRect;
|
QRectF plotRect;
|
||||||
QSGNode *updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *updatePaintNodeData) override;
|
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 plotAreaChanged(const QSizeF &size);
|
||||||
void reset(); // clears all series and axes
|
void reset(); // clears all series and axes
|
||||||
|
|
Loading…
Reference in a new issue