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

Last change on this file since 72 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

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