1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QQUICKWORKERSCRIPT_P_H
5#define QQUICKWORKERSCRIPT_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <qqml.h>
19
20#include <QtQmlWorkerScript/private/qtqmlworkerscriptglobal_p.h>
21#include <QtQml/qqmlparserstatus.h>
22#include <QtCore/qthread.h>
23#include <QtQml/qjsvalue.h>
24#include <QtCore/qurl.h>
25
26QT_BEGIN_NAMESPACE
27
28
29class QQuickWorkerScript;
30class QQuickWorkerScriptEnginePrivate;
31class QQuickWorkerScriptEngine : public QThread
32{
33Q_OBJECT
34public:
35 QQuickWorkerScriptEngine(QQmlEngine *parent = nullptr);
36 ~QQuickWorkerScriptEngine();
37
38 int registerWorkerScript(QQuickWorkerScript *);
39 void removeWorkerScript(int);
40 void executeUrl(int, const QUrl &);
41 void sendMessage(int, const QByteArray &);
42
43protected:
44 void run() override;
45
46private:
47 QQuickWorkerScriptEnginePrivate *d;
48};
49
50class QQmlV4Function;
51class Q_QMLWORKERSCRIPT_PRIVATE_EXPORT QQuickWorkerScript : public QObject, public QQmlParserStatus
52{
53 Q_OBJECT
54 Q_DISABLE_COPY_MOVE(QQuickWorkerScript)
55 Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
56 Q_PROPERTY(bool ready READ ready NOTIFY readyChanged REVISION(2, 15))
57
58 QML_NAMED_ELEMENT(WorkerScript);
59 QML_ADDED_IN_VERSION(2, 0)
60
61 Q_INTERFACES(QQmlParserStatus)
62public:
63 QQuickWorkerScript(QObject *parent = nullptr);
64 ~QQuickWorkerScript();
65
66 QUrl source() const;
67 void setSource(const QUrl &);
68
69 bool ready() const;
70
71public Q_SLOTS:
72 void sendMessage(QQmlV4Function*);
73
74Q_SIGNALS:
75 void sourceChanged();
76 Q_REVISION(2, 15) void readyChanged();
77 void message(const QJSValue &messageObject);
78
79protected:
80 void classBegin() override;
81 void componentComplete() override;
82 bool event(QEvent *) override;
83
84private:
85 QQuickWorkerScriptEngine *engine();
86 QQuickWorkerScriptEngine *m_engine;
87 int m_scriptId;
88 QUrl m_source;
89 bool m_componentComplete;
90};
91
92QT_END_NAMESPACE
93
94QML_DECLARE_TYPE(QQuickWorkerScript)
95
96#endif // QQUICKWORKERSCRIPT_P_H
97

source code of qtdeclarative/src/qmlworkerscript/qquickworkerscript_p.h