Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qqmllistmodelworkeragent.cpp
Go to the documentation of this file.
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// Qt-Security score:significant
4
7#include <private/qqmldata_p.h>
8#include <private/qqmlengine_p.h>
9#include <qqmlinfo.h>
10
11#include <QtCore/qcoreevent.h>
12#include <QtCore/qcoreapplication.h>
13#include <QtCore/qdebug.h>
14
15
17
18QQmlListModelWorkerAgent::Sync::~Sync()
19{
20}
21
22QQmlListModelWorkerAgent::QQmlListModelWorkerAgent(QQmlListModel *model)
23: m_ref(1), m_orig(model), m_copy(new QQmlListModel(model, this))
24{
25}
26
28{
29 mutex.lock();
30 syncDone.wakeAll();
31 mutex.unlock();
32}
33
35{
36 return m_copy->m_engine;
37}
38
39void QQmlListModelWorkerAgent::setEngine(QV4::ExecutionEngine *eng)
40{
41 if (eng != m_copy->m_engine) {
42 m_copy->m_engine = eng;
43 emit engineChanged(eng);
44 }
45}
46
48{
49 m_ref.ref();
50}
51
53{
54 bool del = !m_ref.deref();
55
56 if (del)
57 deleteLater();
58}
59
61{
62 m_orig = nullptr;
63}
64
66{
67 return m_copy->count();
68}
69
71{
72 m_copy->clear();
73}
74
75void QQmlListModelWorkerAgent::remove(QQmlV4FunctionPtr args)
76{
77 m_copy->remove(args);
78}
79
80void QQmlListModelWorkerAgent::append(QQmlV4FunctionPtr args)
81{
82 m_copy->append(args);
83}
84
85void QQmlListModelWorkerAgent::insert(QQmlV4FunctionPtr args)
86{
87 m_copy->insert(args);
88}
89
90QJSValue QQmlListModelWorkerAgent::get(int index) const
91{
92 return m_copy->get(index);
93}
94
95void QQmlListModelWorkerAgent::set(int index, const QJSValue &value)
96{
97 m_copy->set(index, value);
98}
99
100void QQmlListModelWorkerAgent::setProperty(int index, const QString& property, const QVariant& value)
101{
102 m_copy->setProperty(index, property, value);
103}
104
105void QQmlListModelWorkerAgent::move(int from, int to, int count)
106{
107 m_copy->move(from, to, count);
108}
109
111{
112 Sync *s = new Sync(m_copy);
113
114 mutex.lock();
115 QCoreApplication::postEvent(this, s);
116 syncDone.wait(&mutex);
117 mutex.unlock();
118}
119
121{
122 if (e->type() == QEvent::User) {
123 bool cc = false;
124 QMutexLocker locker(&mutex);
125 if (m_orig) {
126 Sync *s = static_cast<Sync *>(e);
127
128 cc = (m_orig->count() != s->list->count());
129
130 Q_ASSERT(m_orig->m_dynamicRoles == s->list->m_dynamicRoles);
131 if (m_orig->m_dynamicRoles)
132 QQmlListModel::sync(s->list, m_orig);
133 else
134 ListModel::sync(s->list->m_listModel, m_orig->m_listModel);
135 }
136
137 syncDone.wakeAll();
138 locker.unlock();
139
140 if (cc)
141 emit m_orig->countChanged();
142 return true;
143 }
144
145 return QObject::event(e);
146}
147
148QT_END_NAMESPACE
149
150#include "moc_qqmllistmodelworkeragent_p.cpp"
static bool sync(ListModel *src, ListModel *target)
bool event(QEvent *) override
This virtual function receives events to an object and should return true if the event e was recogniz...
Q_INVOKABLE void move(int from, int to, int count)
Q_INVOKABLE void remove(QQmlV4FunctionPtr args)
Q_INVOKABLE void insert(QQmlV4FunctionPtr args)
Q_INVOKABLE void setProperty(int index, const QString &property, const QVariant &value)
Q_INVOKABLE void append(QQmlV4FunctionPtr args)
void setEngine(QV4::ExecutionEngine *eng)
QV4::ExecutionEngine * engine() const