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

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

trunk: Merged in qt 4.6.1 sources.

File size: 16.7 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 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_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#ifdef Q_NO_DATA_RELOCATION
149#define Q_OBJECT_GETSTATICMETAOBJECT static const QMetaObject &getStaticMetaObject();
150#else
151#define Q_OBJECT_GETSTATICMETAOBJECT
152#endif
153
154/* tmake ignore Q_OBJECT */
155#define Q_OBJECT \
156public: \
157 Q_OBJECT_CHECK \
158 static const QMetaObject staticMetaObject; \
159 Q_OBJECT_GETSTATICMETAOBJECT \
160 virtual const QMetaObject *metaObject() const; \
161 virtual void *qt_metacast(const char *); \
162 QT_TR_FUNCTIONS \
163 virtual int qt_metacall(QMetaObject::Call, int, void **); \
164private:
165/* tmake ignore Q_OBJECT */
166#define Q_OBJECT_FAKE Q_OBJECT
167/* tmake ignore Q_GADGET */
168#define Q_GADGET \
169public: \
170 static const QMetaObject staticMetaObject; \
171 Q_OBJECT_GETSTATICMETAOBJECT \
172private:
173#else // Q_MOC_RUN
174#define slots slots
175#define signals signals
176#define Q_SLOTS Q_SLOTS
177#define Q_SIGNALS Q_SIGNALS
178#define Q_CLASSINFO(name, value) Q_CLASSINFO(name, value)
179#define Q_INTERFACES(x) Q_INTERFACES(x)
180#define Q_PROPERTY(text) Q_PROPERTY(text)
181#define Q_OVERRIDE(text) Q_OVERRIDE(text)
182#define Q_ENUMS(x) Q_ENUMS(x)
183#define Q_FLAGS(x) Q_FLAGS(x)
184#ifdef QT3_SUPPORT
185# define Q_SETS(x) Q_SETS(x)
186#endif
187 /* tmake ignore Q_OBJECT */
188#define Q_OBJECT Q_OBJECT
189 /* tmake ignore Q_OBJECT */
190#define Q_OBJECT_FAKE Q_OBJECT_FAKE
191 /* tmake ignore Q_GADGET */
192#define Q_GADGET Q_GADGET
193#define Q_SCRIPTABLE Q_SCRIPTABLE
194#define Q_INVOKABLE Q_INVOKABLE
195#define Q_SIGNAL Q_SIGNAL
196#define Q_SLOT Q_SLOT
197#endif //Q_MOC_RUN
198
199// macro for onaming members
200#ifdef METHOD
201#undef METHOD
202#endif
203#ifdef SLOT
204#undef SLOT
205#endif
206#ifdef SIGNAL
207#undef SIGNAL
208#endif
209
210Q_CORE_EXPORT const char *qFlagLocation(const char *method);
211
212#define QTOSTRING_HELPER(s) #s
213#define QTOSTRING(s) QTOSTRING_HELPER(s)
214#ifndef QT_NO_DEBUG
215# define QLOCATION "\0"__FILE__":"QTOSTRING(__LINE__)
216# define METHOD(a) qFlagLocation("0"#a QLOCATION)
217# define SLOT(a) qFlagLocation("1"#a QLOCATION)
218# define SIGNAL(a) qFlagLocation("2"#a QLOCATION)
219#else
220# define METHOD(a) "0"#a
221# define SLOT(a) "1"#a
222# define SIGNAL(a) "2"#a
223#endif
224
225#ifdef QT3_SUPPORT
226#define METHOD_CODE 0 // member type codes
227#define SLOT_CODE 1
228#define SIGNAL_CODE 2
229#endif
230
231#define QMETHOD_CODE 0 // member type codes
232#define QSLOT_CODE 1
233#define QSIGNAL_CODE 2
234
235#define Q_ARG(type, data) QArgument<type >(#type, data)
236#define Q_RETURN_ARG(type, data) QReturnArgument<type >(#type, data)
237
238class QObject;
239class QMetaMethod;
240class QMetaEnum;
241class QMetaProperty;
242class QMetaClassInfo;
243
244
245class Q_CORE_EXPORT QGenericArgument
246{
247public:
248 inline QGenericArgument(const char *aName = 0, const void *aData = 0)
249 : _data(aData), _name(aName) {}
250 inline void *data() const { return const_cast<void *>(_data); }
251 inline const char *name() const { return _name; }
252
253private:
254 const void *_data;
255 const char *_name;
256};
257
258class Q_CORE_EXPORT QGenericReturnArgument: public QGenericArgument
259{
260public:
261 inline QGenericReturnArgument(const char *aName = 0, void *aData = 0)
262 : QGenericArgument(aName, aData)
263 {}
264};
265
266template <class T>
267class QArgument: public QGenericArgument
268{
269public:
270 inline QArgument(const char *aName, const T &aData)
271 : QGenericArgument(aName, static_cast<const void *>(&aData))
272 {}
273};
274
275
276template <typename T>
277class QReturnArgument: public QGenericReturnArgument
278{
279public:
280 inline QReturnArgument(const char *aName, T &aData)
281 : QGenericReturnArgument(aName, static_cast<void *>(&aData))
282 {}
283};
284
285struct Q_CORE_EXPORT QMetaObject
286{
287 const char *className() const;
288 const QMetaObject *superClass() const;
289
290 QObject *cast(QObject *obj) const;
291
292#ifndef QT_NO_TRANSLATION
293 // ### Qt 4: Merge overloads
294 QString tr(const char *s, const char *c) const;
295 QString trUtf8(const char *s, const char *c) const;
296 QString tr(const char *s, const char *c, int n) const;
297 QString trUtf8(const char *s, const char *c, int n) const;
298#endif // QT_NO_TRANSLATION
299
300 int methodOffset() const;
301 int enumeratorOffset() const;
302 int propertyOffset() const;
303 int classInfoOffset() const;
304
305 int constructorCount() const;
306 int methodCount() const;
307 int enumeratorCount() const;
308 int propertyCount() const;
309 int classInfoCount() const;
310
311 int indexOfConstructor(const char *constructor) const;
312 int indexOfMethod(const char *method) const;
313 int indexOfSignal(const char *signal) const;
314 int indexOfSlot(const char *slot) const;
315 int indexOfEnumerator(const char *name) const;
316 int indexOfProperty(const char *name) const;
317 int indexOfClassInfo(const char *name) const;
318
319 QMetaMethod constructor(int index) const;
320 QMetaMethod method(int index) const;
321 QMetaEnum enumerator(int index) const;
322 QMetaProperty property(int index) const;
323 QMetaClassInfo classInfo(int index) const;
324 QMetaProperty userProperty() const;
325
326 static bool checkConnectArgs(const char *signal, const char *method);
327 static QByteArray normalizedSignature(const char *method);
328 static QByteArray normalizedType(const char *type);
329
330 // internal index-based connect
331 static bool connect(const QObject *sender, int signal_index,
332 const QObject *receiver, int method_index,
333 int type = 0, int *types = 0);
334 // internal index-based disconnect
335 static bool disconnect(const QObject *sender, int signal_index,
336 const QObject *receiver, int method_index);
337 // internal slot-name based connect
338 static void connectSlotsByName(QObject *o);
339
340 // internal index-based signal activation
341 static void activate(QObject *sender, int signal_index, void **argv); //obsolete
342 static void activate(QObject *sender, int from_signal_index, int to_signal_index, void **argv); //obsolete
343 static void activate(QObject *sender, const QMetaObject *, int local_signal_index, void **argv);
344 static void activate(QObject *sender, const QMetaObject *, int from_local_signal_index, int to_local_signal_index, void **argv); //obsolete
345
346 // internal guarded pointers
347 static void addGuard(QObject **ptr);
348 static void removeGuard(QObject **ptr);
349 static void changeGuard(QObject **ptr, QObject *o);
350
351 static bool invokeMethod(QObject *obj, const char *member,
352 Qt::ConnectionType,
353 QGenericReturnArgument ret,
354 QGenericArgument val0 = QGenericArgument(0),
355 QGenericArgument val1 = QGenericArgument(),
356 QGenericArgument val2 = QGenericArgument(),
357 QGenericArgument val3 = QGenericArgument(),
358 QGenericArgument val4 = QGenericArgument(),
359 QGenericArgument val5 = QGenericArgument(),
360 QGenericArgument val6 = QGenericArgument(),
361 QGenericArgument val7 = QGenericArgument(),
362 QGenericArgument val8 = QGenericArgument(),
363 QGenericArgument val9 = QGenericArgument());
364
365 static inline bool invokeMethod(QObject *obj, const char *member,
366 QGenericReturnArgument ret,
367 QGenericArgument val0 = QGenericArgument(0),
368 QGenericArgument val1 = QGenericArgument(),
369 QGenericArgument val2 = QGenericArgument(),
370 QGenericArgument val3 = QGenericArgument(),
371 QGenericArgument val4 = QGenericArgument(),
372 QGenericArgument val5 = QGenericArgument(),
373 QGenericArgument val6 = QGenericArgument(),
374 QGenericArgument val7 = QGenericArgument(),
375 QGenericArgument val8 = QGenericArgument(),
376 QGenericArgument val9 = QGenericArgument())
377 {
378 return invokeMethod(obj, member, Qt::AutoConnection, ret, val0, val1, val2, val3,
379 val4, val5, val6, val7, val8, val9);
380 }
381
382 static inline bool invokeMethod(QObject *obj, const char *member,
383 Qt::ConnectionType type,
384 QGenericArgument val0 = QGenericArgument(0),
385 QGenericArgument val1 = QGenericArgument(),
386 QGenericArgument val2 = QGenericArgument(),
387 QGenericArgument val3 = QGenericArgument(),
388 QGenericArgument val4 = QGenericArgument(),
389 QGenericArgument val5 = QGenericArgument(),
390 QGenericArgument val6 = QGenericArgument(),
391 QGenericArgument val7 = QGenericArgument(),
392 QGenericArgument val8 = QGenericArgument(),
393 QGenericArgument val9 = QGenericArgument())
394 {
395 return invokeMethod(obj, member, type, QGenericReturnArgument(), val0, val1, val2,
396 val3, val4, val5, val6, val7, val8, val9);
397 }
398
399 static inline bool invokeMethod(QObject *obj, const char *member,
400 QGenericArgument val0 = QGenericArgument(0),
401 QGenericArgument val1 = QGenericArgument(),
402 QGenericArgument val2 = QGenericArgument(),
403 QGenericArgument val3 = QGenericArgument(),
404 QGenericArgument val4 = QGenericArgument(),
405 QGenericArgument val5 = QGenericArgument(),
406 QGenericArgument val6 = QGenericArgument(),
407 QGenericArgument val7 = QGenericArgument(),
408 QGenericArgument val8 = QGenericArgument(),
409 QGenericArgument val9 = QGenericArgument())
410 {
411 return invokeMethod(obj, member, Qt::AutoConnection, QGenericReturnArgument(), val0,
412 val1, val2, val3, val4, val5, val6, val7, val8, val9);
413 }
414
415 QObject *newInstance(QGenericArgument val0 = QGenericArgument(0),
416 QGenericArgument val1 = QGenericArgument(),
417 QGenericArgument val2 = QGenericArgument(),
418 QGenericArgument val3 = QGenericArgument(),
419 QGenericArgument val4 = QGenericArgument(),
420 QGenericArgument val5 = QGenericArgument(),
421 QGenericArgument val6 = QGenericArgument(),
422 QGenericArgument val7 = QGenericArgument(),
423 QGenericArgument val8 = QGenericArgument(),
424 QGenericArgument val9 = QGenericArgument()) const;
425
426 enum Call {
427 InvokeMetaMethod,
428 ReadProperty,
429 WriteProperty,
430 ResetProperty,
431 QueryPropertyDesignable,
432 QueryPropertyScriptable,
433 QueryPropertyStored,
434 QueryPropertyEditable,
435 QueryPropertyUser,
436 CreateInstance
437 };
438
439 int static_metacall(Call, int, void **) const;
440 static int metacall(QObject *, Call, int, void **);
441
442#ifdef QT3_SUPPORT
443 QT3_SUPPORT const char *superClassName() const;
444#endif
445
446 struct { // private data
447 const QMetaObject *superdata;
448 const char *stringdata;
449 const uint *data;
450 const void *extradata;
451 } d;
452
453};
454
455typedef const QMetaObject& (*QMetaObjectAccessor)();
456
457struct QMetaObjectExtraData
458{
459#ifdef Q_NO_DATA_RELOCATION
460 const QMetaObjectAccessor *objects;
461#else
462 const QMetaObject **objects;
463#endif
464 int (*static_metacall)(QMetaObject::Call, int, void **);
465};
466
467inline const char *QMetaObject::className() const
468{ return d.stringdata; }
469
470inline const QMetaObject *QMetaObject::superClass() const
471{ return d.superdata; }
472
473#ifdef QT3_SUPPORT
474inline const char *QMetaObject::superClassName() const
475{ return d.superdata ? d.superdata->className() : 0; }
476#endif
477
478QT_END_NAMESPACE
479
480QT_END_HEADER
481
482#endif // QOBJECTDEFS_H
Note: See TracBrowser for help on using the repository browser.