aboutsummaryrefslogtreecommitdiffstats
path: root/tests/manual/threading/workerscript
diff options
context:
space:
mode:
Diffstat (limited to 'tests/manual/threading/workerscript')
-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
7 files changed, 204 insertions, 0 deletions
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>