aboutsummaryrefslogtreecommitdiffstats
path: root/tests/manual/threading
diff options
context:
space:
mode:
Diffstat (limited to 'tests/manual/threading')
-rw-r--r--tests/manual/threading/CMakeLists.txt2
-rw-r--r--tests/manual/threading/threadedlistmodel/CMakeLists.txt33
-rw-r--r--tests/manual/threading/threadedlistmodel/dataloader.mjs12
-rw-r--r--tests/manual/threading/threadedlistmodel/threadedlistmodel.cpp19
-rw-r--r--tests/manual/threading/threadedlistmodel/threadedlistmodel.pro6
-rw-r--r--tests/manual/threading/threadedlistmodel/threadedlistmodel.qrc5
-rw-r--r--tests/manual/threading/threadedlistmodel/timedisplay.qml42
-rw-r--r--tests/manual/threading/workerscript/CMakeLists.txt34
-rw-r--r--tests/manual/threading/workerscript/Spinner.qml51
-rw-r--r--tests/manual/threading/workerscript/workerscript.cpp19
-rw-r--r--tests/manual/threading/workerscript/workerscript.mjs27
-rw-r--r--tests/manual/threading/workerscript/workerscript.pro6
-rw-r--r--tests/manual/threading/workerscript/workerscript.qml60
-rw-r--r--tests/manual/threading/workerscript/workerscript.qrc7
14 files changed, 323 insertions, 0 deletions
diff --git a/tests/manual/threading/CMakeLists.txt b/tests/manual/threading/CMakeLists.txt
new file mode 100644
index 0000000000..99ed5d9d6e
--- /dev/null
+++ b/tests/manual/threading/CMakeLists.txt
@@ -0,0 +1,2 @@
+add_subdirectory(threadedlistmodel)
+add_subdirectory(workerscript)
diff --git a/tests/manual/threading/threadedlistmodel/CMakeLists.txt b/tests/manual/threading/threadedlistmodel/CMakeLists.txt
new file mode 100644
index 0000000000..68fb5c511c
--- /dev/null
+++ b/tests/manual/threading/threadedlistmodel/CMakeLists.txt
@@ -0,0 +1,33 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+if (NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(threadedlistmodel LANGUAGES C CXX ASM)
+ find_package(Qt6BuildInternals COMPONENTS STANDALONE_TEST)
+endif()
+
+qt_internal_add_manual_test(tst_manual_threadedlistmodel
+ GUI
+ SOURCES
+ threadedlistmodel.cpp
+ DEFINES
+ QT_DEPRECATED_WARNINGS
+ LIBRARIES
+ Qt::Gui
+ Qt::Qml
+ Qt::Quick
+)
+
+# Resources:
+set(qmake_immediate_resource_files
+ timedisplay.qml
+ dataloader.mjs
+)
+
+qt_internal_add_resource(tst_manual_threadedlistmodel "qmake_immediate"
+ PREFIX
+ "/qt/qml/threadedlistmodel"
+ FILES
+ ${qmake_immediate_resource_files}
+)
diff --git a/tests/manual/threading/threadedlistmodel/dataloader.mjs b/tests/manual/threading/threadedlistmodel/dataloader.mjs
new file mode 100644
index 0000000000..2c436d34dc
--- /dev/null
+++ b/tests/manual/threading/threadedlistmodel/dataloader.mjs
@@ -0,0 +1,12 @@
+// Copyright (C) 2017 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+// ![0]
+WorkerScript.onMessage = function(msg) {
+ if (msg.action == 'appendCurrentTime') {
+ var data = {'time': new Date().toTimeString()};
+ msg.model.append(data);
+ msg.model.sync(); // updates the changes to the list
+ }
+}
+// ![0]
diff --git a/tests/manual/threading/threadedlistmodel/threadedlistmodel.cpp b/tests/manual/threading/threadedlistmodel/threadedlistmodel.cpp
new file mode 100644
index 0000000000..569e1d8418
--- /dev/null
+++ b/tests/manual/threading/threadedlistmodel/threadedlistmodel.cpp
@@ -0,0 +1,19 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#include <QtGui/qguiapplication.h>
+#include <QtQuick/QQuickView>
+
+int main(int argc, char *argv[])
+{
+ QGuiApplication app(argc, argv);
+
+ QCoreApplication::setApplicationName("threadedlistmodel-manual-test");
+ QCoreApplication::setOrganizationName("QtProject");
+
+ QQuickView view;
+ view.setSource(QUrl(QStringLiteral("qrc:/qt/qml/threadedlistmodel/timedisplay.qml")));
+ view.show();
+
+ return app.exec();
+}
diff --git a/tests/manual/threading/threadedlistmodel/threadedlistmodel.pro b/tests/manual/threading/threadedlistmodel/threadedlistmodel.pro
new file mode 100644
index 0000000000..b3849b3e1a
--- /dev/null
+++ b/tests/manual/threading/threadedlistmodel/threadedlistmodel.pro
@@ -0,0 +1,6 @@
+TEMPLATE = app
+TARGET = threadedlistmodel
+QT += qml quick
+
+SOURCES += threadedlistmodel.cpp
+RESOURCES += threadedlistmodel.qrc
diff --git a/tests/manual/threading/threadedlistmodel/threadedlistmodel.qrc b/tests/manual/threading/threadedlistmodel/threadedlistmodel.qrc
new file mode 100644
index 0000000000..dbc5bc312d
--- /dev/null
+++ b/tests/manual/threading/threadedlistmodel/threadedlistmodel.qrc
@@ -0,0 +1,5 @@
+<RCC>
+ <qresource prefix="/qt/qml/threadedlistmodel">
+ <file>timedisplay.qml</file>
+ </qresource>
+</RCC>
diff --git a/tests/manual/threading/threadedlistmodel/timedisplay.qml b/tests/manual/threading/threadedlistmodel/timedisplay.qml
new file mode 100644
index 0000000000..19bd694137
--- /dev/null
+++ b/tests/manual/threading/threadedlistmodel/timedisplay.qml
@@ -0,0 +1,42 @@
+// Copyright (C) 2017 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+import QtQuick
+
+Rectangle {
+ color: "white"
+ width: 200
+ height: 300
+
+ ListView {
+ anchors.fill: parent
+ model: listModel
+ delegate: Component {
+ Text {
+ required property string time
+ text: time
+ }
+ }
+
+ ListModel { id: listModel }
+
+ WorkerScript {
+ id: worker
+ source: "dataloader.mjs"
+ }
+
+// ![0]
+ Timer {
+ id: timer
+ interval: 2000; repeat: true
+ running: true
+ triggeredOnStart: true
+
+ onTriggered: {
+ var msg = {'action': 'appendCurrentTime', 'model': listModel};
+ worker.sendMessage(msg);
+ }
+ }
+// ![0]
+ }
+}
diff --git a/tests/manual/threading/workerscript/CMakeLists.txt b/tests/manual/threading/workerscript/CMakeLists.txt
new file mode 100644
index 0000000000..3f73985b33
--- /dev/null
+++ b/tests/manual/threading/workerscript/CMakeLists.txt
@@ -0,0 +1,34 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+if (NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(workerscript LANGUAGES C CXX ASM)
+ find_package(Qt6BuildInternals COMPONENTS STANDALONE_TEST)
+endif()
+
+qt_internal_add_manual_test(tst_manual_workerscript
+ GUI
+ SOURCES
+ workerscript.cpp
+ DEFINES
+ QT_DEPRECATED_WARNINGS
+ LIBRARIES
+ Qt::Gui
+ Qt::Qml
+ Qt::Quick
+)
+
+# Resources:
+set(qmake_immediate_resource_files
+ "Spinner.qml"
+ "workerscript.qml"
+ "workerscript.mjs"
+)
+
+qt_internal_add_resource(tst_manual_workerscript "qmake_immediate"
+ PREFIX
+ "/qt/qml/workerscript"
+ FILES
+ ${qmake_immediate_resource_files}
+)
diff --git a/tests/manual/threading/workerscript/Spinner.qml b/tests/manual/threading/workerscript/Spinner.qml
new file mode 100644
index 0000000000..0c894a2567
--- /dev/null
+++ b/tests/manual/threading/workerscript/Spinner.qml
@@ -0,0 +1,51 @@
+// Copyright (C) 2017 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+import QtQuick
+
+Rectangle {
+ width: 64
+ height: 64
+ property alias value: list.currentIndex
+ property alias label: caption.text
+
+ Text {
+ id: caption
+ text: "Spinner"
+ anchors.horizontalCenter: parent.horizontalCenter
+ }
+
+ Rectangle {
+ anchors.top: caption.bottom
+ anchors.topMargin: 4
+ anchors.horizontalCenter: parent.horizontalCenter
+ height: 48
+ width: 32
+ color: "black"
+ ListView {
+ id: list
+ anchors.fill: parent
+ highlightRangeMode: ListView.StrictlyEnforceRange
+ preferredHighlightBegin: height/3
+ preferredHighlightEnd: height/3
+ clip: true
+ model: 64
+ delegate: Text {
+ required property int index
+ font.pixelSize: 18;
+ color: "white";
+ text: index;
+ anchors.horizontalCenter: parent.horizontalCenter
+ }
+ }
+ Rectangle {
+ anchors.fill: parent
+ gradient: Gradient {
+ GradientStop { position: 0.0; color: "#FF000000" }
+ GradientStop { position: 0.2; color: "#00000000" }
+ GradientStop { position: 0.8; color: "#00000000" }
+ GradientStop { position: 1.0; color: "#FF000000" }
+ }
+ }
+ }
+}
diff --git a/tests/manual/threading/workerscript/workerscript.cpp b/tests/manual/threading/workerscript/workerscript.cpp
new file mode 100644
index 0000000000..9b28b7c350
--- /dev/null
+++ b/tests/manual/threading/workerscript/workerscript.cpp
@@ -0,0 +1,19 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#include <QtGui/qguiapplication.h>
+#include <QtQuick/QQuickView>
+
+int main(int argc, char *argv[])
+{
+ QGuiApplication app(argc, argv);
+
+ QCoreApplication::setApplicationName("workerscript-manual-test");
+ QCoreApplication::setOrganizationName("QtProject");
+
+ QQuickView view;
+ view.setSource(QUrl(QStringLiteral("qrc:/qt/qml/workerscript/workerscript.qml")));
+ view.show();
+
+ return app.exec();
+}
diff --git a/tests/manual/threading/workerscript/workerscript.mjs b/tests/manual/threading/workerscript/workerscript.mjs
new file mode 100644
index 0000000000..cecce85896
--- /dev/null
+++ b/tests/manual/threading/workerscript/workerscript.mjs
@@ -0,0 +1,27 @@
+// Copyright (C) 2017 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+//Will be initialized when WorkerScript{} is instantiated
+var cache = new Array(64);
+for (var i = 0; i < 64; i++)
+ cache[i] = new Array(64);
+
+function triangle(row, column) {
+ if (cache[row][column])
+ return cache[row][column]
+ if (column < 0 || column > row)
+ return -1;
+ if (column == 0 || column == row)
+ return 1;
+ return triangle(row-1, column-1) + triangle(row-1, column);
+}
+//! [0]
+WorkerScript.onMessage = function(message) {
+ //Calculate result (may take a while, using a naive algorithm)
+ var calculatedResult = triangle(message.row, message.column);
+ //Send result back to main thread
+ WorkerScript.sendMessage( { row: message.row,
+ column: message.column,
+ result: calculatedResult} );
+}
+//! [0]
diff --git a/tests/manual/threading/workerscript/workerscript.pro b/tests/manual/threading/workerscript/workerscript.pro
new file mode 100644
index 0000000000..33ec5bda14
--- /dev/null
+++ b/tests/manual/threading/workerscript/workerscript.pro
@@ -0,0 +1,6 @@
+TEMPLATE = app
+TARGET = workerscript
+QT += qml quick
+
+SOURCES += workerscript.cpp
+RESOURCES += workerscript.qrc
diff --git a/tests/manual/threading/workerscript/workerscript.qml b/tests/manual/threading/workerscript/workerscript.qml
new file mode 100644
index 0000000000..378b45bc82
--- /dev/null
+++ b/tests/manual/threading/workerscript/workerscript.qml
@@ -0,0 +1,60 @@
+// Copyright (C) 2017 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+import QtQuick
+
+Rectangle {
+ width: 320; height: 480
+
+ WorkerScript {
+ id: myWorker
+ source: "workerscript.mjs"
+
+ onMessage: (messageObject) => {
+ if (messageObject.row == rowSpinner.value && messageObject.column == columnSpinner.value){ //Not an old result
+ if (messageObject.result == -1)
+ resultText.text = "Column must be <= Row";
+ else
+ resultText.text = messageObject.result;
+ }
+ }
+ }
+
+ Row {
+ y: 24
+ spacing: 24
+ anchors.horizontalCenter: parent.horizontalCenter
+
+ Spinner {
+ id: rowSpinner
+ label: "Row"
+ onValueChanged: {
+ resultText.text = "Loading...";
+ myWorker.sendMessage( { row: rowSpinner.value, column: columnSpinner.value } );
+ }
+ }
+
+ Spinner {
+ id: columnSpinner
+ label: "Column"
+ onValueChanged: {
+ resultText.text = "Loading...";
+ myWorker.sendMessage( { row: rowSpinner.value, column: columnSpinner.value } );
+ }
+ }
+ }
+
+ Text {
+ id: resultText
+ y: 180
+ width: parent.width
+ horizontalAlignment: Text.AlignHCenter
+ wrapMode: Text.WordWrap
+ font.pixelSize: 32
+ }
+
+ Text {
+ text: "Pascal's Triangle Calculator"
+ anchors { horizontalCenter: parent.horizontalCenter; bottom: parent.bottom; bottomMargin: 50 }
+ }
+}
diff --git a/tests/manual/threading/workerscript/workerscript.qrc b/tests/manual/threading/workerscript/workerscript.qrc
new file mode 100644
index 0000000000..ca3833ff1c
--- /dev/null
+++ b/tests/manual/threading/workerscript/workerscript.qrc
@@ -0,0 +1,7 @@
+<RCC>
+ <qresource prefix="/qt/qml/workerscript">
+ <file>Spinner.qml</file>
+ <file>workerscript.mjs</file>
+ <file>workerscript.qml</file>
+ </qresource>
+</RCC>