src/corelib/kernel/qobjectdefs.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 1992-2006 Trolltech ASA. All rights reserved.
00004 **
00005 ** This file is part of the QtCore module of the Qt Toolkit.
00006 **
00007 ** This file may be used under the terms of the GNU General Public
00008 ** License version 2.0 as published by the Free Software Foundation
00009 ** and appearing in the file LICENSE.GPL included in the packaging of
00010 ** this file.  Please review the following information to ensure GNU
00011 ** General Public Licensing requirements will be met:
00012 ** http://www.trolltech.com/products/qt/opensource.html
00013 **
00014 ** If you are unsure which license is appropriate for your use, please
00015 ** review the following information:
00016 ** http://www.trolltech.com/products/qt/licensing.html or contact the
00017 ** sales department at sales@trolltech.com.
00018 **
00019 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00020 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00021 **
00022 ****************************************************************************/
00023 
00024 #ifndef QOBJECTDEFS_H
00025 #define QOBJECTDEFS_H
00026 
00027 #include <QtCore/qnamespace.h>
00028 
00029 QT_BEGIN_HEADER
00030 
00031 QT_MODULE(Core)
00032 
00033 class QString;
00034 
00035 class QByteArray;
00036 
00037 #ifndef Q_MOC_OUTPUT_REVISION
00038 #define Q_MOC_OUTPUT_REVISION 59
00039 #endif
00040 
00041 // The following macros are our "extensions" to C++
00042 // They are used, strictly speaking, only by the moc.
00043 
00044 #ifndef Q_MOC_RUN
00045 # if defined(QT_NO_KEYWORDS)
00046 #  define QT_NO_EMIT
00047 # else
00048 #   define slots
00049 #   define signals protected
00050 # endif
00051 # define Q_SLOTS
00052 # define Q_SIGNALS protected
00053 # define Q_PRIVATE_SLOT(d, signature)
00054 #ifndef QT_NO_EMIT
00055 # define emit
00056 #endif
00057 #define Q_CLASSINFO(name, value)
00058 #define Q_INTERFACES(x)
00059 #define Q_PROPERTY(text)
00060 #define Q_OVERRIDE(text)
00061 #define Q_ENUMS(x)
00062 #define Q_FLAGS(x)
00063 #ifdef QT3_SUPPORT
00064 # define Q_SETS(x)
00065 #endif
00066 #define Q_SCRIPTABLE
00067 #define Q_INVOKABLE
00068 
00069 #ifndef QT_NO_TRANSLATION
00070 # ifndef QT_NO_TEXTCODEC
00071 // full set of tr functions
00072 // ### Qt 5: merge overloads
00073 #  define QT_TR_FUNCTIONS \
00074     static inline QString tr(const char *s, const char *c = 0) \
00075         { return staticMetaObject.tr(s, c); } \
00076     static inline QString trUtf8(const char *s, const char *c = 0) \
00077         { return staticMetaObject.trUtf8(s, c); } \
00078     static inline QString tr(const char *s, const char *c, int n) \
00079         { return staticMetaObject.tr(s, c, n); } \
00080     static inline QString trUtf8(const char *s, const char *c, int n) \
00081         { return staticMetaObject.trUtf8(s, c, n); }
00082 # else
00083 // no QTextCodec, no utf8
00084 // ### Qt 5: merge overloads
00085 #  define QT_TR_FUNCTIONS \
00086     static inline QString tr(const char *s, const char *c = 0) \
00087         { return staticMetaObject.tr(s, c); } \
00088     static inline QString tr(const char *s, const char *c, int n) \
00089         { return staticMetaObject.tr(s, c, n); }
00090 # endif
00091 #else
00092 // inherit the ones from QObject
00093 # define QT_TR_FUNCTIONS
00094 #endif
00095 
00096 /* tmake ignore Q_OBJECT */
00097 #define Q_OBJECT \
00098 public: \
00099     static const QMetaObject staticMetaObject; \
00100     virtual const QMetaObject *metaObject() const; \
00101     virtual void *qt_metacast(const char *); \
00102     QT_TR_FUNCTIONS \
00103     virtual int qt_metacall(QMetaObject::Call, int, void **); \
00104 private:
00105 /* tmake ignore Q_OBJECT */
00106 #define Q_OBJECT_FAKE Q_OBJECT
00107 /* tmake ignore Q_GADGET */
00108 #define Q_GADGET \
00109 public: \
00110     static const QMetaObject staticMetaObject; \
00111 private:
00112 #else // Q_MOC_RUN
00113 #define slots slots
00114 #define signals signals
00115 #define Q_SLOTS Q_SLOTS
00116 #define Q_SIGNALS Q_SIGNALS
00117 #define Q_CLASSINFO(name, value) Q_CLASSINFO(name, value)
00118 #define Q_INTERFACES(x) Q_INTERFACES(x)
00119 #define Q_PROPERTY(text) Q_PROPERTY(text)
00120 #define Q_OVERRIDE(text) Q_OVERRIDE(text)
00121 #define Q_ENUMS(x) Q_ENUMS(x)
00122 #define Q_FLAGS(x) Q_FLAGS(x)
00123 #ifdef QT3_SUPPORT
00124 # define Q_SETS(x) Q_SETS(x)
00125 #endif
00126  /* tmake ignore Q_OBJECT */
00127 #define Q_OBJECT Q_OBJECT
00128  /* tmake ignore Q_OBJECT */
00129 #define Q_OBJECT_FAKE Q_OBJECT_FAKE
00130  /* tmake ignore Q_GADGET */
00131 #define Q_GADGET Q_GADGET
00132 #define Q_SCRIPTABLE Q_SCRIPTABLE
00133 #define Q_INVOKABLE Q_INVOKABLE
00134 #endif //Q_MOC_RUN
00135 
00136 // macro for onaming members
00137 #ifdef METHOD
00138 #undef METHOD
00139 #endif
00140 #ifdef SLOT
00141 #undef SLOT
00142 #endif
00143 #ifdef SIGNAL
00144 #undef SIGNAL
00145 #endif
00146 
00147 #define METHOD(a)        "0"#a
00148 #define SLOT(a)                "1"#a
00149 #define SIGNAL(a)        "2"#a
00150 
00151 #ifdef QT3_SUPPORT
00152 #define METHOD_CODE        0                        // member type codes
00153 #define SLOT_CODE        1
00154 #define SIGNAL_CODE        2
00155 #endif
00156 
00157 #define QMETHOD_CODE        0                        // member type codes
00158 #define QSLOT_CODE        1
00159 #define QSIGNAL_CODE        2
00160 
00161 #define Q_ARG(type, data) QArgument<type >(#type, data)
00162 #define Q_RETURN_ARG(type, data) QReturnArgument<type >(#type, data)
00163 
00164 class QObject;
00165 class QMetaMethod;
00166 class QMetaEnum;
00167 class QMetaProperty;
00168 class QMetaClassInfo;
00169 
00170 
00171 class Q_CORE_EXPORT QGenericArgument
00172 {
00173 public:
00174     inline QGenericArgument(const char *aName = 0, const void *aData = 0)
00175         : _data(aData), _name(aName) {}
00176     inline void *data() const { return const_cast<void *>(_data); }
00177     inline const char *name() const { return _name; }
00178 
00179 private:
00180     const void *_data;
00181     const char *_name;
00182 };
00183 
00184 class Q_CORE_EXPORT QGenericReturnArgument: public QGenericArgument
00185 {
00186 public:
00187     inline QGenericReturnArgument(const char *aName = 0, void *aData = 0)
00188         : QGenericArgument(aName, aData)
00189         {}
00190 };
00191 
00192 template <class T>
00193 class QArgument: public QGenericArgument
00194 {
00195 public:
00196     inline QArgument(const char *aName, const T &aData)
00197         : QGenericArgument(aName, static_cast<const void *>(&aData))
00198         {}
00199 };
00200 
00201 
00202 template <typename T>
00203 class QReturnArgument: public QGenericReturnArgument
00204 {
00205 public:
00206     inline QReturnArgument(const char *aName, T &aData)
00207         : QGenericReturnArgument(aName, static_cast<void *>(&aData))
00208         {}
00209 };
00210 
00211 struct Q_CORE_EXPORT QMetaObject
00212 {
00213     const char *className() const;
00214     const QMetaObject *superClass() const;
00215 
00216     QObject *cast(QObject *obj) const;
00217 
00218 #ifndef QT_NO_TRANSLATION
00219     // ### Qt 4: Merge overloads
00220     QString tr(const char *s, const char *c) const;
00221     QString trUtf8(const char *s, const char *c) const;
00222     QString tr(const char *s, const char *c, int n) const;
00223     QString trUtf8(const char *s, const char *c, int n) const;
00224 #endif // QT_NO_TRANSLATION
00225 
00226     int methodOffset() const;
00227     int enumeratorOffset() const;
00228     int propertyOffset() const;
00229     int classInfoOffset() const;
00230 
00231     int methodCount() const;
00232     int enumeratorCount() const;
00233     int propertyCount() const;
00234     int classInfoCount() const;
00235 
00236     int indexOfMethod(const char *method) const;
00237     int indexOfSignal(const char *signal) const;
00238     int indexOfSlot(const char *slot) const;
00239     int indexOfEnumerator(const char *name) const;
00240     int indexOfProperty(const char *name) const;
00241     int indexOfClassInfo(const char *name) const;
00242 
00243     QMetaMethod method(int index) const;
00244     QMetaEnum enumerator(int index) const;
00245     QMetaProperty property(int index) const;
00246     QMetaClassInfo classInfo(int index) const;
00247     QMetaProperty userProperty() const;
00248 
00249     static bool checkConnectArgs(const char *signal, const char *method);
00250     static QByteArray normalizedSignature(const char *method);
00251     static QByteArray normalizedType(const char *type);
00252 
00253     // internal index-based connect
00254     static bool connect(const QObject *sender, int signal_index,
00255                         const QObject *receiver, int method_index,
00256                         int type = 0, int *types = 0);
00257     // internal index-based disconnect
00258     static bool disconnect(const QObject *sender, int signal_index,
00259                            const QObject *receiver, int method_index);
00260     // internal slot-name based connect
00261     static void connectSlotsByName(QObject *o);
00262 
00263     // internal index-based signal activation
00264     static void activate(QObject *sender, int signal_index, void **argv);
00265     static void activate(QObject *sender, int from_signal_index, int to_signal_index, void **argv);
00266     static void activate(QObject *sender, const QMetaObject *, int local_signal_index, void **argv);
00267     static void activate(QObject *sender, const QMetaObject *, int from_local_signal_index, int to_local_signal_index, void **argv);
00268     // internal guarded pointers
00269     static void addGuard(QObject **ptr);
00270     static void removeGuard(QObject **ptr);
00271     static void changeGuard(QObject **ptr, QObject *o);
00272 
00273     static bool invokeMethod(QObject *obj, const char *member,
00274                              Qt::ConnectionType,
00275                              QGenericReturnArgument ret,
00276                              QGenericArgument val0 = QGenericArgument(0),
00277                              QGenericArgument val1 = QGenericArgument(),
00278                              QGenericArgument val2 = QGenericArgument(),
00279                              QGenericArgument val3 = QGenericArgument(),
00280                              QGenericArgument val4 = QGenericArgument(),
00281                              QGenericArgument val5 = QGenericArgument(),
00282                              QGenericArgument val6 = QGenericArgument(),
00283                              QGenericArgument val7 = QGenericArgument(),
00284                              QGenericArgument val8 = QGenericArgument(),
00285                              QGenericArgument val9 = QGenericArgument());
00286 
00287     static inline bool invokeMethod(QObject *obj, const char *member,
00288                              QGenericReturnArgument ret,
00289                              QGenericArgument val0 = QGenericArgument(0),
00290                              QGenericArgument val1 = QGenericArgument(),
00291                              QGenericArgument val2 = QGenericArgument(),
00292                              QGenericArgument val3 = QGenericArgument(),
00293                              QGenericArgument val4 = QGenericArgument(),
00294                              QGenericArgument val5 = QGenericArgument(),
00295                              QGenericArgument val6 = QGenericArgument(),
00296                              QGenericArgument val7 = QGenericArgument(),
00297                              QGenericArgument val8 = QGenericArgument(),
00298                              QGenericArgument val9 = QGenericArgument())
00299     {
00300         return invokeMethod(obj, member, Qt::AutoConnection, ret, val0, val1, val2, val3,
00301                 val4, val5, val6, val7, val8, val9);
00302     }
00303 
00304     static inline bool invokeMethod(QObject *obj, const char *member,
00305                              Qt::ConnectionType type,
00306                              QGenericArgument val0 = QGenericArgument(0),
00307                              QGenericArgument val1 = QGenericArgument(),
00308                              QGenericArgument val2 = QGenericArgument(),
00309                              QGenericArgument val3 = QGenericArgument(),
00310                              QGenericArgument val4 = QGenericArgument(),
00311                              QGenericArgument val5 = QGenericArgument(),
00312                              QGenericArgument val6 = QGenericArgument(),
00313                              QGenericArgument val7 = QGenericArgument(),
00314                              QGenericArgument val8 = QGenericArgument(),
00315                              QGenericArgument val9 = QGenericArgument())
00316     {
00317         return invokeMethod(obj, member, type, QGenericReturnArgument(), val0, val1, val2,
00318                                  val3, val4, val5, val6, val7, val8, val9);
00319     }
00320 
00321 
00322     static inline bool invokeMethod(QObject *obj, const char *member,
00323                              QGenericArgument val0 = QGenericArgument(0),
00324                              QGenericArgument val1 = QGenericArgument(),
00325                              QGenericArgument val2 = QGenericArgument(),
00326                              QGenericArgument val3 = QGenericArgument(),
00327                              QGenericArgument val4 = QGenericArgument(),
00328                              QGenericArgument val5 = QGenericArgument(),
00329                              QGenericArgument val6 = QGenericArgument(),
00330                              QGenericArgument val7 = QGenericArgument(),
00331                              QGenericArgument val8 = QGenericArgument(),
00332                              QGenericArgument val9 = QGenericArgument())
00333     {
00334         return invokeMethod(obj, member, Qt::AutoConnection, QGenericReturnArgument(), val0,
00335                 val1, val2, val3, val4, val5, val6, val7, val8, val9);
00336     }
00337 
00338     enum Call {
00339         InvokeMetaMethod,
00340         ReadProperty,
00341         WriteProperty,
00342         ResetProperty,
00343         QueryPropertyDesignable,
00344         QueryPropertyScriptable,
00345         QueryPropertyStored,
00346         QueryPropertyEditable,
00347         QueryPropertyUser
00348     };
00349 
00350 #ifdef QT3_SUPPORT
00351     QT3_SUPPORT const char *superClassName() const;
00352 #endif
00353 
00354     struct { // private data
00355         const QMetaObject *superdata;
00356         const char *stringdata;
00357         const uint *data;
00358         const QMetaObject **extradata;
00359     } d;
00360 };
00361 
00362 inline const char *QMetaObject::className() const
00363 { return d.stringdata; }
00364 
00365 inline const QMetaObject *QMetaObject::superClass() const
00366 { return d.superdata; }
00367 
00368 #ifdef QT3_SUPPORT
00369 inline const char *QMetaObject::superClassName() const
00370 { return d.superdata ? d.superdata->className() : 0; }
00371 #endif
00372 
00373 QT_END_HEADER
00374 
00375 #endif // QOBJECTDEFS_H

Generated on Thu Mar 15 11:53:34 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1