From 4b8ceb41aed352f10d36db5284453f425dbc5f3f Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Fri, 30 Dec 2011 12:00:09 +0100 Subject: 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 --- .../corelib/kernel/qmetatype/tst_qmetatype.cpp | 39 +++++++++++++++++++--- .../auto/corelib/kernel/qvariant/tst_qvariant.cpp | 5 +++ .../tst_exceptionsafety_objects.cpp | 5 +++ tests/benchmarks/corelib/tools/qstring/main.cpp | 15 +++++++++ 4 files changed, 60 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp index 3107fe49d9..de93c21d43 100644 --- a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp +++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp @@ -596,21 +596,50 @@ Q_DECLARE_TYPEINFO(CustomMovable, Q_MOVABLE_TYPE); QT_END_NAMESPACE Q_DECLARE_METATYPE(CustomMovable); +class CustomObject : public QObject +{ + Q_OBJECT +public: + CustomObject(QObject *parent = 0) + : QObject(parent) + { + + } +}; +Q_DECLARE_METATYPE(CustomObject*); + +struct SecondBase {}; + +class CustomMultiInheritanceObject : public QObject, SecondBase +{ + Q_OBJECT +public: + CustomMultiInheritanceObject(QObject *parent = 0) + : QObject(parent) + { + + } +}; +Q_DECLARE_METATYPE(CustomMultiInheritanceObject*); + void tst_QMetaType::flags_data() { QTest::addColumn("type"); QTest::addColumn("isMovable"); QTest::addColumn("isComplex"); + QTest::addColumn("isPointerToQObject"); #define ADD_METATYPE_TEST_ROW(MetaTypeName, MetaTypeId, RealType) \ - QTest::newRow(#RealType) << MetaTypeId << bool(!QTypeInfo::isStatic) << bool(QTypeInfo::isComplex); + QTest::newRow(#RealType) << MetaTypeId << bool(!QTypeInfo::isStatic) << bool(QTypeInfo::isComplex) << bool(QtPrivate::IsPointerToTypeDerivedFromQObject::Value); QT_FOR_EACH_STATIC_CORE_CLASS(ADD_METATYPE_TEST_ROW) QT_FOR_EACH_STATIC_PRIMITIVE_POINTER(ADD_METATYPE_TEST_ROW) QT_FOR_EACH_STATIC_CORE_POINTER(ADD_METATYPE_TEST_ROW) #undef ADD_METATYPE_TEST_ROW - QTest::newRow("TestSpace::Foo") << ::qMetaTypeId() << false << true; - QTest::newRow("Whity") << ::qMetaTypeId >() << false << true; - QTest::newRow("CustomMovable") << ::qMetaTypeId() << true << true; + QTest::newRow("TestSpace::Foo") << ::qMetaTypeId() << false << true << false; + QTest::newRow("Whity") << ::qMetaTypeId >() << false << true << false; + QTest::newRow("CustomMovable") << ::qMetaTypeId() << true << true << false; + QTest::newRow("CustomObject*") << ::qMetaTypeId() << true << false << true; + QTest::newRow("CustomMultiInheritanceObject*") << ::qMetaTypeId() << true << false << true; } void tst_QMetaType::flags() @@ -618,10 +647,12 @@ void tst_QMetaType::flags() QFETCH(int, type); QFETCH(bool, isMovable); QFETCH(bool, isComplex); + QFETCH(bool, isPointerToQObject); QCOMPARE(bool(QMetaType::typeFlags(type) & QMetaType::NeedsConstruction), isComplex); QCOMPARE(bool(QMetaType::typeFlags(type) & QMetaType::NeedsDestruction), isComplex); QCOMPARE(bool(QMetaType::typeFlags(type) & QMetaType::MovableType), isMovable); + QCOMPARE(bool(QMetaType::typeFlags(type) & QMetaType::PointerToQObject), isPointerToQObject); } void tst_QMetaType::construct_data() diff --git a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp index f8fa92e244..f40b1eae0b 100644 --- a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp +++ b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp @@ -3324,6 +3324,11 @@ void tst_QVariant::colorInteger() } class Forward; +QT_BEGIN_NAMESPACE namespace QtPrivate { +template <> struct IsPointerToTypeDerivedFromQObject { + enum { Value = false }; +}; +} QT_END_NAMESPACE Q_DECLARE_METATYPE(Forward*); void tst_QVariant::forwardDeclare() diff --git a/tests/auto/other/exceptionsafety_objects/tst_exceptionsafety_objects.cpp b/tests/auto/other/exceptionsafety_objects/tst_exceptionsafety_objects.cpp index 49516b7c9b..65ac276704 100644 --- a/tests/auto/other/exceptionsafety_objects/tst_exceptionsafety_objects.cpp +++ b/tests/auto/other/exceptionsafety_objects/tst_exceptionsafety_objects.cpp @@ -99,6 +99,11 @@ struct AbstractTester Q_DECLARE_METATYPE(AbstractTester *) typedef void (*TestFunction)(QObject*); +QT_BEGIN_NAMESPACE namespace QtPrivate { +template <> struct IsPointerToTypeDerivedFromQObject { + enum { Value = false }; +}; +} QT_END_NAMESPACE Q_DECLARE_METATYPE(TestFunction) template diff --git a/tests/benchmarks/corelib/tools/qstring/main.cpp b/tests/benchmarks/corelib/tools/qstring/main.cpp index be2abe5c51..5ab53e3394 100644 --- a/tests/benchmarks/corelib/tools/qstring/main.cpp +++ b/tests/benchmarks/corelib/tools/qstring/main.cpp @@ -1298,6 +1298,11 @@ static int ucstrncmp_ssse3_aligning2(const ushort *a, const ushort *b, int len) #endif typedef int (* UcstrncmpFunction)(const ushort *, const ushort *, int); +QT_BEGIN_NAMESPACE namespace QtPrivate { +template <> struct IsPointerToTypeDerivedFromQObject { + enum { Value = false }; +}; +} QT_END_NAMESPACE Q_DECLARE_METATYPE(UcstrncmpFunction) void tst_QString::ucstrncmp_data() const @@ -1457,6 +1462,11 @@ void tst_QString::fromLatin1() const } typedef void (* FromLatin1Function)(ushort *, const char *, int); +QT_BEGIN_NAMESPACE namespace QtPrivate { +template <> struct IsPointerToTypeDerivedFromQObject { + enum { Value = false }; +}; +} QT_END_NAMESPACE Q_DECLARE_METATYPE(FromLatin1Function) void fromLatin1_regular(ushort *dst, const char *str, int size) @@ -1907,6 +1917,11 @@ void tst_QString::fromLatin1Alternatives() const } typedef int (* FromUtf8Function)(ushort *, const char *, int); +QT_BEGIN_NAMESPACE namespace QtPrivate { +template <> struct IsPointerToTypeDerivedFromQObject { + enum { Value = false }; +}; +} QT_END_NAMESPACE Q_DECLARE_METATYPE(FromUtf8Function) extern QTextCodec::ConverterState *state; -- cgit v1.2.3