Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qqmlnotifier_p.h
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
4#ifndef QQMLNOTIFIER_P_H
5#define QQMLNOTIFIER_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 <QtCore/qmetaobject.h>
19#include <private/qmetaobject_p.h>
20#include <private/qtqmlglobal_p.h>
21
23
25class QQmlData;
26class Q_QML_EXPORT QQmlNotifier
27{
28public:
29 inline QQmlNotifier();
30 inline ~QQmlNotifier();
31 inline void notify();
32
33 static void notify(QQmlData *ddata, int notifierIndex);
34
35private:
36 friend class QQmlData;
39
40 static void emitNotify(QQmlNotifierEndpoint *, void **a);
41 QQmlNotifierEndpoint *endpoints = nullptr;
42};
43
44class QQmlEngine;
46{
49public:
50 // QQmlNotifierEndpoint can only invoke one of a set of pre-defined callbacks.
51 // To add another callback, extend this enum and add the callback to the top
52 // of qqmlnotifier.cpp. Four bits are reserved for the callback, so there can
53 // be up to 15 of them (0 is reserved).
61
62 inline QQmlNotifierEndpoint(Callback callback);
63 inline ~QQmlNotifierEndpoint();
64
65 inline bool isConnected() const;
66 inline bool isConnected(QObject *source, int sourceSignal) const;
67 inline bool isConnected(QQmlNotifier *) const;
68
69 void connect(QObject *source, int sourceSignal, QQmlEngine *engine, bool doNotify = true);
70 inline void connect(QQmlNotifier *);
71 inline void disconnect();
72
73 inline bool isNotifying() const;
74 inline void startNotifying(qintptr *originalSenderPtr);
75 inline void stopNotifying(qintptr *originalSenderPtr);
76
77 inline void cancelNotify();
78
79 inline int signalIndex() const { return sourceSignal; }
80
81 inline qintptr sender() const;
82 inline void setSender(qintptr sender);
83
84 inline QObject *senderAsObject() const;
85 inline QQmlNotifier *senderAsNotifier() const;
86
87private:
88 friend class QQmlData;
89 friend class QQmlNotifier;
90
91 // Contains either the QObject*, or the QQmlNotifier* that this
92 // endpoint is connected to. While the endpoint is notifying, the
93 // senderPtr points to another qintptr that contains this value.
94 qintptr senderPtr;
95
96 Callback callback:4;
97 int needsConnectNotify:1;
98 // The index is in the range returned by QObjectPrivate::signalIndex().
99 // This is different from QMetaMethod::methodIndex().
100 signed int sourceSignal:27;
101};
102
106
108{
109 QQmlNotifierEndpoint *endpoint = endpoints;
110 while (endpoint) {
111 QQmlNotifierEndpoint *n = endpoint;
112 endpoint = n->next;
113 n->setSender(0x0);
114 n->next = nullptr;
115 n->prev = nullptr;
116 n->sourceSignal = -1;
117 }
118 endpoints = nullptr;
119}
120
122{
123 void *args[] = { nullptr };
124 if (endpoints) emitNotify(endpoints, args);
125}
126
128: next(nullptr), prev(nullptr), senderPtr(0), callback(callback), needsConnectNotify(false), sourceSignal(-1)
129{
130}
131
136
138{
139 return prev != nullptr;
140}
141
147{
148 return this->sourceSignal != -1 && senderAsObject() == source &&
149 this->sourceSignal == sourceSignal;
150}
151
153{
154 return sourceSignal == -1 && senderAsNotifier() == notifier;
155}
156
158{
159 disconnect();
160
161 next = notifier->endpoints;
162 if (next) { next->prev = &next; }
163 notifier->endpoints = this;
164 prev = &notifier->endpoints;
166}
167
169{
170 // Remove from notifier chain before calling disconnectNotify(), so that that
171 // QObject::receivers() returns the correct value in there
172 if (next) next->prev = prev;
173 if (prev) *prev = next;
174
175 if (sourceSignal != -1 && needsConnectNotify) {
176 QObject * const obj = senderAsObject();
177 Q_ASSERT(obj);
179
180 // In some degenerate cases an object being destructed might be unable
181 // to produce a metaObject(). Therefore we check here.
182 if (const QMetaObject *mo = obj->metaObject())
183 priv->disconnectNotify(QMetaObjectPrivate::signal(mo, sourceSignal));
184 }
185
186 setSender(0x0);
187 next = nullptr;
188 prev = nullptr;
189 sourceSignal = -1;
190}
191
200{
201 return senderPtr & 0x1;
202}
203
205{
206 Q_ASSERT(*originalSenderPtr == 0);
207 // Set the endpoint to notifying:
208 // - Save the original senderPtr,
209 *originalSenderPtr = senderPtr;
210 // - Take a pointer of it,
211 // - And assign that to the senderPtr, including a flag to signify "notifying".
212 senderPtr = qintptr(originalSenderPtr) | 0x1;
213}
214
216{
217 // End of notifying, restore values
218 Q_ASSERT((senderPtr & ~0x1) == qintptr(originalSenderPtr));
219 senderPtr = *originalSenderPtr;
220 *originalSenderPtr = 0;
221}
222
227{
228 if (isNotifying()) {
229 auto *ptr = (qintptr *)(senderPtr & ~0x1);
230 Q_ASSERT(ptr);
231 senderPtr = *ptr;
232 *ptr = 0;
233 }
234}
235
237{
238 return isNotifying() ? *(qintptr *)(senderPtr & ~0x1) : senderPtr;
239}
240
242{
243 // If we're just notifying, we write through to the originalSenderPtr
244 if (isNotifying())
245 *(qintptr *)(senderPtr & ~0x1) = sender;
246 else
247 senderPtr = sender;
248}
249
251{
252 return (QObject *)(sender());
253}
254
259
261
262#endif // QQMLNOTIFIER_P_H
263
DarwinBluetooth::LECBManagerNotifier * notifier
static QObjectPrivate * get(QObject *o)
Definition qobject_p.h:150
\inmodule QtCore
Definition qobject.h:103
The QQmlEngine class provides an environment for instantiating QML components.
Definition qqmlengine.h:57
void setSender(qintptr sender)
void cancelNotify()
Cancel any notifies that are in progress.
bool isNotifying() const
Returns true if a notify is in progress.
QObject * senderAsObject() const
void connect(QObject *source, int sourceSignal, QQmlEngine *engine, bool doNotify=true)
QQmlNotifier * senderAsNotifier() const
void stopNotifying(qintptr *originalSenderPtr)
qintptr sender() const
void startNotifying(qintptr *originalSenderPtr)
QQmlNotifierEndpoint(Callback callback)
auto mo
[7]
short next
Definition keywords.cpp:445
Combined button and popup list for selecting options.
static bool doNotify(QObject *, QEvent *)
static ControlElement< T > * ptr(QWidget *widget)
static const QMetaObjectPrivate * priv(const uint *data)
GLboolean GLboolean GLboolean GLboolean a
[7]
GLfloat n
GLsizei GLsizei GLchar * source
GLhandleARB obj
[2]
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
ptrdiff_t qintptr
Definition qtypes.h:166
QObject::connect nullptr
QJSValueList args
QJSEngine engine
[0]
static Q_CORE_EXPORT QMetaMethod signal(const QMetaObject *m, int signal_index)
\inmodule QtCore