Qt 6.x
The Qt SDK
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
5#include "qqmllistmodel_p_p.h"
6#include <private/qqmldata_p.h>
7#include <private/qqmlengine_p.h>
8#include <qqmlinfo.h>
9
10#include <QtCore/qcoreevent.h>
11#include <QtCore/qcoreapplication.h>
12#include <QtCore/qdebug.h>
13
14
16
17QQmlListModelWorkerAgent::Sync::~Sync()
18{
19}
20
22: m_ref(1), m_orig(model), m_copy(new QQmlListModel(model, this))
23{
24}
25
27{
28 mutex.lock();
29 syncDone.wakeAll();
30 mutex.unlock();
31}
32
34{
35 return m_copy->m_engine;
36}
37
39{
40 if (eng != m_copy->m_engine) {
41 m_copy->m_engine = eng;
43 }
44}
45
47{
48 m_ref.ref();
49}
50
52{
53 bool del = !m_ref.deref();
54
55 if (del)
57}
58
60{
61 m_orig = nullptr;
62}
63
65{
66 return m_copy->count();
67}
68
70{
71 m_copy->clear();
72}
73
75{
76 m_copy->remove(args);
77}
78
80{
81 m_copy->append(args);
82}
83
85{
86 m_copy->insert(args);
87}
88
90{
91 return m_copy->get(index);
92}
93
95{
96 m_copy->set(index, value);
97}
98
100{
101 m_copy->setProperty(index, property, value);
102}
103
104void QQmlListModelWorkerAgent::move(int from, int to, int count)
105{
106 m_copy->move(from, to, count);
107}
108
110{
111 Sync *s = new Sync(m_copy);
112
113 mutex.lock();
115 syncDone.wait(&mutex);
116 mutex.unlock();
117}
118
120{
121 if (e->type() == QEvent::User) {
122 bool cc = false;
123 QMutexLocker locker(&mutex);
124 if (m_orig) {
125 Sync *s = static_cast<Sync *>(e);
126
127 cc = (m_orig->count() != s->list->count());
128
129 Q_ASSERT(m_orig->m_dynamicRoles == s->list->m_dynamicRoles);
130 if (m_orig->m_dynamicRoles)
131 QQmlListModel::sync(s->list, m_orig);
132 else
133 ListModel::sync(s->list->m_listModel, m_orig->m_listModel);
134 }
135
136 syncDone.wakeAll();
137 locker.unlock();
138
139 if (cc)
140 emit m_orig->countChanged();
141 return true;
142 }
143
144 return QObject::event(e);
145}
146
148
149#include "moc_qqmllistmodelworkeragent_p.cpp"
static bool sync(ListModel *src, ListModel *target)
bool ref() noexcept
bool deref() noexcept
static void postEvent(QObject *receiver, QEvent *event, int priority=Qt::NormalEventPriority)
\inmodule QtCore
Definition qcoreevent.h:45
The QJSValue class acts as a container for Qt/JavaScript data types.
Definition qjsvalue.h:31
\inmodule QtCore
Definition qmutex.h:317
void unlock() noexcept
Unlocks this mutex locker.
Definition qmutex.h:323
void unlock() noexcept
Unlocks the mutex.
Definition qmutex.h:293
void lock() noexcept
Locks the mutex.
Definition qmutex.h:290
virtual bool event(QEvent *event)
This virtual function receives events to an object and should return true if the event e was recogniz...
Definition qobject.cpp:1363
void deleteLater()
\threadsafe
Definition qobject.cpp:2352
Q_INVOKABLE void append(QQmlV4Function *args)
bool event(QEvent *) override
This virtual function receives events to an object and should return true if the event e was recogniz...
void engineChanged(QV4::ExecutionEngine *engine)
Q_INVOKABLE void move(int from, int to, int count)
Q_INVOKABLE void set(int index, const QJSValue &value)
Q_INVOKABLE void remove(QQmlV4Function *args)
Q_INVOKABLE void setProperty(int index, const QString &property, const QVariant &value)
void setEngine(QV4::ExecutionEngine *eng)
Q_INVOKABLE void insert(QQmlV4Function *args)
Q_INVOKABLE QJSValue get(int index) const
Q_INVOKABLE void insert(QQmlV4Function *args)
\qmlmethod ListModel::insert(int index, jsobject dict)
Q_INVOKABLE void sync()
\qmlmethod ListModel::sync()
Q_INVOKABLE void clear()
\qmlmethod ListModel::clear()
Q_INVOKABLE void append(QQmlV4Function *args)
\qmlmethod ListModel::append(jsobject dict)
Q_INVOKABLE void setProperty(int index, const QString &property, const QVariant &value)
\qmlmethod ListModel::setProperty(int index, string property, variant value)
Q_INVOKABLE QJSValue get(int index) const
\qmlmethod object ListModel::get(int index)
Q_INVOKABLE void move(int from, int to, int count)
\qmlmethod ListModel::move(int from, int to, int n)
Q_INVOKABLE void remove(QQmlV4Function *args)
\qmlmethod ListModel::remove(int index, int count = 1)
void countChanged()
Q_INVOKABLE void set(int index, const QJSValue &value)
\qmlmethod ListModel::set(int index, jsobject dict)
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
\inmodule QtCore
Definition qvariant.h:64
bool wait(QMutex *, QDeadlineTimer=QDeadlineTimer(QDeadlineTimer::Forever))
#define this
Definition dialogs.cpp:9
double e
Combined button and popup list for selecting options.
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
GLuint index
[2]
GLenum GLenum GLsizei count
GLdouble s
[6]
Definition qopenglext.h:235
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define emit
const char property[13]
Definition qwizard.cpp:101
QSqlQueryModel * model
[16]
QJSValueList args