2022-05-13 13:12:05 +00:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
#ifndef QQUICKWORKERSCRIPT_P_H
|
|
|
|
#define QQUICKWORKERSCRIPT_P_H
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// W A R N I N G
|
|
|
|
// -------------
|
|
|
|
//
|
|
|
|
// This file is not part of the Qt API. It exists purely as an
|
|
|
|
// implementation detail. This header file may change from version to
|
|
|
|
// version without notice, or even be removed.
|
|
|
|
//
|
|
|
|
// We mean it.
|
|
|
|
//
|
|
|
|
|
2017-10-23 12:49:22 +00:00
|
|
|
#include <qqml.h>
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2020-01-30 09:48:21 +00:00
|
|
|
#include <QtQmlWorkerScript/private/qtqmlworkerscriptglobal_p.h>
|
2013-01-23 23:17:27 +00:00
|
|
|
#include <QtQml/qqmlparserstatus.h>
|
2011-04-27 10:05:43 +00:00
|
|
|
#include <QtCore/qthread.h>
|
2012-02-16 04:43:03 +00:00
|
|
|
#include <QtQml/qjsvalue.h>
|
2011-04-27 10:05:43 +00:00
|
|
|
#include <QtCore/qurl.h>
|
|
|
|
|
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
class QQuickWorkerScript;
|
|
|
|
class QQuickWorkerScriptEnginePrivate;
|
|
|
|
class QQuickWorkerScriptEngine : public QThread
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2018-02-21 09:41:54 +00:00
|
|
|
QQuickWorkerScriptEngine(QQmlEngine *parent = nullptr);
|
2016-09-19 09:05:31 +00:00
|
|
|
~QQuickWorkerScriptEngine();
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
int registerWorkerScript(QQuickWorkerScript *);
|
2011-04-27 10:05:43 +00:00
|
|
|
void removeWorkerScript(int);
|
|
|
|
void executeUrl(int, const QUrl &);
|
2011-05-11 07:20:40 +00:00
|
|
|
void sendMessage(int, const QByteArray &);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
protected:
|
2016-09-19 09:05:31 +00:00
|
|
|
void run() override;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
private:
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickWorkerScriptEnginePrivate *d;
|
2011-04-27 10:05:43 +00:00
|
|
|
};
|
|
|
|
|
2013-05-08 14:22:39 +00:00
|
|
|
class QQmlV4Function;
|
2021-07-12 12:49:10 +00:00
|
|
|
class Q_QMLWORKERSCRIPT_PRIVATE_EXPORT QQuickWorkerScript : public QObject, public QQmlParserStatus
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
2021-07-14 07:35:37 +00:00
|
|
|
Q_DISABLE_COPY_MOVE(QQuickWorkerScript)
|
2011-04-27 10:05:43 +00:00
|
|
|
Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
|
2020-03-09 00:00:06 +00:00
|
|
|
Q_PROPERTY(bool ready READ ready NOTIFY readyChanged REVISION(2, 15))
|
2019-12-06 09:56:22 +00:00
|
|
|
|
2019-08-21 16:34:21 +00:00
|
|
|
QML_NAMED_ELEMENT(WorkerScript);
|
2020-01-16 12:42:11 +00:00
|
|
|
QML_ADDED_IN_VERSION(2, 0)
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_INTERFACES(QQmlParserStatus)
|
2011-04-27 10:05:43 +00:00
|
|
|
public:
|
2018-02-21 09:41:54 +00:00
|
|
|
QQuickWorkerScript(QObject *parent = nullptr);
|
2016-09-19 09:05:31 +00:00
|
|
|
~QQuickWorkerScript();
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QUrl source() const;
|
|
|
|
void setSource(const QUrl &);
|
|
|
|
|
2019-12-06 09:56:22 +00:00
|
|
|
bool ready() const;
|
|
|
|
|
2013-09-09 13:55:04 +00:00
|
|
|
public Q_SLOTS:
|
2013-05-08 14:22:39 +00:00
|
|
|
void sendMessage(QQmlV4Function*);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2013-09-09 13:55:04 +00:00
|
|
|
Q_SIGNALS:
|
2011-04-27 10:05:43 +00:00
|
|
|
void sourceChanged();
|
2020-03-09 00:00:06 +00:00
|
|
|
Q_REVISION(2, 15) void readyChanged();
|
2019-04-04 14:00:36 +00:00
|
|
|
void message(const QJSValue &messageObject);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
protected:
|
2016-09-19 09:05:31 +00:00
|
|
|
void classBegin() override;
|
|
|
|
void componentComplete() override;
|
|
|
|
bool event(QEvent *) override;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
private:
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickWorkerScriptEngine *engine();
|
|
|
|
QQuickWorkerScriptEngine *m_engine;
|
2011-04-27 10:05:43 +00:00
|
|
|
int m_scriptId;
|
|
|
|
QUrl m_source;
|
|
|
|
bool m_componentComplete;
|
|
|
|
};
|
|
|
|
|
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
#endif // QQUICKWORKERSCRIPT_P_H
|