statistics: convert chart to QQuickItem

It turns out that the wrong base class was used for the chart.
QQuickWidget can only be used on desktop, not in a mobile UI.

Therefore, turn this into a QQuickItem and move the container
QQuickWidget into desktop-only code.

Currently, this code is insane: The chart is rendered onto a
QGraphicsScene (as it was before), which is then rendered into
a QImage, which is transformed into a QSGTexture, which is then
projected onto the device. This is performed on every mouse
move event, since these events in general change the position
of the info-box.

The plan is to slowly convert elements such as the info-box into
QQuickItems. Browsing the QtQuick documentation, this will
not be much fun.

Also note that the rendering currently tears, flickers and has
antialiasing artifacts, most likely owing to integer (QImage)
to floating point (QGraphicsScene, QQuickItem) conversion
problems. The data flow is
QGraphicsScene (float) -> QImage (int) -> QQuickItem (float).

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2021-01-07 14:38:37 +01:00 committed by Dirk Hohndel
parent f6b857b8fe
commit e7907c494f
32 changed files with 299 additions and 269 deletions

View file

@ -2,6 +2,7 @@
#include "statsgrid.h"
#include "statsaxis.h"
#include "statscolors.h"
#include "statshelper.h"
#include "zvalues.h"
#include <QChart>
@ -10,8 +11,8 @@
static const double gridWidth = 1.0;
static const Qt::PenStyle gridStyle = Qt::SolidLine;
StatsGrid::StatsGrid(QtCharts::QChart *chart, const StatsAxis &xAxis, const StatsAxis &yAxis)
: chart(chart), xAxis(xAxis), yAxis(yAxis)
StatsGrid::StatsGrid(QGraphicsScene *scene, const StatsAxis &xAxis, const StatsAxis &yAxis)
: scene(scene), xAxis(xAxis), yAxis(yAxis)
{
}
@ -24,12 +25,12 @@ void StatsGrid::updatePositions()
return;
for (double x: xtics) {
lines.emplace_back(new QGraphicsLineItem(x, ytics.front(), x, ytics.back(), chart));
lines.emplace_back(createItem<QGraphicsLineItem>(scene, x, ytics.front(), x, ytics.back()));
lines.back()->setPen(QPen(gridColor, gridWidth, gridStyle));
lines.back()->setZValue(ZValues::grid);
}
for (double y: ytics) {
lines.emplace_back(new QGraphicsLineItem(xtics.front(), y, xtics.back(), y, chart));
lines.emplace_back(createItem<QGraphicsLineItem>(scene, xtics.front(), y, xtics.back(), y));
lines.back()->setPen(QPen(gridColor, gridWidth, gridStyle));
lines.back()->setZValue(ZValues::grid);
}