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

@ -4,6 +4,7 @@
#include <QChart>
#include <QFontMetrics>
#include <QGraphicsScene>
static const QColor informationBorderColor(Qt::black);
static const QColor informationColor(0xff, 0xff, 0x00, 192); // Note: fourth argument is opacity
@ -11,7 +12,7 @@ static const int informationBorder = 2;
static const double informationBorderRadius = 4.0; // Radius of rounded corners
static const int distanceFromPointer = 10; // Distance to place box from mouse pointer or scatter item
InformationBox::InformationBox(QtCharts::QChart *chart) : RoundRectItem(informationBorderRadius, chart), chart(chart)
InformationBox::InformationBox() : RoundRectItem(informationBorderRadius, nullptr)
{
setPen(QPen(informationBorderColor, informationBorder));
setBrush(informationColor);
@ -37,7 +38,7 @@ void InformationBox::setText(const std::vector<QString> &text, QPointF pos)
void InformationBox::setPos(QPointF pos)
{
QRectF plotArea = chart->plotArea();
QRectF plotArea = scene()->sceneRect();
double x = pos.x() + distanceFromPointer;
if (x + width >= plotArea.right()) {
@ -79,6 +80,6 @@ void InformationBox::addLine(const QString &s)
int InformationBox::recommendedMaxLines() const
{
QFontMetrics fm(font);
int maxHeight = static_cast<int>(chart->plotArea().height());
int maxHeight = static_cast<int>(scene()->sceneRect().height());
return maxHeight * 2 / fm.height() / 3;
}