Fix QMetaType::metaObjectForType for QtGui and QtWidgets types

Follow the same convention as other functions using the QMetaTypeSwitcher

It was not a problem since none of the built-ins type in QtWidgets
or QtGui were pointer and could not have a QMetaObject. But since
we want to register the metaobject for Q_GADGET, it would fail compilation
as types like QFont are not defined in QtCore.

Change-Id: I6307bf6f25439ed48355ef7ecfa60575de318a25
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
bb10
Olivier Goffart 2014-10-31 22:38:56 +01:00
parent 2e207e2943
commit 3ad7742b28
1 changed files with 20 additions and 1 deletions

View File

@ -1982,8 +1982,27 @@ public:
MetaObject(const int type)
: m_type(type)
{}
template<typename T, bool IsAcceptedType = DefinedTypesFilter::Acceptor<T>::IsAccepted>
struct MetaObjectImpl
{
static const QMetaObject *MetaObject(int /*type*/)
{ return QtPrivate::MetaObjectForType<T>::value(); }
};
template<typename T>
const QMetaObject *delegate(const T*) { return QtPrivate::MetaObjectForType<T>::value(); }
struct MetaObjectImpl<T, /* IsAcceptedType = */ false>
{
static const QMetaObject *MetaObject(int type) {
if (QModulesPrivate::QTypeModuleInfo<T>::IsGui)
return Q_LIKELY(qMetaTypeGuiHelper) ? qMetaTypeGuiHelper[type - QMetaType::FirstGuiType].metaObject : 0;
if (QModulesPrivate::QTypeModuleInfo<T>::IsWidget)
return Q_LIKELY(qMetaTypeWidgetsHelper) ? qMetaTypeWidgetsHelper[type - QMetaType::FirstWidgetsType].metaObject : 0;
return 0;
}
};
template <typename T>
const QMetaObject *delegate(const T *) { return MetaObjectImpl<T>::MetaObject(m_type); }
const QMetaObject *delegate(const void*) { return 0; }
const QMetaObject *delegate(const QMetaTypeSwitcher::UnknownType*) { return 0; }
const QMetaObject *delegate(const QMetaTypeSwitcher::NotBuiltinType*) { return customMetaObject(m_type); }