Make the automatic 1arg and 2arg metatype macros work with namespaced Qt.

Change-Id: I64aa3cacd0cf57235ad43f089716765b384ef412
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
This commit is contained in:
Stephen Kelly 2013-09-06 13:03:40 +02:00 committed by The Qt Project
parent 2ff15ff065
commit 15a17323ed
2 changed files with 38 additions and 4 deletions

View File

@ -1727,6 +1727,7 @@ typedef QMap<QString, QVariant> QVariantMap;
typedef QHash<QString, QVariant> QVariantHash;
#define Q_DECLARE_METATYPE_TEMPLATE_1ARG(SINGLE_ARG_TEMPLATE) \
QT_BEGIN_NAMESPACE \
template <typename T> \
struct QMetaTypeId< SINGLE_ARG_TEMPLATE<T> > \
{ \
@ -1754,9 +1755,11 @@ struct QMetaTypeId< SINGLE_ARG_TEMPLATE<T> > \
metatype_id.storeRelease(newId); \
return newId; \
} \
};
}; \
QT_END_NAMESPACE
#define Q_DECLARE_METATYPE_TEMPLATE_2ARG(DOUBLE_ARG_TEMPLATE) \
QT_BEGIN_NAMESPACE \
template<typename T, typename U> \
struct QMetaTypeId< DOUBLE_ARG_TEMPLATE<T, U> > \
{ \
@ -1787,7 +1790,8 @@ struct QMetaTypeId< DOUBLE_ARG_TEMPLATE<T, U> > \
metatype_id.storeRelease(newId); \
return newId; \
} \
};
}; \
QT_END_NAMESPACE
namespace QtPrivate {
@ -1838,7 +1842,7 @@ struct QMetaTypeId< SMART_POINTER<T> > \
QtPrivate::IsPointerToTypeDerivedFromQObject<T*>::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 T> 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 <class T1, class T2> 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)

View File

@ -2275,10 +2275,26 @@ public:
T* operator->() const { return pointer; }
};
template<typename T>
struct SequentialContainer
{
T t;
};
template<typename T, typename U>
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<int>)
void tst_QVariant::qvariant_cast_QObject_wrapper()
@ -2292,6 +2308,15 @@ void tst_QVariant::qvariant_cast_QObject_wrapper()
v.convert(qMetaTypeId<QObject*>());
QCOMPARE(v.value<QObject*>(), object);
MyNS::SequentialContainer<int> sc;
sc.t = 47;
MyNS::AssociativeContainer<int, short> ac;
ac.t = 42;
ac.u = 5;
QVariant::fromValue(sc);
QVariant::fromValue(ac);
// Compile tests:
qRegisterMetaType<MyNS::SmartPointer<int> >();
// Not declared as a metatype: