Line data Source code
1 : /****************************************************************************
2 : **
3 : ** Copyright (C) 2016 The Qt Company Ltd.
4 : ** Copyright (C) 2016 Intel Corporation.
5 : ** Contact: https://www.qt.io/licensing/
6 : **
7 : ** This file is part of the QtCore module of the Qt Toolkit.
8 : **
9 : ** $QT_BEGIN_LICENSE:LGPL$
10 : ** Commercial License Usage
11 : ** Licensees holding valid commercial Qt licenses may use this file in
12 : ** accordance with the commercial license agreement provided with the
13 : ** Software or, alternatively, in accordance with the terms contained in
14 : ** a written agreement between you and The Qt Company. For licensing terms
15 : ** and conditions see https://www.qt.io/terms-conditions. For further
16 : ** information use the contact form at https://www.qt.io/contact-us.
17 : **
18 : ** GNU Lesser General Public License Usage
19 : ** Alternatively, this file may be used under the terms of the GNU Lesser
20 : ** General Public License version 3 as published by the Free Software
21 : ** Foundation and appearing in the file LICENSE.LGPL3 included in the
22 : ** packaging of this file. Please review the following information to
23 : ** ensure the GNU Lesser General Public License version 3 requirements
24 : ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
25 : **
26 : ** GNU General Public License Usage
27 : ** Alternatively, this file may be used under the terms of the GNU
28 : ** General Public License version 2.0 or (at your option) the GNU General
29 : ** Public license version 3 or any later version approved by the KDE Free
30 : ** Qt Foundation. The licenses are as published by the Free Software
31 : ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
32 : ** included in the packaging of this file. Please review the following
33 : ** information to ensure the GNU General Public License requirements will
34 : ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
35 : ** https://www.gnu.org/licenses/gpl-3.0.html.
36 : **
37 : ** $QT_END_LICENSE$
38 : **
39 : ****************************************************************************/
40 :
41 : #ifndef QOBJECTDEFS_H
42 : #define QOBJECTDEFS_H
43 :
44 : #if defined(__OBJC__) && !defined(__cplusplus)
45 : # warning "File built in Objective-C mode (.m), but using Qt requires Objective-C++ (.mm)"
46 : #endif
47 :
48 : #include <QtCore/qnamespace.h>
49 :
50 : #include <QtCore/qobjectdefs_impl.h>
51 :
52 : QT_BEGIN_NAMESPACE
53 :
54 :
55 : class QByteArray;
56 : struct QArrayData;
57 : typedef QArrayData QByteArrayData;
58 :
59 : class QString;
60 : #ifndef Q_MOC_OUTPUT_REVISION
61 : #define Q_MOC_OUTPUT_REVISION 67
62 : #endif
63 :
64 : // The following macros can be defined by tools that understand Qt
65 : // to have the information from the macro.
66 : #ifndef QT_ANNOTATE_CLASS
67 : # ifndef Q_COMPILER_VARIADIC_MACROS
68 : # define QT_ANNOTATE_CLASS(type, x)
69 : # else
70 : # define QT_ANNOTATE_CLASS(type, ...)
71 : # endif
72 : #endif
73 : #ifndef QT_ANNOTATE_CLASS2
74 : # define QT_ANNOTATE_CLASS2(type, a1, a2)
75 : #endif
76 : #ifndef QT_ANNOTATE_FUNCTION
77 : # define QT_ANNOTATE_FUNCTION(x)
78 : #endif
79 : #ifndef QT_ANNOTATE_ACCESS_SPECIFIER
80 : # define QT_ANNOTATE_ACCESS_SPECIFIER(x)
81 : #endif
82 :
83 : // The following macros are our "extensions" to C++
84 : // They are used, strictly speaking, only by the moc.
85 :
86 : #ifndef Q_MOC_RUN
87 : #ifndef QT_NO_META_MACROS
88 : # if defined(QT_NO_KEYWORDS)
89 : # define QT_NO_EMIT
90 : # else
91 : # ifndef QT_NO_SIGNALS_SLOTS_KEYWORDS
92 : # define slots Q_SLOTS
93 : # define signals Q_SIGNALS
94 : # endif
95 : # endif
96 : # define Q_SLOTS QT_ANNOTATE_ACCESS_SPECIFIER(qt_slot)
97 : # define Q_SIGNALS public QT_ANNOTATE_ACCESS_SPECIFIER(qt_signal)
98 : # define Q_PRIVATE_SLOT(d, signature) QT_ANNOTATE_CLASS2(qt_private_slot, d, signature)
99 : # define Q_EMIT
100 : #ifndef QT_NO_EMIT
101 : # define emit
102 : #endif
103 : #ifndef Q_CLASSINFO
104 : # define Q_CLASSINFO(name, value)
105 : #endif
106 : #define Q_PLUGIN_METADATA(x) QT_ANNOTATE_CLASS(qt_plugin_metadata, x)
107 : #define Q_INTERFACES(x) QT_ANNOTATE_CLASS(qt_interfaces, x)
108 : #ifdef Q_COMPILER_VARIADIC_MACROS
109 : # define Q_PROPERTY(...) QT_ANNOTATE_CLASS(qt_property, __VA_ARGS__)
110 : #else
111 : # define Q_PROPERTY(text) QT_ANNOTATE_CLASS(qt_property, text)
112 : #endif
113 : #define Q_PRIVATE_PROPERTY(d, text) QT_ANNOTATE_CLASS2(qt_private_property, d, text)
114 : #ifndef Q_REVISION
115 : # define Q_REVISION(v)
116 : #endif
117 : #define Q_OVERRIDE(text) QT_ANNOTATE_CLASS(qt_override, text)
118 : #define QDOC_PROPERTY(text) QT_ANNOTATE_CLASS(qt_qdoc_property, text)
119 : #define Q_ENUMS(x) QT_ANNOTATE_CLASS(qt_enums, x)
120 : #define Q_FLAGS(x) QT_ANNOTATE_CLASS(qt_enums, x)
121 : #define Q_ENUM_IMPL(ENUM) \
122 : friend Q_DECL_CONSTEXPR const QMetaObject *qt_getEnumMetaObject(ENUM) Q_DECL_NOEXCEPT { return &staticMetaObject; } \
123 : friend Q_DECL_CONSTEXPR const char *qt_getEnumName(ENUM) Q_DECL_NOEXCEPT { return #ENUM; }
124 : #define Q_ENUM(x) Q_ENUMS(x) Q_ENUM_IMPL(x)
125 : #define Q_FLAG(x) Q_FLAGS(x) Q_ENUM_IMPL(x)
126 : #define Q_ENUM_NS_IMPL(ENUM) \
127 : inline Q_DECL_CONSTEXPR const QMetaObject *qt_getEnumMetaObject(ENUM) Q_DECL_NOEXCEPT { return &staticMetaObject; } \
128 : inline Q_DECL_CONSTEXPR const char *qt_getEnumName(ENUM) Q_DECL_NOEXCEPT { return #ENUM; }
129 : #define Q_ENUM_NS(x) Q_ENUMS(x) Q_ENUM_NS_IMPL(x)
130 : #define Q_FLAG_NS(x) Q_FLAGS(x) Q_ENUM_NS_IMPL(x)
131 : #define Q_SCRIPTABLE QT_ANNOTATE_FUNCTION(qt_scriptable)
132 : #define Q_INVOKABLE QT_ANNOTATE_FUNCTION(qt_invokable)
133 : #define Q_SIGNAL QT_ANNOTATE_FUNCTION(qt_signal)
134 : #define Q_SLOT QT_ANNOTATE_FUNCTION(qt_slot)
135 : #endif // QT_NO_META_MACROS
136 :
137 : #ifndef QT_NO_TRANSLATION
138 : // full set of tr functions
139 : # define QT_TR_FUNCTIONS \
140 : static inline QString tr(const char *s, const char *c = Q_NULLPTR, int n = -1) \
141 : { return staticMetaObject.tr(s, c, n); } \
142 : QT_DEPRECATED static inline QString trUtf8(const char *s, const char *c = Q_NULLPTR, int n = -1) \
143 : { return staticMetaObject.tr(s, c, n); }
144 : #else
145 : // inherit the ones from QObject
146 : # define QT_TR_FUNCTIONS
147 : #endif
148 :
149 : // ### Qt6: remove
150 : #define Q_OBJECT_CHECK /* empty, unused since Qt 5.2 */
151 :
152 : #if defined(Q_CC_INTEL)
153 : // Cannot redefine the visibility of a method in an exported class
154 : # define Q_DECL_HIDDEN_STATIC_METACALL
155 : #else
156 : # define Q_DECL_HIDDEN_STATIC_METACALL Q_DECL_HIDDEN
157 : #endif
158 :
159 : #if defined(Q_CC_CLANG) && Q_CC_CLANG >= 306
160 : # define Q_OBJECT_NO_OVERRIDE_WARNING QT_WARNING_DISABLE_CLANG("-Winconsistent-missing-override")
161 : #elif defined(Q_CC_GNU) && !defined(Q_CC_INTEL) && Q_CC_GNU >= 501
162 : # define Q_OBJECT_NO_OVERRIDE_WARNING QT_WARNING_DISABLE_GCC("-Wsuggest-override")
163 : #else
164 : # define Q_OBJECT_NO_OVERRIDE_WARNING
165 : #endif
166 :
167 : #if defined(Q_CC_GNU) && !defined(Q_CC_INTEL) && Q_CC_GNU >= 600
168 : # define Q_OBJECT_NO_ATTRIBUTES_WARNING QT_WARNING_DISABLE_GCC("-Wattributes")
169 : #else
170 : # define Q_OBJECT_NO_ATTRIBUTES_WARNING
171 : #endif
172 :
173 : /* qmake ignore Q_OBJECT */
174 : #define Q_OBJECT \
175 : public: \
176 : QT_WARNING_PUSH \
177 : Q_OBJECT_NO_OVERRIDE_WARNING \
178 : static const QMetaObject staticMetaObject; \
179 : virtual const QMetaObject *metaObject() const; \
180 : virtual void *qt_metacast(const char *); \
181 : virtual int qt_metacall(QMetaObject::Call, int, void **); \
182 : QT_TR_FUNCTIONS \
183 : private: \
184 : Q_OBJECT_NO_ATTRIBUTES_WARNING \
185 : Q_DECL_HIDDEN_STATIC_METACALL static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **); \
186 : QT_WARNING_POP \
187 : struct QPrivateSignal {}; \
188 : QT_ANNOTATE_CLASS(qt_qobject, "")
189 :
190 : /* qmake ignore Q_OBJECT */
191 : #define Q_OBJECT_FAKE Q_OBJECT QT_ANNOTATE_CLASS(qt_fake, "")
192 :
193 : #ifndef QT_NO_META_MACROS
194 : /* qmake ignore Q_GADGET */
195 : #define Q_GADGET \
196 : public: \
197 : static const QMetaObject staticMetaObject; \
198 : void qt_check_for_QGADGET_macro(); \
199 : typedef void QtGadgetHelper; \
200 : private: \
201 : QT_WARNING_PUSH \
202 : Q_OBJECT_NO_ATTRIBUTES_WARNING \
203 : Q_DECL_HIDDEN_STATIC_METACALL static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **); \
204 : QT_WARNING_POP \
205 : QT_ANNOTATE_CLASS(qt_qgadget, "") \
206 : /*end*/
207 :
208 : /* qmake ignore Q_NAMESPACE */
209 : #define Q_NAMESPACE \
210 : extern const QMetaObject staticMetaObject; \
211 : QT_ANNOTATE_CLASS(qt_qnamespace, "") \
212 : /*end*/
213 :
214 : #endif // QT_NO_META_MACROS
215 :
216 : #else // Q_MOC_RUN
217 : #define slots slots
218 : #define signals signals
219 : #define Q_SLOTS Q_SLOTS
220 : #define Q_SIGNALS Q_SIGNALS
221 : #define Q_CLASSINFO(name, value) Q_CLASSINFO(name, value)
222 : #define Q_INTERFACES(x) Q_INTERFACES(x)
223 : #define Q_PROPERTY(text) Q_PROPERTY(text)
224 : #define Q_PRIVATE_PROPERTY(d, text) Q_PRIVATE_PROPERTY(d, text)
225 : #define Q_REVISION(v) Q_REVISION(v)
226 : #define Q_OVERRIDE(text) Q_OVERRIDE(text)
227 : #define Q_ENUMS(x) Q_ENUMS(x)
228 : #define Q_FLAGS(x) Q_FLAGS(x)
229 : #define Q_ENUM(x) Q_ENUM(x)
230 : #define Q_FLAGS(x) Q_FLAGS(x)
231 : /* qmake ignore Q_OBJECT */
232 : #define Q_OBJECT Q_OBJECT
233 : /* qmake ignore Q_OBJECT */
234 : #define Q_OBJECT_FAKE Q_OBJECT_FAKE
235 : /* qmake ignore Q_GADGET */
236 : #define Q_GADGET Q_GADGET
237 : #define Q_SCRIPTABLE Q_SCRIPTABLE
238 : #define Q_INVOKABLE Q_INVOKABLE
239 : #define Q_SIGNAL Q_SIGNAL
240 : #define Q_SLOT Q_SLOT
241 : #endif //Q_MOC_RUN
242 :
243 : #ifdef Q_CLANG_QDOC
244 : #undef Q_GADGET
245 : #define Q_GADGET
246 : #endif
247 :
248 : #ifndef QT_NO_META_MACROS
249 : // macro for onaming members
250 : #ifdef METHOD
251 : #undef METHOD
252 : #endif
253 : #ifdef SLOT
254 : #undef SLOT
255 : #endif
256 : #ifdef SIGNAL
257 : #undef SIGNAL
258 : #endif
259 : #endif // QT_NO_META_MACROS
260 :
261 : Q_CORE_EXPORT const char *qFlagLocation(const char *method);
262 :
263 : #ifndef QT_NO_META_MACROS
264 : #ifndef QT_NO_DEBUG
265 : # define QLOCATION "\0" __FILE__ ":" QT_STRINGIFY(__LINE__)
266 : # ifndef QT_NO_KEYWORDS
267 : # define METHOD(a) qFlagLocation("0"#a QLOCATION)
268 : # endif
269 : # define SLOT(a) qFlagLocation("1"#a QLOCATION)
270 : # define SIGNAL(a) qFlagLocation("2"#a QLOCATION)
271 : #else
272 : # ifndef QT_NO_KEYWORDS
273 : # define METHOD(a) "0"#a
274 : # endif
275 : # define SLOT(a) "1"#a
276 : # define SIGNAL(a) "2"#a
277 : #endif
278 :
279 : #define QMETHOD_CODE 0 // member type codes
280 : #define QSLOT_CODE 1
281 : #define QSIGNAL_CODE 2
282 : #endif // QT_NO_META_MACROS
283 :
284 : #define Q_ARG(type, data) QArgument<type >(#type, data)
285 : #define Q_RETURN_ARG(type, data) QReturnArgument<type >(#type, data)
286 :
287 : class QObject;
288 : class QMetaMethod;
289 : class QMetaEnum;
290 : class QMetaProperty;
291 : class QMetaClassInfo;
292 :
293 :
294 : class Q_CORE_EXPORT QGenericArgument
295 : {
296 : public:
297 286 : inline QGenericArgument(const char *aName = Q_NULLPTR, const void *aData = Q_NULLPTR)
298 286 : : _data(aData), _name(aName) {}
299 : inline void *data() const { return const_cast<void *>(_data); }
300 : inline const char *name() const { return _name; }
301 :
302 : private:
303 : const void *_data;
304 : const char *_name;
305 : };
306 :
307 : class Q_CORE_EXPORT QGenericReturnArgument: public QGenericArgument
308 : {
309 : public:
310 26 : inline QGenericReturnArgument(const char *aName = Q_NULLPTR, void *aData = Q_NULLPTR)
311 26 : : QGenericArgument(aName, aData)
312 26 : {}
313 : };
314 :
315 : template <class T>
316 : class QArgument: public QGenericArgument
317 : {
318 : public:
319 78 : inline QArgument(const char *aName, const T &aData)
320 78 : : QGenericArgument(aName, static_cast<const void *>(&aData))
321 78 : {}
322 : };
323 : template <class T>
324 : class QArgument<T &>: public QGenericArgument
325 : {
326 : public:
327 : inline QArgument(const char *aName, T &aData)
328 : : QGenericArgument(aName, static_cast<const void *>(&aData))
329 : {}
330 : };
331 :
332 :
333 : template <typename T>
334 : class QReturnArgument: public QGenericReturnArgument
335 : {
336 : public:
337 : inline QReturnArgument(const char *aName, T &aData)
338 : : QGenericReturnArgument(aName, static_cast<void *>(&aData))
339 : {}
340 : };
341 :
342 : struct Q_CORE_EXPORT QMetaObject
343 : {
344 : class Connection;
345 : const char *className() const;
346 : const QMetaObject *superClass() const;
347 :
348 : bool inherits(const QMetaObject *metaObject) const Q_DECL_NOEXCEPT;
349 : QObject *cast(QObject *obj) const;
350 : const QObject *cast(const QObject *obj) const;
351 :
352 : #ifndef QT_NO_TRANSLATION
353 : QString tr(const char *s, const char *c, int n = -1) const;
354 : #endif // QT_NO_TRANSLATION
355 :
356 : int methodOffset() const;
357 : int enumeratorOffset() const;
358 : int propertyOffset() const;
359 : int classInfoOffset() const;
360 :
361 : int constructorCount() const;
362 : int methodCount() const;
363 : int enumeratorCount() const;
364 : int propertyCount() const;
365 : int classInfoCount() const;
366 :
367 : int indexOfConstructor(const char *constructor) const;
368 : int indexOfMethod(const char *method) const;
369 : int indexOfSignal(const char *signal) const;
370 : int indexOfSlot(const char *slot) const;
371 : int indexOfEnumerator(const char *name) const;
372 : int indexOfProperty(const char *name) const;
373 : int indexOfClassInfo(const char *name) const;
374 :
375 : QMetaMethod constructor(int index) const;
376 : QMetaMethod method(int index) const;
377 : QMetaEnum enumerator(int index) const;
378 : QMetaProperty property(int index) const;
379 : QMetaClassInfo classInfo(int index) const;
380 : QMetaProperty userProperty() const;
381 :
382 : static bool checkConnectArgs(const char *signal, const char *method);
383 : static bool checkConnectArgs(const QMetaMethod &signal,
384 : const QMetaMethod &method);
385 : static QByteArray normalizedSignature(const char *method);
386 : static QByteArray normalizedType(const char *type);
387 :
388 : // internal index-based connect
389 : static Connection connect(const QObject *sender, int signal_index,
390 : const QObject *receiver, int method_index,
391 : int type = 0, int *types = Q_NULLPTR);
392 : // internal index-based disconnect
393 : static bool disconnect(const QObject *sender, int signal_index,
394 : const QObject *receiver, int method_index);
395 : static bool disconnectOne(const QObject *sender, int signal_index,
396 : const QObject *receiver, int method_index);
397 : // internal slot-name based connect
398 : static void connectSlotsByName(QObject *o);
399 :
400 : // internal index-based signal activation
401 : static void activate(QObject *sender, int signal_index, void **argv);
402 : static void activate(QObject *sender, const QMetaObject *, int local_signal_index, void **argv);
403 : static void activate(QObject *sender, int signal_offset, int local_signal_index, void **argv);
404 :
405 : static bool invokeMethod(QObject *obj, const char *member,
406 : Qt::ConnectionType,
407 : QGenericReturnArgument ret,
408 : QGenericArgument val0 = QGenericArgument(Q_NULLPTR),
409 : QGenericArgument val1 = QGenericArgument(),
410 : QGenericArgument val2 = QGenericArgument(),
411 : QGenericArgument val3 = QGenericArgument(),
412 : QGenericArgument val4 = QGenericArgument(),
413 : QGenericArgument val5 = QGenericArgument(),
414 : QGenericArgument val6 = QGenericArgument(),
415 : QGenericArgument val7 = QGenericArgument(),
416 : QGenericArgument val8 = QGenericArgument(),
417 : QGenericArgument val9 = QGenericArgument());
418 :
419 : static inline bool invokeMethod(QObject *obj, const char *member,
420 : QGenericReturnArgument ret,
421 : QGenericArgument val0 = QGenericArgument(Q_NULLPTR),
422 : QGenericArgument val1 = QGenericArgument(),
423 : QGenericArgument val2 = QGenericArgument(),
424 : QGenericArgument val3 = QGenericArgument(),
425 : QGenericArgument val4 = QGenericArgument(),
426 : QGenericArgument val5 = QGenericArgument(),
427 : QGenericArgument val6 = QGenericArgument(),
428 : QGenericArgument val7 = QGenericArgument(),
429 : QGenericArgument val8 = QGenericArgument(),
430 : QGenericArgument val9 = QGenericArgument())
431 : {
432 : return invokeMethod(obj, member, Qt::AutoConnection, ret, val0, val1, val2, val3,
433 : val4, val5, val6, val7, val8, val9);
434 : }
435 :
436 26 : static inline bool invokeMethod(QObject *obj, const char *member,
437 : Qt::ConnectionType type,
438 : QGenericArgument val0 = QGenericArgument(Q_NULLPTR),
439 : QGenericArgument val1 = QGenericArgument(),
440 : QGenericArgument val2 = QGenericArgument(),
441 : QGenericArgument val3 = QGenericArgument(),
442 : QGenericArgument val4 = QGenericArgument(),
443 : QGenericArgument val5 = QGenericArgument(),
444 : QGenericArgument val6 = QGenericArgument(),
445 : QGenericArgument val7 = QGenericArgument(),
446 : QGenericArgument val8 = QGenericArgument(),
447 : QGenericArgument val9 = QGenericArgument())
448 : {
449 52 : return invokeMethod(obj, member, type, QGenericReturnArgument(), val0, val1, val2,
450 52 : val3, val4, val5, val6, val7, val8, val9);
451 : }
452 :
453 : static inline bool invokeMethod(QObject *obj, const char *member,
454 : QGenericArgument val0 = QGenericArgument(Q_NULLPTR),
455 : QGenericArgument val1 = QGenericArgument(),
456 : QGenericArgument val2 = QGenericArgument(),
457 : QGenericArgument val3 = QGenericArgument(),
458 : QGenericArgument val4 = QGenericArgument(),
459 : QGenericArgument val5 = QGenericArgument(),
460 : QGenericArgument val6 = QGenericArgument(),
461 : QGenericArgument val7 = QGenericArgument(),
462 : QGenericArgument val8 = QGenericArgument(),
463 : QGenericArgument val9 = QGenericArgument())
464 : {
465 : return invokeMethod(obj, member, Qt::AutoConnection, QGenericReturnArgument(), val0,
466 : val1, val2, val3, val4, val5, val6, val7, val8, val9);
467 : }
468 :
469 : #ifdef Q_QDOC
470 : template<typename PointerToMemberFunction, typename MemberFunctionReturnType>
471 : static bool invokeMethod(QObject *receiver, PointerToMemberFunction function, Qt::ConnectionType type = Qt::AutoConnection, MemberFunctionReturnType *ret = nullptr);
472 : template<typename PointerToMemberFunction, typename MemberFunctionReturnType>
473 : static bool invokeMethod(QObject *receiver, PointerToMemberFunction function, MemberFunctionReturnType *ret);
474 : template<typename Functor, typename FunctorReturnType>
475 : static bool invokeMethod(QObject *context, Functor function, Qt::ConnectionType type = Qt::AutoConnection, FunctorReturnType *ret = nullptr);
476 : template<typename Functor, typename FunctorReturnType>
477 : static bool invokeMethod(QObject *context, Functor function, FunctorReturnType *ret);
478 : #else
479 :
480 : // invokeMethod() for member function pointer
481 : template <typename Func>
482 : static typename std::enable_if<QtPrivate::FunctionPointer<Func>::IsPointerToMemberFunction
483 : && !std::is_convertible<Func, const char*>::value
484 : && QtPrivate::FunctionPointer<Func>::ArgumentCount == 0, bool>::type
485 : invokeMethod(typename QtPrivate::FunctionPointer<Func>::Object *object,
486 : Func function,
487 : Qt::ConnectionType type = Qt::AutoConnection,
488 : typename QtPrivate::FunctionPointer<Func>::ReturnType *ret = nullptr)
489 : {
490 : return invokeMethodImpl(object, new QtPrivate::QSlotObjectWithNoArgs<Func>(function), type, ret);
491 : }
492 :
493 : template <typename Func>
494 : static typename std::enable_if<QtPrivate::FunctionPointer<Func>::IsPointerToMemberFunction
495 : && !std::is_convertible<Func, const char*>::value
496 : && QtPrivate::FunctionPointer<Func>::ArgumentCount == 0, bool>::type
497 : invokeMethod(typename QtPrivate::FunctionPointer<Func>::Object *object,
498 : Func function,
499 : typename QtPrivate::FunctionPointer<Func>::ReturnType *ret)
500 : {
501 : return invokeMethodImpl(object, new QtPrivate::QSlotObjectWithNoArgs<Func>(function), Qt::AutoConnection, ret);
502 : }
503 :
504 : // invokeMethod() for function pointer (not member)
505 : template <typename Func>
506 : static typename std::enable_if<!QtPrivate::FunctionPointer<Func>::IsPointerToMemberFunction
507 : && !std::is_convertible<Func, const char*>::value
508 : && QtPrivate::FunctionPointer<Func>::ArgumentCount == 0, bool>::type
509 : invokeMethod(QObject *context, Func function,
510 : Qt::ConnectionType type = Qt::AutoConnection,
511 : typename QtPrivate::FunctionPointer<Func>::ReturnType *ret = nullptr)
512 : {
513 : return invokeMethodImpl(context, new QtPrivate::QFunctorSlotObjectWithNoArgsImplicitReturn<Func>(function), type, ret);
514 : }
515 :
516 : template <typename Func>
517 : static typename std::enable_if<!QtPrivate::FunctionPointer<Func>::IsPointerToMemberFunction
518 : && !std::is_convertible<Func, const char*>::value
519 : && QtPrivate::FunctionPointer<Func>::ArgumentCount == 0, bool>::type
520 : invokeMethod(QObject *context, Func function,
521 : typename QtPrivate::FunctionPointer<Func>::ReturnType *ret)
522 : {
523 : return invokeMethodImpl(context, new QtPrivate::QFunctorSlotObjectWithNoArgsImplicitReturn<Func>(function), Qt::AutoConnection, ret);
524 : }
525 :
526 : // invokeMethod() for Functor
527 : template <typename Func>
528 : static typename std::enable_if<!QtPrivate::FunctionPointer<Func>::IsPointerToMemberFunction
529 : && QtPrivate::FunctionPointer<Func>::ArgumentCount == -1
530 : && !std::is_convertible<Func, const char*>::value, bool>::type
531 : invokeMethod(QObject *context, Func function,
532 : Qt::ConnectionType type = Qt::AutoConnection, decltype(function()) *ret = nullptr)
533 : {
534 : return invokeMethodImpl(context,
535 : new QtPrivate::QFunctorSlotObjectWithNoArgs<Func, decltype(function())>(function),
536 : type,
537 : ret);
538 : }
539 :
540 : template <typename Func>
541 : static typename std::enable_if<!QtPrivate::FunctionPointer<Func>::IsPointerToMemberFunction
542 : && QtPrivate::FunctionPointer<Func>::ArgumentCount == -1
543 : && !std::is_convertible<Func, const char*>::value, bool>::type
544 : invokeMethod(QObject *context, Func function, typename std::result_of<Func()>::type *ret)
545 : {
546 : return invokeMethodImpl(context,
547 : new QtPrivate::QFunctorSlotObjectWithNoArgs<Func, decltype(function())>(function),
548 : Qt::AutoConnection,
549 : ret);
550 : }
551 :
552 : #endif
553 :
554 : QObject *newInstance(QGenericArgument val0 = QGenericArgument(Q_NULLPTR),
555 : QGenericArgument val1 = QGenericArgument(),
556 : QGenericArgument val2 = QGenericArgument(),
557 : QGenericArgument val3 = QGenericArgument(),
558 : QGenericArgument val4 = QGenericArgument(),
559 : QGenericArgument val5 = QGenericArgument(),
560 : QGenericArgument val6 = QGenericArgument(),
561 : QGenericArgument val7 = QGenericArgument(),
562 : QGenericArgument val8 = QGenericArgument(),
563 : QGenericArgument val9 = QGenericArgument()) const;
564 :
565 : enum Call {
566 : InvokeMetaMethod,
567 : ReadProperty,
568 : WriteProperty,
569 : ResetProperty,
570 : QueryPropertyDesignable,
571 : QueryPropertyScriptable,
572 : QueryPropertyStored,
573 : QueryPropertyEditable,
574 : QueryPropertyUser,
575 : CreateInstance,
576 : IndexOfMethod,
577 : RegisterPropertyMetaType,
578 : RegisterMethodArgumentMetaType
579 : };
580 :
581 : int static_metacall(Call, int, void **) const;
582 : static int metacall(QObject *, Call, int, void **);
583 :
584 : struct { // private data
585 : const QMetaObject *superdata;
586 : const QByteArrayData *stringdata;
587 : const uint *data;
588 : typedef void (*StaticMetacallFunction)(QObject *, QMetaObject::Call, int, void **);
589 : StaticMetacallFunction static_metacall;
590 : const QMetaObject * const *relatedMetaObjects;
591 : void *extradata; //reserved for future use
592 : } d;
593 :
594 : private:
595 : static bool invokeMethodImpl(QObject *object, QtPrivate::QSlotObjectBase *slot, Qt::ConnectionType type, void *ret);
596 : };
597 :
598 : class Q_CORE_EXPORT QMetaObject::Connection {
599 : void *d_ptr; //QObjectPrivate::Connection*
600 : explicit Connection(void *data) : d_ptr(data) { }
601 : friend class QObject;
602 : friend class QObjectPrivate;
603 : friend struct QMetaObject;
604 : bool isConnected_helper() const;
605 : public:
606 : ~Connection();
607 : Connection();
608 : Connection(const Connection &other);
609 : Connection &operator=(const Connection &other);
610 : #ifdef Q_QDOC
611 : operator bool() const;
612 : #else
613 : typedef void *Connection::*RestrictedBool;
614 6 : operator RestrictedBool() const { return d_ptr && isConnected_helper() ? &Connection::d_ptr : Q_NULLPTR; }
615 : #endif
616 :
617 : #ifdef Q_COMPILER_RVALUE_REFS
618 : inline Connection(Connection &&o) : d_ptr(o.d_ptr) { o.d_ptr = Q_NULLPTR; }
619 : inline Connection &operator=(Connection &&other)
620 : { qSwap(d_ptr, other.d_ptr); return *this; }
621 : #endif
622 : };
623 :
624 : inline const QMetaObject *QMetaObject::superClass() const
625 : { return d.superdata; }
626 :
627 : namespace QtPrivate {
628 : /* Trait that tells is a the Object has a Q_OBJECT macro */
629 : template <typename Object> struct HasQ_OBJECT_Macro {
630 : template <typename T>
631 : static char test(int (T::*)(QMetaObject::Call, int, void **));
632 : static int test(int (Object::*)(QMetaObject::Call, int, void **));
633 : enum { Value = sizeof(test(&Object::qt_metacall)) == sizeof(int) };
634 : };
635 : }
636 :
637 : QT_END_NAMESPACE
638 :
639 : #endif // QOBJECTDEFS_H
|