From e7907c494f7f78831c2e2d523f7eb43e25ee77c0 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Thu, 7 Jan 2021 14:38:37 +0100 Subject: 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 --- stats/barseries.cpp | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'stats/barseries.cpp') diff --git a/stats/barseries.cpp b/stats/barseries.cpp index 5727745a0..986aa7e0d 100644 --- a/stats/barseries.cpp +++ b/stats/barseries.cpp @@ -2,6 +2,7 @@ #include "barseries.h" #include "informationbox.h" #include "statscolors.h" +#include "statshelper.h" #include "statstranslations.h" #include "zvalues.h" @@ -27,19 +28,19 @@ bool BarSeries::Index::operator==(const Index &i2) const return std::tie(bar, subitem) == std::tie(i2.bar, i2.subitem); } -BarSeries::BarSeries(QtCharts::QChart *chart, StatsAxis *xAxis, StatsAxis *yAxis, +BarSeries::BarSeries(QGraphicsScene *scene, StatsAxis *xAxis, StatsAxis *yAxis, bool horizontal, bool stacked, const QString &categoryName, const StatsVariable *valueVariable, std::vector valueBinNames) : - StatsSeries(chart, xAxis, yAxis), + StatsSeries(scene, xAxis, yAxis), horizontal(horizontal), stacked(stacked), categoryName(categoryName), valueVariable(valueVariable), valueBinNames(std::move(valueBinNames)) { } -BarSeries::BarSeries(QtCharts::QChart *chart, StatsAxis *xAxis, StatsAxis *yAxis, +BarSeries::BarSeries(QGraphicsScene *scene, StatsAxis *xAxis, StatsAxis *yAxis, bool horizontal, const QString &categoryName, const std::vector &items) : - BarSeries(chart, xAxis, yAxis, horizontal, false, categoryName, nullptr, std::vector()) + BarSeries(scene, xAxis, yAxis, horizontal, false, categoryName, nullptr, std::vector()) { for (const CountItem &item: items) { StatsOperationResults res; @@ -50,10 +51,10 @@ BarSeries::BarSeries(QtCharts::QChart *chart, StatsAxis *xAxis, StatsAxis *yAxis } } -BarSeries::BarSeries(QtCharts::QChart *chart, StatsAxis *xAxis, StatsAxis *yAxis, +BarSeries::BarSeries(QGraphicsScene *scene, StatsAxis *xAxis, StatsAxis *yAxis, bool horizontal, const QString &categoryName, const StatsVariable *valueVariable, const std::vector &items) : - BarSeries(chart, xAxis, yAxis, horizontal, false, categoryName, valueVariable, std::vector()) + BarSeries(scene, xAxis, yAxis, horizontal, false, categoryName, valueVariable, std::vector()) { for (const ValueItem &item: items) { add_item(item.lowerBound, item.upperBound, makeSubItems(item.value, item.label), @@ -61,11 +62,11 @@ BarSeries::BarSeries(QtCharts::QChart *chart, StatsAxis *xAxis, StatsAxis *yAxis } } -BarSeries::BarSeries(QtCharts::QChart *chart, StatsAxis *xAxis, StatsAxis *yAxis, +BarSeries::BarSeries(QGraphicsScene *scene, StatsAxis *xAxis, StatsAxis *yAxis, bool horizontal, bool stacked, const QString &categoryName, const StatsVariable *valueVariable, std::vector valueBinNames, const std::vector &items) : - BarSeries(chart, xAxis, yAxis, horizontal, stacked, categoryName, valueVariable, std::move(valueBinNames)) + BarSeries(scene, xAxis, yAxis, horizontal, stacked, categoryName, valueVariable, std::move(valueBinNames)) { for (const MultiItem &item: items) { StatsOperationResults res; @@ -85,12 +86,12 @@ BarSeries::~BarSeries() { } -BarSeries::BarLabel::BarLabel(QtCharts::QChart *chart, const std::vector &labels, int bin_nr, int binCount) : +BarSeries::BarLabel::BarLabel(QGraphicsScene *scene, const std::vector &labels, int bin_nr, int binCount) : totalWidth(0.0), totalHeight(0.0), isOutside(false) { items.reserve(labels.size()); for (const QString &label: labels) { - items.emplace_back(new QGraphicsSimpleTextItem(chart)); + items.emplace_back(createItem(scene)); items.back()->setText(label); items.back()->setZValue(ZValues::seriesLabels); QRectF rect = items.back()->boundingRect(); @@ -175,7 +176,7 @@ void BarSeries::BarLabel::updatePosition(bool horizontal, bool center, const QRe highlight(false, bin_nr, binCount); } -BarSeries::Item::Item(QtCharts::QChart *chart, BarSeries *series, double lowerBound, double upperBound, +BarSeries::Item::Item(QGraphicsScene *scene, BarSeries *series, double lowerBound, double upperBound, std::vector subitemsIn, const QString &binName, const StatsOperationResults &res, int total, bool horizontal, bool stacked, int binCount) : @@ -264,9 +265,9 @@ std::vector BarSeries::makeSubItems(const std::vector 0.0) { - res.push_back({ std::make_unique(chart), {}, from, from + v, bin_nr }); + res.push_back({ createItemPtr(scene), {}, from, from + v, bin_nr }); if (!label.empty()) - res.back().label = std::make_unique(chart, label, bin_nr, binCount()); + res.back().label = std::make_unique(scene, label, bin_nr, binCount()); } if (stacked) from += v; @@ -292,7 +293,7 @@ void BarSeries::add_item(double lowerBound, double upperBound, std::vector(scene); information->setText(makeInfo(item, highlighted.subitem), pos); } else { information.reset(); -- cgit v1.2.3-70-g09d2