diff options
author | Olivier Goffart <ogoffart@woboq.com> | 2011-11-23 15:03:04 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-11-25 01:12:14 +0100 |
commit | 66b659c8a4a429b483b66fd1a1d1429a2c0d3b4a (patch) | |
tree | c654cac67ca5d6cc2cbd2d41d03b83f5011dc0c3 /src/corelib/kernel/qobject_impl.h | |
parent | 583c55b243d9894d93d32fbe15bece2a9beb1d10 (diff) |
Add support for QueuedConnection when connecting using the new syntax
QMetaCallEvent now can handle a pointer to QSlotObjectBase
Change-Id: I94da1e68ce9bb1fd96a9ae013a389552eb625faa
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/kernel/qobject_impl.h')
-rw-r--r-- | src/corelib/kernel/qobject_impl.h | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/corelib/kernel/qobject_impl.h b/src/corelib/kernel/qobject_impl.h index 7d3dc1659b..9918b1f1c2 100644 --- a/src/corelib/kernel/qobject_impl.h +++ b/src/corelib/kernel/qobject_impl.h @@ -344,6 +344,43 @@ namespace QtPrivate { #endif + /* + Logic to statically generate the array of qMetaTypeId + ConnectionTypes<FunctionPointer<Signal>::Arguments>::types() returns an array + of int that is suitable for the types arguments of the connection functions. + + The array only exist of all the types are declared as a metatype + (detected using the TypesAreDeclaredMetaType helper struct) + If one of the type is not declared, the function return 0 and the signal + cannot be used in queued connection. + */ +#ifndef Q_COMPILER_VARIADIC_TEMPLATES + template <typename ArgList> struct TypesAreDeclaredMetaType { enum { Value = false }; }; + template <> struct TypesAreDeclaredMetaType<void> { enum { Value = true }; }; + template <typename Arg, typename Tail> struct TypesAreDeclaredMetaType<List<Arg, Tail> > { enum { Value = QMetaTypeId2<Arg>::Defined && TypesAreDeclaredMetaType<Tail>::Value }; }; + + template <typename ArgList, bool Declared = TypesAreDeclaredMetaType<ArgList>::Value > struct ConnectionTypes + { static const int *types() { return 0; } }; + template <> struct ConnectionTypes<void, true> + { static const int *types() { static const int t[1] = { 0 }; return t; } }; + template <typename Arg1> struct ConnectionTypes<List<Arg1, void>, true> + { static const int *types() { static const int t[2] = { QtPrivate::QMetaTypeIdHelper<Arg1>::qt_metatype_id(), 0 }; return t; } }; + template <typename Arg1, typename Arg2> struct ConnectionTypes<List<Arg1, List<Arg2, void> >, true> + { static const int *types() { static const int t[3] = { QtPrivate::QMetaTypeIdHelper<Arg1>::qt_metatype_id(), QtPrivate::QMetaTypeIdHelper<Arg2>::qt_metatype_id(), 0 }; return t; } }; + template <typename Arg1, typename Arg2, typename Arg3> struct ConnectionTypes<List<Arg1, List<Arg2, List<Arg3, void> > >, true> + { static const int *types() { static const int t[4] = { QtPrivate::QMetaTypeIdHelper<Arg1>::qt_metatype_id(), QtPrivate::QMetaTypeIdHelper<Arg2>::qt_metatype_id(), + QtPrivate::QMetaTypeIdHelper<Arg3>::qt_metatype_id(), 0 }; return t; } }; +#else + template <typename ArgList> struct TypesAreDeclaredMetaType { enum { Value = false }; }; + template <> struct TypesAreDeclaredMetaType<List<>> { enum { Value = true }; }; + template <typename Arg, typename... Tail> struct TypesAreDeclaredMetaType<List<Arg, Tail...> > + { enum { Value = QMetaTypeId2<Arg>::Defined && TypesAreDeclaredMetaType<List<Tail...>>::Value }; }; + + template <typename ArgList, bool Declared = TypesAreDeclaredMetaType<ArgList>::Value > struct ConnectionTypes + { static const int *types() { return 0; } }; + template <typename... Args> struct ConnectionTypes<List<Args...>, true> + { static const int *types() { static const int t[sizeof...(Args) + 1] = { (QtPrivate::QMetaTypeIdHelper<Args>::qt_metatype_id())..., 0 }; return t; } }; +#endif } |