diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2021-01-07 14:38:37 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2021-01-10 15:16:52 -0800 |
commit | e7907c494f7f78831c2e2d523f7eb43e25ee77c0 (patch) | |
tree | cbd169e1b2160569364a62b755ba082d7485af23 /desktop-widgets | |
parent | f6b857b8fe787b1d76d20ecc9407994da1139354 (diff) | |
download | subsurface-e7907c494f7f78831c2e2d523f7eb43e25ee77c0.tar.gz |
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>
Diffstat (limited to 'desktop-widgets')
-rw-r--r-- | desktop-widgets/qml/statsview2.qml | 6 | ||||
-rw-r--r-- | desktop-widgets/qml/statsview2.qrc | 5 | ||||
-rw-r--r-- | desktop-widgets/statswidget.cpp | 17 | ||||
-rw-r--r-- | desktop-widgets/statswidget.h | 2 | ||||
-rw-r--r-- | desktop-widgets/statswidget.ui | 10 |
5 files changed, 27 insertions, 13 deletions
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 @@ +<RCC> + <qresource prefix="/qml"> + <file>statsview2.qml</file> + </qresource> +</RCC> 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<int>::of(&QComboBox::activated), this, &StatsWidget::var1BinnerChanged); connect(ui.var2Binner, QOverload<int>::of(&QComboBox::activated), this, &StatsWidget::var2BinnerChanged); connect(ui.var2Operation, QOverload<int>::of(&QComboBox::activated), this, &StatsWidget::var2OperationChanged); + + ui.stats->setSource(urlStatsView); + ui.stats->setResizeMode(QQuickWidget::SizeRootObjectToView); + QQuickItem *root = ui.stats->rootObject(); + view = qobject_cast<StatsView *>(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 <memory> 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<std::unique_ptr<QCheckBox>> 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 @@ </layout> </item> <item> - <widget class="StatsView" name="stats"> + <widget class="QQuickWidget" name="stats"> <property name="sizePolicy"> <sizepolicy hsizetype="Expanding" vsizetype="Expanding"> <horstretch>0</horstretch> @@ -116,14 +116,6 @@ </item> </layout> </widget> - <customwidgets> - <customwidget> - <class>StatsView</class> - <extends>QQuickWidget</extends> - <header>stats/statsview.h</header> - <container>1</container> - </customwidget> - </customwidgets> <resources> <include location="../subsurface.qrc"/> </resources> |