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 QQUICKLISTMODELWORKERAGENT_P_H |
5 | #define QQUICKLISTMODELWORKERAGENT_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 <qtqmlmodelsglobal_p.h> |
19 | |
20 | #include <QEvent> |
21 | #include <QMutex> |
22 | #include <QWaitCondition> |
23 | #include <QtQml/qqml.h> |
24 | |
25 | #include <private/qv4engine_p.h> |
26 | |
27 | QT_REQUIRE_CONFIG(qml_list_model); |
28 | |
29 | QT_BEGIN_NAMESPACE |
30 | |
31 | |
32 | class QQmlListModel; |
33 | |
34 | class QQmlListModelWorkerAgent : public QObject |
35 | { |
36 | Q_OBJECT |
37 | Q_PROPERTY(int count READ count FINAL) |
38 | Q_PROPERTY(QV4::ExecutionEngine *engine READ engine WRITE setEngine NOTIFY engineChanged FINAL) |
39 | QML_ANONYMOUS |
40 | QML_ADDED_IN_VERSION(2, 0) |
41 | |
42 | public: |
43 | QQmlListModelWorkerAgent(QQmlListModel *); |
44 | ~QQmlListModelWorkerAgent(); |
45 | |
46 | QV4::ExecutionEngine *engine() const; |
47 | void setEngine(QV4::ExecutionEngine *eng); |
48 | |
49 | Q_INVOKABLE void addref(); |
50 | Q_INVOKABLE void release(); |
51 | |
52 | int count() const; |
53 | |
54 | Q_INVOKABLE void clear(); |
55 | Q_INVOKABLE void remove(QQmlV4Function *args); |
56 | Q_INVOKABLE void append(QQmlV4Function *args); |
57 | Q_INVOKABLE void insert(QQmlV4Function *args); |
58 | Q_INVOKABLE QJSValue get(int index) const; |
59 | Q_INVOKABLE void set(int index, const QJSValue &value); |
60 | Q_INVOKABLE void setProperty(int index, const QString& property, const QVariant& value); |
61 | Q_INVOKABLE void move(int from, int to, int count); |
62 | Q_INVOKABLE void sync(); |
63 | |
64 | void modelDestroyed(); |
65 | |
66 | Q_SIGNALS: |
67 | void engineChanged(QV4::ExecutionEngine *engine); |
68 | |
69 | protected: |
70 | bool event(QEvent *) override; |
71 | |
72 | private: |
73 | friend class QQuickWorkerScriptEnginePrivate; |
74 | friend class QQmlListModel; |
75 | |
76 | struct Sync : public QEvent { |
77 | Sync(QQmlListModel *l) |
78 | : QEvent(QEvent::User) |
79 | , list(l) |
80 | {} |
81 | ~Sync(); |
82 | QQmlListModel *list; |
83 | }; |
84 | |
85 | QAtomicInt m_ref; |
86 | QQmlListModel *m_orig; |
87 | QQmlListModel *m_copy; |
88 | QMutex mutex; |
89 | QWaitCondition syncDone; |
90 | }; |
91 | |
92 | QT_END_NAMESPACE |
93 | |
94 | #endif // QQUICKLISTMODELWORKERAGENT_P_H |
95 | |
96 |