diff options
author | Stephen Kelly <stephen.kelly@kdab.com> | 2011-12-30 12:00:09 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-01-24 15:27:25 +0100 |
commit | 4b8ceb41aed352f10d36db5284453f425dbc5f3f (patch) | |
tree | 6362bc3353107a7d35b7bb1cefb7f1751fe473fe /src/corelib/kernel/qmetatype.h | |
parent | 6efefb3fe5c7c392bc4857d979dee51042a4f043 (diff) |
Store the is-a QObject fact with the metatype declaration.
This is a source incompatible change for Q_DECLARE_METATYPE(T*),
which now requires T to be fully defined.
The consequences of this are:
* Forward declared types can no longer be declared as a metatype.
(though this is a very uncommon thing to do).
There is a trivial workaround where necessary.
Change-Id: Id74c40088b8c0b466fcd7c55abd616f69acc82c8
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Diffstat (limited to 'src/corelib/kernel/qmetatype.h')
-rw-r--r-- | src/corelib/kernel/qmetatype.h | 47 |
1 files changed, 44 insertions, 3 deletions
diff --git a/src/corelib/kernel/qmetatype.h b/src/corelib/kernel/qmetatype.h index e81dbb69d1..7c38d1cd13 100644 --- a/src/corelib/kernel/qmetatype.h +++ b/src/corelib/kernel/qmetatype.h @@ -207,7 +207,8 @@ public: enum TypeFlag { NeedsConstruction = 0x1, NeedsDestruction = 0x2, - MovableType = 0x4 + MovableType = 0x4, + PointerToQObject = 0x8 }; Q_DECLARE_FLAGS(TypeFlags, TypeFlag) @@ -315,6 +316,9 @@ struct QMetaTypeId2 static inline int qt_metatype_id() { return QMetaTypeId<T>::qt_metatype_id(); } }; +class QObject; +class QWidget; + namespace QtPrivate { template <typename T, bool Defined = QMetaTypeId2<T>::Defined> struct QMetaTypeIdHelper { @@ -325,6 +329,43 @@ namespace QtPrivate { static inline int qt_metatype_id() { return -1; } }; + + template<typename T> + struct IsPointerToTypeDerivedFromQObject + { + enum { Value = false }; + }; + + // Specialize to avoid sizeof(void) warning + template<> + struct IsPointerToTypeDerivedFromQObject<void*> + { + enum { Value = false }; + }; + template<> + struct IsPointerToTypeDerivedFromQObject<QObject*> + { + enum { Value = true }; + }; + template<> + struct IsPointerToTypeDerivedFromQObject<QWidget*> + { + enum { Value = true }; + }; + + template<typename T> + struct IsPointerToTypeDerivedFromQObject<T*> + { + typedef qint8 yes_type; + typedef qint64 no_type; + +#ifndef QT_NO_QOBJECT + static yes_type checkType(QObject* ); +#endif + static no_type checkType(...); + Q_STATIC_ASSERT_X(sizeof(T), "Type argument of Q_DECLARE_METATYPE(T*) must be fully defined"); + enum { Value = sizeof(checkType(static_cast<T*>(0))) == sizeof(yes_type) }; + }; } template <typename T> @@ -354,6 +395,8 @@ int qRegisterMetaType(const char *typeName flags |= QMetaType::NeedsConstruction; flags |= QMetaType::NeedsDestruction; } + if (QtPrivate::IsPointerToTypeDerivedFromQObject<T>::Value) + flags |= QMetaType::PointerToQObject; return QMetaType::registerType(typeName, reinterpret_cast<QMetaType::Deleter>(dptr), reinterpret_cast<QMetaType::Creator>(cptr), @@ -459,8 +502,6 @@ QT_FOR_EACH_STATIC_WIDGETS_CLASS(QT_FORWARD_DECLARE_STATIC_TYPES_ITER) #undef QT_FORWARD_DECLARE_STATIC_TYPES_ITER -class QWidget; -class QObject; template <class T> class QList; template <class T1, class T2> class QMap; template <class T1, class T2> class QHash; |