source: trunk/src/corelib/kernel/qobjectdefs.h@ 779

Last change on this file since 779 was 769, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.3 sources from branches/vendor/nokia/qt.

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