diff options
author | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2019-12-12 01:00:07 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2019-12-12 10:06:06 +0100 |
commit | 1196b1ef6c5d2cb05ceba5d6f178dc7e2432ed61 (patch) | |
tree | 2a99ee28d15d8ee51fc28096e5559bfc2d453e3f /src/qmlworkerscript | |
parent | fb54af6638dcbeae8ad21249fe234ef4d82c005b (diff) | |
parent | ca206bceaff3667469986402e6143bf4c666b228 (diff) |
Merge remote-tracking branch 'origin/5.15' into dev
Conflicts:
src/qml/types/qqmlbind.cpp
Change-Id: Ib992d1a7ac6c1a96d39819be6f23955dc31b44b2
Diffstat (limited to 'src/qmlworkerscript')
5 files changed, 98 insertions, 4 deletions
diff --git a/src/qmlworkerscript/doc/qtqmlworkerscript.qdocconf b/src/qmlworkerscript/doc/qtqmlworkerscript.qdocconf index bb883cf39f..e56e1759b3 100644 --- a/src/qmlworkerscript/doc/qtqmlworkerscript.qdocconf +++ b/src/qmlworkerscript/doc/qtqmlworkerscript.qdocconf @@ -23,15 +23,13 @@ qhp.QtQmlWorkerScript.sortPages = true tagfile = qtqmlworkerscript.tags -depends += qtcore qtqml qtdoc +depends += qtcore qtqml qtquick qtdoc headerdirs += .. sourcedirs += .. \ ../../imports/workerscript -exampledirs += ../../../examples/qml \ - ../ \ - snippets +exampledirs += snippets navigation.qmltypespage = "Qt Qml WorkerScript QML Types" diff --git a/src/qmlworkerscript/doc/snippets/qml/workerscript/script.mjs b/src/qmlworkerscript/doc/snippets/qml/workerscript/script.mjs new file mode 100644 index 0000000000..f55dee3507 --- /dev/null +++ b/src/qmlworkerscript/doc/snippets/qml/workerscript/script.mjs @@ -0,0 +1,4 @@ +WorkerScript.onMessage = function(message) { + // ... long-running operations and calculations are done here + WorkerScript.sendMessage({ 'reply': 'Mouse is at ' + message.x + ',' + message.y }) +} diff --git a/src/qmlworkerscript/doc/snippets/qml/workerscript/workerscript.qml b/src/qmlworkerscript/doc/snippets/qml/workerscript/workerscript.qml new file mode 100644 index 0000000000..cc637d34cf --- /dev/null +++ b/src/qmlworkerscript/doc/snippets/qml/workerscript/workerscript.qml @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//![0] +import QtQuick 2.0 + +Rectangle { + width: 300; height: 300 + + Text { + id: myText + text: 'Click anywhere' + } + + WorkerScript { + id: myWorker + source: "script.mjs" + + onMessage: myText.text = messageObject.reply + } + + MouseArea { + anchors.fill: parent + onClicked: myWorker.sendMessage({ 'x': mouse.x, 'y': mouse.y }) + } +} +//![0] diff --git a/src/qmlworkerscript/qquickworkerscript.cpp b/src/qmlworkerscript/qquickworkerscript.cpp index 8b236697b9..9e4b3e1b46 100644 --- a/src/qmlworkerscript/qquickworkerscript.cpp +++ b/src/qmlworkerscript/qquickworkerscript.cpp @@ -533,6 +533,17 @@ void QQuickWorkerScript::setSource(const QUrl &source) } /*! + \qmlproperty url WorkerScript::ready + + This holds whether the WorkerScript has been initialized and is ready + for receiving messages via \tt WorkerScript.sendMessage(). +*/ +bool QQuickWorkerScript::ready() const +{ + return m_engine != nullptr; +} + +/*! \qmlmethod WorkerScript::sendMessage(jsobject message) Sends the given \a message to a worker script handler in another @@ -592,6 +603,8 @@ QQuickWorkerScriptEngine *QQuickWorkerScript::engine() if (m_source.isValid()) m_engine->executeUrl(m_scriptId, m_source); + emit readyChanged(); + return m_engine; } return nullptr; diff --git a/src/qmlworkerscript/qquickworkerscript_p.h b/src/qmlworkerscript/qquickworkerscript_p.h index 9b5d3587fb..d1f686a78d 100644 --- a/src/qmlworkerscript/qquickworkerscript_p.h +++ b/src/qmlworkerscript/qquickworkerscript_p.h @@ -87,6 +87,8 @@ class Q_AUTOTEST_EXPORT QQuickWorkerScript : public QObject, public QQmlParserSt { Q_OBJECT Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) + Q_PROPERTY(bool ready READ ready NOTIFY readyChanged) + QML_NAMED_ELEMENT(WorkerScript); Q_INTERFACES(QQmlParserStatus) @@ -97,11 +99,14 @@ public: QUrl source() const; void setSource(const QUrl &); + bool ready() const; + public Q_SLOTS: void sendMessage(QQmlV4Function*); Q_SIGNALS: void sourceChanged(); + void readyChanged(); void message(const QJSValue &messageObject); protected: |