From 15a17323ed2f2d19816ce3acc928b7bbb6b86eab Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Fri, 6 Sep 2013 13:03:40 +0200 Subject: [PATCH] Make the automatic 1arg and 2arg metatype macros work with namespaced Qt. Change-Id: I64aa3cacd0cf57235ad43f089716765b384ef412 Reviewed-by: Olivier Goffart --- src/corelib/kernel/qmetatype.h | 17 ++++++++++--- .../corelib/kernel/qvariant/tst_qvariant.cpp | 25 +++++++++++++++++++ 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/corelib/kernel/qmetatype.h b/src/corelib/kernel/qmetatype.h index 80c1f21c0d..57a622ebe5 100644 --- a/src/corelib/kernel/qmetatype.h +++ b/src/corelib/kernel/qmetatype.h @@ -1727,6 +1727,7 @@ typedef QMap QVariantMap; typedef QHash QVariantHash; #define Q_DECLARE_METATYPE_TEMPLATE_1ARG(SINGLE_ARG_TEMPLATE) \ +QT_BEGIN_NAMESPACE \ template \ struct QMetaTypeId< SINGLE_ARG_TEMPLATE > \ { \ @@ -1754,9 +1755,11 @@ struct QMetaTypeId< SINGLE_ARG_TEMPLATE > \ metatype_id.storeRelease(newId); \ return newId; \ } \ -}; +}; \ +QT_END_NAMESPACE #define Q_DECLARE_METATYPE_TEMPLATE_2ARG(DOUBLE_ARG_TEMPLATE) \ +QT_BEGIN_NAMESPACE \ template \ struct QMetaTypeId< DOUBLE_ARG_TEMPLATE > \ { \ @@ -1787,7 +1790,8 @@ struct QMetaTypeId< DOUBLE_ARG_TEMPLATE > \ metatype_id.storeRelease(newId); \ return newId; \ } \ -}; +}; \ +QT_END_NAMESPACE namespace QtPrivate { @@ -1838,7 +1842,7 @@ struct QMetaTypeId< SMART_POINTER > \ QtPrivate::IsPointerToTypeDerivedFromQObject::Value> \ { \ };\ -QT_END_NAMESPACE \ +QT_END_NAMESPACE #define QT_FOR_EACH_AUTOMATIC_TEMPLATE_SMART_POINTER(F) \ F(QSharedPointer) \ @@ -1846,9 +1850,13 @@ QT_END_NAMESPACE \ F(QPointer) #define Q_DECLARE_METATYPE_TEMPLATE_1ARG_ITER(TEMPLATENAME) \ + QT_BEGIN_NAMESPACE \ template class TEMPLATENAME; \ + QT_END_NAMESPACE \ Q_DECLARE_METATYPE_TEMPLATE_1ARG(TEMPLATENAME) +QT_END_NAMESPACE + QT_FOR_EACH_AUTOMATIC_TEMPLATE_1ARG(Q_DECLARE_METATYPE_TEMPLATE_1ARG_ITER) #undef Q_DECLARE_METATYPE_TEMPLATE_1ARG_ITER @@ -1857,7 +1865,9 @@ Q_DECLARE_METATYPE_TEMPLATE_1ARG(std::vector) Q_DECLARE_METATYPE_TEMPLATE_1ARG(std::list) #define Q_DECLARE_METATYPE_TEMPLATE_2ARG_ITER(TEMPLATENAME, CPPTYPE) \ + QT_BEGIN_NAMESPACE \ template CPPTYPE TEMPLATENAME; \ + QT_END_NAMESPACE \ Q_DECLARE_METATYPE_TEMPLATE_2ARG(TEMPLATENAME) QT_FOR_EACH_AUTOMATIC_TEMPLATE_2ARG(Q_DECLARE_METATYPE_TEMPLATE_2ARG_ITER) @@ -1870,7 +1880,6 @@ Q_DECLARE_METATYPE_TEMPLATE_2ARG(std::map) #define Q_DECLARE_METATYPE_TEMPLATE_SMART_POINTER_ITER(TEMPLATENAME) \ Q_DECLARE_SMART_POINTER_METATYPE(TEMPLATENAME) -QT_END_NAMESPACE QT_FOR_EACH_AUTOMATIC_TEMPLATE_SMART_POINTER(Q_DECLARE_METATYPE_TEMPLATE_SMART_POINTER_ITER) diff --git a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp index 0b50bc7576..eab2ba4f36 100644 --- a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp +++ b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp @@ -2275,10 +2275,26 @@ public: T* operator->() const { return pointer; } }; +template +struct SequentialContainer +{ + T t; +}; + +template +struct AssociativeContainer +{ + T t; + U u; +}; + } Q_DECLARE_SMART_POINTER_METATYPE(MyNS::SmartPointer) +Q_DECLARE_METATYPE_TEMPLATE_1ARG(MyNS::SequentialContainer) +Q_DECLARE_METATYPE_TEMPLATE_2ARG(MyNS::AssociativeContainer) + Q_DECLARE_METATYPE(MyNS::SmartPointer) void tst_QVariant::qvariant_cast_QObject_wrapper() @@ -2292,6 +2308,15 @@ void tst_QVariant::qvariant_cast_QObject_wrapper() v.convert(qMetaTypeId()); QCOMPARE(v.value(), object); + MyNS::SequentialContainer sc; + sc.t = 47; + MyNS::AssociativeContainer ac; + ac.t = 42; + ac.u = 5; + + QVariant::fromValue(sc); + QVariant::fromValue(ac); + // Compile tests: qRegisterMetaType >(); // Not declared as a metatype: