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 --- desktop-widgets/qml/statsview2.qml | 6 ++++++ desktop-widgets/qml/statsview2.qrc | 5 +++++ desktop-widgets/statswidget.cpp | 17 +++++++++++++---- desktop-widgets/statswidget.h | 2 ++ desktop-widgets/statswidget.ui | 10 +--------- 5 files changed, 27 insertions(+), 13 deletions(-) create mode 100644 desktop-widgets/qml/statsview2.qml create mode 100644 desktop-widgets/qml/statsview2.qrc (limited to 'desktop-widgets') diff --git a/desktop-widgets/qml/statsview2.qml b/desktop-widgets/qml/statsview2.qml new file mode 100644 index 000000000..ccad7fd1e --- /dev/null +++ b/desktop-widgets/qml/statsview2.qml @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: GPL-2.0 +import QtQuick 2.0 +import org.subsurfacedivelog.mobile 1.0 + +StatsView { +} diff --git a/desktop-widgets/qml/statsview2.qrc b/desktop-widgets/qml/statsview2.qrc new file mode 100644 index 000000000..d54f6c6b9 --- /dev/null +++ b/desktop-widgets/qml/statsview2.qrc @@ -0,0 +1,5 @@ + + + statsview2.qml + + diff --git a/desktop-widgets/statswidget.cpp b/desktop-widgets/statswidget.cpp index 01fd16eb1..e0090395f 100644 --- a/desktop-widgets/statswidget.cpp +++ b/desktop-widgets/statswidget.cpp @@ -70,6 +70,7 @@ QSize ChartItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QMod return size; } +static const QUrl urlStatsView = QUrl(QStringLiteral("qrc:/qml/statsview2.qml")); StatsWidget::StatsWidget(QWidget *parent) : QWidget(parent) { ui.setupUi(this); @@ -83,6 +84,13 @@ StatsWidget::StatsWidget(QWidget *parent) : QWidget(parent) connect(ui.var1Binner, QOverload::of(&QComboBox::activated), this, &StatsWidget::var1BinnerChanged); connect(ui.var2Binner, QOverload::of(&QComboBox::activated), this, &StatsWidget::var2BinnerChanged); connect(ui.var2Operation, QOverload::of(&QComboBox::activated), this, &StatsWidget::var2OperationChanged); + + ui.stats->setSource(urlStatsView); + ui.stats->setResizeMode(QQuickWidget::SizeRootObjectToView); + QQuickItem *root = ui.stats->rootObject(); + view = qobject_cast(root); + if (!view) + qWarning("Oops. The root of the StatsView is not a StatsView."); } // Initialize QComboBox with list of variables @@ -96,7 +104,7 @@ static void setVariableList(QComboBox *combo, const StatsState::VariableList &li } // Initialize QComboBox and QLabel of binners. Hide if there are no binners. -static void setBinList(QLabel *label, QComboBox *combo, const StatsState::BinnerList &list) +static void setBinList(QComboBox *combo, const StatsState::BinnerList &list) { combo->clear(); combo->setEnabled(!list.binners.empty()); @@ -114,8 +122,8 @@ void StatsWidget::updateUi() int pos = charts.update(uiState.charts); ui.chartType->setCurrentIndex(pos); ui.chartType->setItemDelegate(new ChartItemDelegate); - setBinList(ui.var1BinnerLabel, ui.var1Binner, uiState.binners1); - setBinList(ui.var2BinnerLabel, ui.var2Binner, uiState.binners2); + setBinList(ui.var1Binner, uiState.binners1); + setBinList(ui.var2Binner, uiState.binners2); setVariableList(ui.var2Operation, uiState.operations2); // Add checkboxes for additional features @@ -129,7 +137,8 @@ void StatsWidget::updateUi() ui.features->addWidget(check); } - ui.stats->plot(state); + if (view) + view->plot(state); } void StatsWidget::closeStats() diff --git a/desktop-widgets/statswidget.h b/desktop-widgets/statswidget.h index 40e6d106c..b85d89730 100644 --- a/desktop-widgets/statswidget.h +++ b/desktop-widgets/statswidget.h @@ -9,6 +9,7 @@ #include class QCheckBox; +class StatsView; class StatsWidget : public QWidget { Q_OBJECT @@ -27,6 +28,7 @@ slots: private: Ui::StatsWidget ui; StatsState state; + StatsView *view; void updateUi(); std::vector> features; diff --git a/desktop-widgets/statswidget.ui b/desktop-widgets/statswidget.ui index 684b0fa58..a20fb4a8f 100644 --- a/desktop-widgets/statswidget.ui +++ b/desktop-widgets/statswidget.ui @@ -105,7 +105,7 @@ - + 0 @@ -116,14 +116,6 @@ - - - StatsView - QQuickWidget -
stats/statsview.h
- 1 -
-
-- cgit v1.2.3-70-g09d2