1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtCore module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
45 #include <QtCore/qnamespace.h>
47 #include <QtCore/qobjectdefs_impl.h>
56 typedef QArrayData QByteArrayData;
60 #ifndef Q_MOC_OUTPUT_REVISION
61 #define Q_MOC_OUTPUT_REVISION 67
64 // The following macros are our "extensions" to C++
65 // They are used, strictly speaking, only by the moc.
68 #ifndef QT_NO_META_MACROS
69 # if defined(QT_NO_KEYWORDS)
72 # ifndef QT_NO_SIGNALS_SLOTS_KEYWORDS
74 # define signals public
78 # define Q_SIGNALS public
79 # define Q_PRIVATE_SLOT(d, signature)
84 #define Q_CLASSINFO(name, value)
85 #define Q_PLUGIN_METADATA(x)
86 #define Q_INTERFACES(x)
87 #define Q_PROPERTY(text)
88 #define Q_PRIVATE_PROPERTY(d, text)
90 #define Q_OVERRIDE(text)
97 #endif // QT_NO_META_MACROS
99 #ifndef QT_NO_TRANSLATION
100 // full set of tr functions
101 # define QT_TR_FUNCTIONS \
102 static inline QString tr(const char *s, const char *c = 0, int n = -1) \
103 { return staticMetaObject.tr(s, c, n); } \
104 QT_DEPRECATED static inline QString trUtf8(const char *s, const char *c = 0, int n = -1) \
105 { return staticMetaObject.tr(s, c, n); }
107 // inherit the ones from QObject
108 # define QT_TR_FUNCTIONS
111 #if defined(QT_NO_QOBJECT_CHECK)
112 /* qmake ignore Q_OBJECT */
113 #define Q_OBJECT_CHECK
116 /* This is a compile time check that ensures that any class cast with qobject_cast
117 actually contains a Q_OBJECT macro. Note: qobject_cast will fail if a QObject
118 subclass doesn't contain Q_OBJECT.
120 In qt_check_for_QOBJECT_macro, we call a dummy templated function with two
121 parameters, the first being "this" and the other the target of the qobject
122 cast. If the types are not identical, we know that a Q_OBJECT macro is missing.
124 If you get a compiler error here, make sure that the class you are casting
125 to contains a Q_OBJECT macro.
128 /* qmake ignore Q_OBJECT */
129 #define Q_OBJECT_CHECK \
130 template <typename T> inline void qt_check_for_QOBJECT_macro(const T &_q_argument) const \
131 { int i = qYouForgotTheQ_OBJECT_Macro(this, &_q_argument); i = i + 1; }
133 template <typename T>
134 inline int qYouForgotTheQ_OBJECT_Macro(T, T) { return 0; }
136 template <typename T1, typename T2>
137 inline void qYouForgotTheQ_OBJECT_Macro(T1, T2) {}
138 #endif // QT_NO_QOBJECT_CHECK
140 #if defined(Q_CC_INTEL)
141 // Cannot redefine the visibility of a method in an exported class
142 # define Q_DECL_HIDDEN_STATIC_METACALL
144 # define Q_DECL_HIDDEN_STATIC_METACALL Q_DECL_HIDDEN
147 /* qmake ignore Q_OBJECT */
151 static const QMetaObject staticMetaObject; \
152 virtual const QMetaObject *metaObject() const; \
153 virtual void *qt_metacast(const char *); \
155 virtual int qt_metacall(QMetaObject::Call, int, void **); \
157 Q_DECL_HIDDEN_STATIC_METACALL static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **);
159 /* qmake ignore Q_OBJECT */
160 #define Q_OBJECT_FAKE Q_OBJECT
162 #ifndef QT_NO_META_MACROS
163 /* qmake ignore Q_GADGET */
166 static const QMetaObject staticMetaObject; \
168 #endif // QT_NO_META_MACROS
172 #define signals signals
173 #define Q_SLOTS Q_SLOTS
174 #define Q_SIGNALS Q_SIGNALS
175 #define Q_CLASSINFO(name, value) Q_CLASSINFO(name, value)
176 #define Q_INTERFACES(x) Q_INTERFACES(x)
177 #define Q_PROPERTY(text) Q_PROPERTY(text)
178 #define Q_PRIVATE_PROPERTY(d, text) Q_PRIVATE_PROPERTY(d, text)
179 #define Q_REVISION(v) Q_REVISION(v)
180 #define Q_OVERRIDE(text) Q_OVERRIDE(text)
181 #define Q_ENUMS(x) Q_ENUMS(x)
182 #define Q_FLAGS(x) Q_FLAGS(x)
183 /* qmake ignore Q_OBJECT */
184 #define Q_OBJECT Q_OBJECT
185 /* qmake ignore Q_OBJECT */
186 #define Q_OBJECT_FAKE Q_OBJECT_FAKE
187 /* qmake ignore Q_GADGET */
188 #define Q_GADGET Q_GADGET
189 #define Q_SCRIPTABLE Q_SCRIPTABLE
190 #define Q_INVOKABLE Q_INVOKABLE
191 #define Q_SIGNAL Q_SIGNAL
192 #define Q_SLOT Q_SLOT
195 #ifndef QT_NO_META_MACROS
196 // macro for onaming members
206 #endif // QT_NO_META_MACROS
208 Q_CORE_EXPORT const char *qFlagLocation(const char *method);
210 #ifndef QT_NO_META_MACROS
211 #define QTOSTRING_HELPER(s) #s
212 #define QTOSTRING(s) QTOSTRING_HELPER(s)
214 # define QLOCATION "\0" __FILE__ ":" QTOSTRING(__LINE__)
215 # ifndef QT_NO_KEYWORDS
216 # define METHOD(a) qFlagLocation("0"#a QLOCATION)
218 # define SLOT(a) qFlagLocation("1"#a QLOCATION)
219 # define SIGNAL(a) qFlagLocation("2"#a QLOCATION)
221 # ifndef QT_NO_KEYWORDS
222 # define METHOD(a) "0"#a
224 # define SLOT(a) "1"#a
225 # define SIGNAL(a) "2"#a
228 #define QMETHOD_CODE 0 // member type codes
230 #define QSIGNAL_CODE 2
231 #endif // QT_NO_META_MACROS
233 #define Q_ARG(type, data) QArgument<type >(#type, data)
234 #define Q_RETURN_ARG(type, data) QReturnArgument<type >(#type, data)
240 class QMetaClassInfo;
243 class Q_CORE_EXPORT QGenericArgument
246 inline QGenericArgument(const char *aName = 0, const void *aData = 0)
247 : _data(aData), _name(aName) {}
248 inline void *data() const { return const_cast<void *>(_data); }
249 inline const char *name() const { return _name; }
256 class Q_CORE_EXPORT QGenericReturnArgument: public QGenericArgument
259 inline QGenericReturnArgument(const char *aName = 0, void *aData = 0)
260 : QGenericArgument(aName, aData)
265 class QArgument: public QGenericArgument
268 inline QArgument(const char *aName, const T &aData)
269 : QGenericArgument(aName, static_cast<const void *>(&aData))
273 class QArgument<T &>: public QGenericArgument
276 inline QArgument(const char *aName, T &aData)
277 : QGenericArgument(aName, static_cast<const void *>(&aData))
282 template <typename T>
283 class QReturnArgument: public QGenericReturnArgument
286 inline QReturnArgument(const char *aName, T &aData)
287 : QGenericReturnArgument(aName, static_cast<void *>(&aData))
291 struct Q_CORE_EXPORT QMetaObject
294 const char *className() const;
295 const QMetaObject *superClass() const;
297 QObject *cast(QObject *obj) const;
298 const QObject *cast(const QObject *obj) const;
300 #ifndef QT_NO_TRANSLATION
301 QString tr(const char *s, const char *c, int n = -1) const;
302 #endif // QT_NO_TRANSLATION
304 int methodOffset() const;
305 int enumeratorOffset() const;
306 int propertyOffset() const;
307 int classInfoOffset() const;
309 int constructorCount() const;
310 int methodCount() const;
311 int enumeratorCount() const;
312 int propertyCount() const;
313 int classInfoCount() const;
315 int indexOfConstructor(const char *constructor) const;
316 int indexOfMethod(const char *method) const;
317 int indexOfSignal(const char *signal) const;
318 int indexOfSlot(const char *slot) const;
319 int indexOfEnumerator(const char *name) const;
320 int indexOfProperty(const char *name) const;
321 int indexOfClassInfo(const char *name) const;
323 QMetaMethod constructor(int index) const;
324 QMetaMethod method(int index) const;
325 QMetaEnum enumerator(int index) const;
326 QMetaProperty property(int index) const;
327 QMetaClassInfo classInfo(int index) const;
328 QMetaProperty userProperty() const;
330 static bool checkConnectArgs(const char *signal, const char *method);
331 static bool checkConnectArgs(const QMetaMethod &signal,
332 const QMetaMethod &method);
333 static QByteArray normalizedSignature(const char *method);
334 static QByteArray normalizedType(const char *type);
336 // internal index-based connect
337 static Connection connect(const QObject *sender, int signal_index,
338 const QObject *receiver, int method_index,
339 int type = 0, int *types = 0);
340 // internal index-based disconnect
341 static bool disconnect(const QObject *sender, int signal_index,
342 const QObject *receiver, int method_index);
343 static bool disconnectOne(const QObject *sender, int signal_index,
344 const QObject *receiver, int method_index);
345 // internal slot-name based connect
346 static void connectSlotsByName(QObject *o);
348 // internal index-based signal activation
349 static void activate(QObject *sender, int signal_index, void **argv);
350 static void activate(QObject *sender, const QMetaObject *, int local_signal_index, void **argv);
351 static void activate(QObject *sender, int signal_offset, int local_signal_index, void **argv);
353 static bool invokeMethod(QObject *obj, const char *member,
355 QGenericReturnArgument ret,
356 QGenericArgument val0 = QGenericArgument(0),
357 QGenericArgument val1 = QGenericArgument(),
358 QGenericArgument val2 = QGenericArgument(),
359 QGenericArgument val3 = QGenericArgument(),
360 QGenericArgument val4 = QGenericArgument(),
361 QGenericArgument val5 = QGenericArgument(),
362 QGenericArgument val6 = QGenericArgument(),
363 QGenericArgument val7 = QGenericArgument(),
364 QGenericArgument val8 = QGenericArgument(),
365 QGenericArgument val9 = QGenericArgument());
367 static inline bool invokeMethod(QObject *obj, const char *member,
368 QGenericReturnArgument ret,
369 QGenericArgument val0 = QGenericArgument(0),
370 QGenericArgument val1 = QGenericArgument(),
371 QGenericArgument val2 = QGenericArgument(),
372 QGenericArgument val3 = QGenericArgument(),
373 QGenericArgument val4 = QGenericArgument(),
374 QGenericArgument val5 = QGenericArgument(),
375 QGenericArgument val6 = QGenericArgument(),
376 QGenericArgument val7 = QGenericArgument(),
377 QGenericArgument val8 = QGenericArgument(),
378 QGenericArgument val9 = QGenericArgument())
380 return invokeMethod(obj, member, Qt::AutoConnection, ret, val0, val1, val2, val3,
381 val4, val5, val6, val7, val8, val9);
384 static inline bool invokeMethod(QObject *obj, const char *member,
385 Qt::ConnectionType type,
386 QGenericArgument val0 = QGenericArgument(0),
387 QGenericArgument val1 = QGenericArgument(),
388 QGenericArgument val2 = QGenericArgument(),
389 QGenericArgument val3 = QGenericArgument(),
390 QGenericArgument val4 = QGenericArgument(),
391 QGenericArgument val5 = QGenericArgument(),
392 QGenericArgument val6 = QGenericArgument(),
393 QGenericArgument val7 = QGenericArgument(),
394 QGenericArgument val8 = QGenericArgument(),
395 QGenericArgument val9 = QGenericArgument())
397 return invokeMethod(obj, member, type, QGenericReturnArgument(), val0, val1, val2,
398 val3, val4, val5, val6, val7, val8, val9);
401 static inline bool invokeMethod(QObject *obj, const char *member,
402 QGenericArgument val0 = QGenericArgument(0),
403 QGenericArgument val1 = QGenericArgument(),
404 QGenericArgument val2 = QGenericArgument(),
405 QGenericArgument val3 = QGenericArgument(),
406 QGenericArgument val4 = QGenericArgument(),
407 QGenericArgument val5 = QGenericArgument(),
408 QGenericArgument val6 = QGenericArgument(),
409 QGenericArgument val7 = QGenericArgument(),
410 QGenericArgument val8 = QGenericArgument(),
411 QGenericArgument val9 = QGenericArgument())
413 return invokeMethod(obj, member, Qt::AutoConnection, QGenericReturnArgument(), val0,
414 val1, val2, val3, val4, val5, val6, val7, val8, val9);
417 QObject *newInstance(QGenericArgument val0 = QGenericArgument(0),
418 QGenericArgument val1 = QGenericArgument(),
419 QGenericArgument val2 = QGenericArgument(),
420 QGenericArgument val3 = QGenericArgument(),
421 QGenericArgument val4 = QGenericArgument(),
422 QGenericArgument val5 = QGenericArgument(),
423 QGenericArgument val6 = QGenericArgument(),
424 QGenericArgument val7 = QGenericArgument(),
425 QGenericArgument val8 = QGenericArgument(),
426 QGenericArgument val9 = QGenericArgument()) const;
433 QueryPropertyDesignable,
434 QueryPropertyScriptable,
436 QueryPropertyEditable,
442 int static_metacall(Call, int, void **) const;
443 static int metacall(QObject *, Call, int, void **);
445 struct { // private data
446 const QMetaObject *superdata;
447 const QByteArrayData *stringdata;
449 typedef void (*StaticMetacallFunction)(QObject *, QMetaObject::Call, int, void **);
450 StaticMetacallFunction static_metacall;
451 const QMetaObject **relatedMetaObjects;
452 void *extradata; //reserved for future use
456 class Q_CORE_EXPORT QMetaObject::Connection {
457 void *d_ptr; //QObjectPrivate::Connection*
458 explicit Connection(void *data) : d_ptr(data) { }
459 friend class QObject;
460 friend struct QMetaObject;
464 Connection(const Connection &other);
465 Connection &operator=(const Connection &other);
467 operator bool() const;
469 typedef void *Connection::*RestrictedBool;
470 operator RestrictedBool() const { return d_ptr ? &Connection::d_ptr : 0; }
473 #ifdef Q_COMPILER_RVALUE_REFS
474 inline Connection(Connection &&o) : d_ptr(o.d_ptr) { o.d_ptr = 0; }
475 inline Connection &operator=(Connection &&other)
476 { qSwap(d_ptr, other.d_ptr); return *this; }
480 inline const QMetaObject *QMetaObject::superClass() const
481 { return d.superdata; }
487 #endif // QOBJECTDEFS_H