1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
5 **
6 ** This file is part of the QtCore module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 **
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 **
30 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file.  Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QOBJECTDEFS_H
43 #define QOBJECTDEFS_H
44 
45 #include <QtCore/qnamespace.h>
46 
47 QT_BEGIN_HEADER
48 
49 QT_BEGIN_NAMESPACE
50 
51 QT_MODULE(Core)
52 
53 class QByteArray;
54 
55 class QString;
56 
57 #ifndef Q_MOC_OUTPUT_REVISION
58 #define Q_MOC_OUTPUT_REVISION 63
59 #endif
60 
61 // The following macros are our "extensions" to C++
62 // They are used, strictly speaking, only by the moc.
63 
64 #ifndef Q_MOC_RUN
65 # if defined(QT_NO_KEYWORDS)
66 #  define QT_NO_EMIT
67 # else
68 #   define slots
69 #   define signals protected
70 # endif
71 # define Q_SLOTS
72 # define Q_SIGNALS protected
73 # define Q_PRIVATE_SLOT(d, signature)
74 # define Q_EMIT
75 #ifndef QT_NO_EMIT
76 # define emit
77 #endif
78 #define Q_CLASSINFO(name, value)
79 #define Q_INTERFACES(x)
80 #define Q_PROPERTY(text)
81 #define Q_PRIVATE_PROPERTY(d, text)
82 #define Q_REVISION(v)
83 #define Q_OVERRIDE(text)
84 #define Q_ENUMS(x)
85 #define Q_FLAGS(x)
86 #ifdef QT3_SUPPORT
87 # define Q_SETS(x)
88 #endif
89 #define Q_SCRIPTABLE
90 #define Q_INVOKABLE
91 #define Q_SIGNAL
92 #define Q_SLOT
93 
94 #ifndef QT_NO_TRANSLATION
95 # ifndef QT_NO_TEXTCODEC
96 // full set of tr functions
97 // ### Qt 5: merge overloads
98 #  define QT_TR_FUNCTIONS \
99     static inline QString tr(const char *s, const char *c = 0) \
100         { return staticMetaObject.tr(s, c); } \
101     static inline QString trUtf8(const char *s, const char *c = 0) \
102         { return staticMetaObject.trUtf8(s, c); } \
103     static inline QString tr(const char *s, const char *c, int n) \
104         { return staticMetaObject.tr(s, c, n); } \
105     static inline QString trUtf8(const char *s, const char *c, int n) \
106         { return staticMetaObject.trUtf8(s, c, n); }
107 # else
108 // no QTextCodec, no utf8
109 // ### Qt 5: merge overloads
110 #  define QT_TR_FUNCTIONS \
111     static inline QString tr(const char *s, const char *c = 0) \
112         { return staticMetaObject.tr(s, c); } \
113     static inline QString tr(const char *s, const char *c, int n) \
114         { return staticMetaObject.tr(s, c, n); }
115 # endif
116 #else
117 // inherit the ones from QObject
118 # define QT_TR_FUNCTIONS
119 #endif
120 
121 #if defined(QT_NO_QOBJECT_CHECK)
122 /* tmake ignore Q_OBJECT */
123 #define Q_OBJECT_CHECK
124 #else
125 
126 /* This is a compile time check that ensures that any class cast with qobject_cast
127    actually contains a Q_OBJECT macro. Note: qobject_cast will fail if a QObject
128    subclass doesn't contain Q_OBJECT.
129 
130    In qt_check_for_QOBJECT_macro, we call a dummy templated function with two
131    parameters, the first being "this" and the other the target of the qobject
132    cast. If the types are not identical, we know that a Q_OBJECT macro is missing.
133 
134    If you get a compiler error here, make sure that the class you are casting
135    to contains a Q_OBJECT macro.
136 */
137 
138 /* tmake ignore Q_OBJECT */
139 #define Q_OBJECT_CHECK \
140     template <typename T> inline void qt_check_for_QOBJECT_macro(const T &_q_argument) const \
141     { int i = qYouForgotTheQ_OBJECT_Macro(this, &_q_argument); i = i + 1; }
142 
143 template <typename T>
qYouForgotTheQ_OBJECT_Macro(T,T)144 inline int qYouForgotTheQ_OBJECT_Macro(T, T) { return 0; }
145 
146 template <typename T1, typename T2>
qYouForgotTheQ_OBJECT_Macro(T1,T2)147 inline void qYouForgotTheQ_OBJECT_Macro(T1, T2) {}
148 #endif // QT_NO_QOBJECT_CHECK
149 
150 #ifdef Q_NO_DATA_RELOCATION
151 #define Q_OBJECT_GETSTATICMETAOBJECT static const QMetaObject &getStaticMetaObject();
152 #else
153 #define Q_OBJECT_GETSTATICMETAOBJECT
154 #endif
155 
156 /* tmake ignore Q_OBJECT */
157 #define Q_OBJECT \
158 public: \
159     Q_OBJECT_CHECK \
160     static const QMetaObject staticMetaObject; \
161     Q_OBJECT_GETSTATICMETAOBJECT \
162     virtual const QMetaObject *metaObject() const; \
163     virtual void *qt_metacast(const char *); \
164     QT_TR_FUNCTIONS \
165     virtual int qt_metacall(QMetaObject::Call, int, void **); \
166 private: \
167     Q_DECL_HIDDEN static const QMetaObjectExtraData staticMetaObjectExtraData; \
168     Q_DECL_HIDDEN static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **);
169 
170 /* tmake ignore Q_OBJECT */
171 #define Q_OBJECT_FAKE Q_OBJECT
172 /* tmake ignore Q_GADGET */
173 #define Q_GADGET \
174 public: \
175     static const QMetaObject staticMetaObject; \
176     Q_OBJECT_GETSTATICMETAOBJECT \
177 private:
178 #else // Q_MOC_RUN
179 #define slots slots
180 #define signals signals
181 #define Q_SLOTS Q_SLOTS
182 #define Q_SIGNALS Q_SIGNALS
183 #define Q_CLASSINFO(name, value) Q_CLASSINFO(name, value)
184 #define Q_INTERFACES(x) Q_INTERFACES(x)
185 #define Q_PROPERTY(text) Q_PROPERTY(text)
186 #define Q_PRIVATE_PROPERTY(d, text) Q_PRIVATE_PROPERTY(d, text)
187 #define Q_REVISION(v) Q_REVISION(v)
188 #define Q_OVERRIDE(text) Q_OVERRIDE(text)
189 #define Q_ENUMS(x) Q_ENUMS(x)
190 #define Q_FLAGS(x) Q_FLAGS(x)
191 #ifdef QT3_SUPPORT
192 # define Q_SETS(x) Q_SETS(x)
193 #endif
194  /* tmake ignore Q_OBJECT */
195 #define Q_OBJECT Q_OBJECT
196  /* tmake ignore Q_OBJECT */
197 #define Q_OBJECT_FAKE Q_OBJECT_FAKE
198  /* tmake ignore Q_GADGET */
199 #define Q_GADGET Q_GADGET
200 #define Q_SCRIPTABLE Q_SCRIPTABLE
201 #define Q_INVOKABLE Q_INVOKABLE
202 #define Q_SIGNAL Q_SIGNAL
203 #define Q_SLOT Q_SLOT
204 #endif //Q_MOC_RUN
205 
206 // macro for onaming members
207 #ifdef METHOD
208 #undef METHOD
209 #endif
210 #ifdef SLOT
211 #undef SLOT
212 #endif
213 #ifdef SIGNAL
214 #undef SIGNAL
215 #endif
216 
217 Q_CORE_EXPORT const char *qFlagLocation(const char *method);
218 
219 #define QTOSTRING_HELPER(s) #s
220 #define QTOSTRING(s) QTOSTRING_HELPER(s)
221 #ifndef QT_NO_DEBUG
222 # define QLOCATION "\0" __FILE__ ":" QTOSTRING(__LINE__)
223 # ifndef QT_NO_KEYWORDS
224 #  define METHOD(a)   qFlagLocation("0"#a QLOCATION)
225 # endif
226 # define SLOT(a)     qFlagLocation("1"#a QLOCATION)
227 # define SIGNAL(a)   qFlagLocation("2"#a QLOCATION)
228 #else
229 # ifndef QT_NO_KEYWORDS
230 #  define METHOD(a)   "0"#a
231 # endif
232 # define SLOT(a)     "1"#a
233 # define SIGNAL(a)   "2"#a
234 #endif
235 
236 #ifdef QT3_SUPPORT
237 #define METHOD_CODE   0                        // member type codes
238 #define SLOT_CODE     1
239 #define SIGNAL_CODE   2
240 #endif
241 
242 #define QMETHOD_CODE  0                        // member type codes
243 #define QSLOT_CODE    1
244 #define QSIGNAL_CODE  2
245 
246 #define Q_ARG(type, data) QArgument<type >(#type, data)
247 #define Q_RETURN_ARG(type, data) QReturnArgument<type >(#type, data)
248 
249 class QObject;
250 class QMetaMethod;
251 class QMetaEnum;
252 class QMetaProperty;
253 class QMetaClassInfo;
254 
255 
256 class Q_CORE_EXPORT QGenericArgument
257 {
258 public:
259     inline QGenericArgument(const char *aName = 0, const void *aData = 0)
_data(aData)260         : _data(aData), _name(aName) {}
data()261     inline void *data() const { return const_cast<void *>(_data); }
name()262     inline const char *name() const { return _name; }
263 
264 private:
265     const void *_data;
266     const char *_name;
267 };
268 
269 class Q_CORE_EXPORT QGenericReturnArgument: public QGenericArgument
270 {
271 public:
272     inline QGenericReturnArgument(const char *aName = 0, void *aData = 0)
QGenericArgument(aName,aData)273         : QGenericArgument(aName, aData)
274         {}
275 };
276 
277 template <class T>
278 class QArgument: public QGenericArgument
279 {
280 public:
QArgument(const char * aName,const T & aData)281     inline QArgument(const char *aName, const T &aData)
282         : QGenericArgument(aName, static_cast<const void *>(&aData))
283         {}
284 };
285 template <class T>
286 class QArgument<T &>: public QGenericArgument
287 {
288 public:
QArgument(const char * aName,T & aData)289     inline QArgument(const char *aName, T &aData)
290         : QGenericArgument(aName, static_cast<const void *>(&aData))
291         {}
292 };
293 
294 
295 template <typename T>
296 class QReturnArgument: public QGenericReturnArgument
297 {
298 public:
QReturnArgument(const char * aName,T & aData)299     inline QReturnArgument(const char *aName, T &aData)
300         : QGenericReturnArgument(aName, static_cast<void *>(&aData))
301         {}
302 };
303 
304 struct Q_CORE_EXPORT QMetaObject
305 {
306     const char *className() const;
307     const QMetaObject *superClass() const;
308 
309     QObject *cast(QObject *obj) const;
310     const QObject *cast(const QObject *obj) const;
311 
312 #ifndef QT_NO_TRANSLATION
313     // ### Qt 4: Merge overloads
314     QString tr(const char *s, const char *c) const;
315     QString trUtf8(const char *s, const char *c) const;
316     QString tr(const char *s, const char *c, int n) const;
317     QString trUtf8(const char *s, const char *c, int n) const;
318 #endif // QT_NO_TRANSLATION
319 
320     int methodOffset() const;
321     int enumeratorOffset() const;
322     int propertyOffset() const;
323     int classInfoOffset() const;
324 
325     int constructorCount() const;
326     int methodCount() const;
327     int enumeratorCount() const;
328     int propertyCount() const;
329     int classInfoCount() const;
330 
331     int indexOfConstructor(const char *constructor) const;
332     int indexOfMethod(const char *method) const;
333     int indexOfSignal(const char *signal) const;
334     int indexOfSlot(const char *slot) const;
335     int indexOfEnumerator(const char *name) const;
336     int indexOfProperty(const char *name) const;
337     int indexOfClassInfo(const char *name) const;
338 
339     QMetaMethod constructor(int index) const;
340     QMetaMethod method(int index) const;
341     QMetaEnum enumerator(int index) const;
342     QMetaProperty property(int index) const;
343     QMetaClassInfo classInfo(int index) const;
344     QMetaProperty userProperty() const;
345 
346     static bool checkConnectArgs(const char *signal, const char *method);
347     static QByteArray normalizedSignature(const char *method);
348     static QByteArray normalizedType(const char *type);
349 
350     // internal index-based connect
351     static bool connect(const QObject *sender, int signal_index,
352                         const QObject *receiver, int method_index,
353                         int type = 0, int *types = 0);
354     // internal index-based disconnect
355     static bool disconnect(const QObject *sender, int signal_index,
356                            const QObject *receiver, int method_index);
357     static bool disconnectOne(const QObject *sender, int signal_index,
358                               const QObject *receiver, int method_index);
359     // internal slot-name based connect
360     static void connectSlotsByName(QObject *o);
361 
362     // internal index-based signal activation
363     static void activate(QObject *sender, int signal_index, void **argv);  //obsolete
364     static void activate(QObject *sender, int from_signal_index, int to_signal_index, void **argv); //obsolete
365     static void activate(QObject *sender, const QMetaObject *, int local_signal_index, void **argv);
366     static void activate(QObject *sender, const QMetaObject *, int from_local_signal_index, int to_local_signal_index, void **argv); //obsolete
367 
368     // internal guarded pointers
369     static void addGuard(QObject **ptr);
370     static void removeGuard(QObject **ptr);
371     static void changeGuard(QObject **ptr, QObject *o);
372 
373     static bool invokeMethod(QObject *obj, const char *member,
374                              Qt::ConnectionType,
375                              QGenericReturnArgument ret,
376                              QGenericArgument val0 = QGenericArgument(0),
377                              QGenericArgument val1 = QGenericArgument(),
378                              QGenericArgument val2 = QGenericArgument(),
379                              QGenericArgument val3 = QGenericArgument(),
380                              QGenericArgument val4 = QGenericArgument(),
381                              QGenericArgument val5 = QGenericArgument(),
382                              QGenericArgument val6 = QGenericArgument(),
383                              QGenericArgument val7 = QGenericArgument(),
384                              QGenericArgument val8 = QGenericArgument(),
385                              QGenericArgument val9 = QGenericArgument());
386 
387     static inline bool invokeMethod(QObject *obj, const char *member,
388                              QGenericReturnArgument ret,
389                              QGenericArgument val0 = QGenericArgument(0),
390                              QGenericArgument val1 = QGenericArgument(),
391                              QGenericArgument val2 = QGenericArgument(),
392                              QGenericArgument val3 = QGenericArgument(),
393                              QGenericArgument val4 = QGenericArgument(),
394                              QGenericArgument val5 = QGenericArgument(),
395                              QGenericArgument val6 = QGenericArgument(),
396                              QGenericArgument val7 = QGenericArgument(),
397                              QGenericArgument val8 = QGenericArgument(),
398                              QGenericArgument val9 = QGenericArgument())
399     {
400         return invokeMethod(obj, member, Qt::AutoConnection, ret, val0, val1, val2, val3,
401                 val4, val5, val6, val7, val8, val9);
402     }
403 
404     static inline bool invokeMethod(QObject *obj, const char *member,
405                              Qt::ConnectionType type,
406                              QGenericArgument val0 = QGenericArgument(0),
407                              QGenericArgument val1 = QGenericArgument(),
408                              QGenericArgument val2 = QGenericArgument(),
409                              QGenericArgument val3 = QGenericArgument(),
410                              QGenericArgument val4 = QGenericArgument(),
411                              QGenericArgument val5 = QGenericArgument(),
412                              QGenericArgument val6 = QGenericArgument(),
413                              QGenericArgument val7 = QGenericArgument(),
414                              QGenericArgument val8 = QGenericArgument(),
415                              QGenericArgument val9 = QGenericArgument())
416     {
417         return invokeMethod(obj, member, type, QGenericReturnArgument(), val0, val1, val2,
418                                  val3, val4, val5, val6, val7, val8, val9);
419     }
420 
421     static inline bool invokeMethod(QObject *obj, const char *member,
422                              QGenericArgument val0 = QGenericArgument(0),
423                              QGenericArgument val1 = QGenericArgument(),
424                              QGenericArgument val2 = QGenericArgument(),
425                              QGenericArgument val3 = QGenericArgument(),
426                              QGenericArgument val4 = QGenericArgument(),
427                              QGenericArgument val5 = QGenericArgument(),
428                              QGenericArgument val6 = QGenericArgument(),
429                              QGenericArgument val7 = QGenericArgument(),
430                              QGenericArgument val8 = QGenericArgument(),
431                              QGenericArgument val9 = QGenericArgument())
432     {
433         return invokeMethod(obj, member, Qt::AutoConnection, QGenericReturnArgument(), val0,
434                 val1, val2, val3, val4, val5, val6, val7, val8, val9);
435     }
436 
437     QObject *newInstance(QGenericArgument val0 = QGenericArgument(0),
438                          QGenericArgument val1 = QGenericArgument(),
439                          QGenericArgument val2 = QGenericArgument(),
440                          QGenericArgument val3 = QGenericArgument(),
441                          QGenericArgument val4 = QGenericArgument(),
442                          QGenericArgument val5 = QGenericArgument(),
443                          QGenericArgument val6 = QGenericArgument(),
444                          QGenericArgument val7 = QGenericArgument(),
445                          QGenericArgument val8 = QGenericArgument(),
446                          QGenericArgument val9 = QGenericArgument()) const;
447 
448     enum Call {
449         InvokeMetaMethod,
450         ReadProperty,
451         WriteProperty,
452         ResetProperty,
453         QueryPropertyDesignable,
454         QueryPropertyScriptable,
455         QueryPropertyStored,
456         QueryPropertyEditable,
457         QueryPropertyUser,
458         CreateInstance
459     };
460 
461     int static_metacall(Call, int, void **) const;
462     static int metacall(QObject *, Call, int, void **);
463 
464 #ifdef QT3_SUPPORT
465     QT3_SUPPORT const char *superClassName() const;
466 #endif
467 
468     struct { // private data
469         const QMetaObject *superdata;
470         const char *stringdata;
471         const uint *data;
472         const void *extradata;
473     } d;
474 };
475 
476 typedef const QMetaObject& (*QMetaObjectAccessor)();
477 
478 struct QMetaObjectExtraData
479 {
480 #ifdef Q_NO_DATA_RELOCATION
481     const QMetaObjectAccessor *objects;
482 #else
483     const QMetaObject **objects;
484 #endif
485 
486     typedef void (*StaticMetacallFunction)(QObject *, QMetaObject::Call, int, void **); //from revision 6
487     //typedef int (*StaticMetaCall)(QMetaObject::Call, int, void **); //used from revison 2 until revison 5
488     StaticMetacallFunction static_metacall;
489 };
490 
className()491 inline const char *QMetaObject::className() const
492 { return d.stringdata; }
493 
superClass()494 inline const QMetaObject *QMetaObject::superClass() const
495 { return d.superdata; }
496 
497 #ifdef QT3_SUPPORT
superClassName()498 inline const char *QMetaObject::superClassName() const
499 { return d.superdata ? d.superdata->className() : 0; }
500 #endif
501 
502 QT_END_NAMESPACE
503 
504 QT_END_HEADER
505 
506 #endif // QOBJECTDEFS_H
507