summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/corelib/kernel/qmetatype.cpp22
-rw-r--r--src/corelib/kernel/qmetatype.h22
-rw-r--r--src/corelib/kernel/qobjectdefs.h1
3 files changed, 38 insertions, 7 deletions
diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp
index 63f181cdac..ee86867249 100644
--- a/src/corelib/kernel/qmetatype.cpp
+++ b/src/corelib/kernel/qmetatype.cpp
@@ -283,10 +283,11 @@ struct DefinedTypesFilter {
\value MovableType An instance of a type having this attribute can be safely moved by memcpy.
\omitvalue SharedPointerToQObject
\omitvalue IsEnumeration
- \omitvalue PointerToQObject
+ \value PointerToQObject This type is a pointer to a derived of QObject
\omitvalue WeakPointerToQObject
\omitvalue TrackingPointerToQObject
\omitvalue WasDeclaredAsMetaType
+ \value IsGadget This type is a Q_GADGET and it's corresponding QMetaObject can be accessed with QMetaType::metaObject Since 5.5.
*/
/*!
@@ -363,8 +364,19 @@ struct DefinedTypesFilter {
/*!
\fn const QMetaObject *QMetaType::metaObject() const
- \since 5.0
- \internal
+ \since 5.5
+
+ return a QMetaObject relative to this type.
+
+ If the type is a pointer type to a subclass of QObject, flags contains
+ QMetaType::PointerToQObject and this function returns the corresponding QMetaObject. This can
+ be used to in combinaison with QMetaObject::construct to create QObject of this type.
+
+ If the type is a Q_GADGET, flags contains QMetaType::IsGadget, and this function returns its
+ QMetaObject. This can be used to retrieve QMetaMethod and QMetaProperty and use them on a
+ pointer of this type. (given by QVariant::data for example)
+
+ \sa QMetaType::metaObjectForType(), QMetaType::flags()
*/
/*!
@@ -2025,7 +2037,9 @@ private:
/*!
\since 5.0
- Returns QMetaObject of a given \a type, if the \a type is a pointer to type derived from QObject.
+ returns QMetaType::metaObject for \a type
+
+ \sa metaObject()
*/
const QMetaObject *QMetaType::metaObjectForType(int type)
{
diff --git a/src/corelib/kernel/qmetatype.h b/src/corelib/kernel/qmetatype.h
index 947bf77796..dc7e7e0395 100644
--- a/src/corelib/kernel/qmetatype.h
+++ b/src/corelib/kernel/qmetatype.h
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Olivier Goffart <ogoffart@woboq.com>
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtCore module of the Qt Toolkit.
@@ -435,7 +436,8 @@ public:
SharedPointerToQObject = 0x20,
WeakPointerToQObject = 0x40,
TrackingPointerToQObject = 0x80,
- WasDeclaredAsMetaType = 0x100
+ WasDeclaredAsMetaType = 0x100,
+ IsGadget = 0x200
};
Q_DECLARE_FLAGS(TypeFlags, TypeFlag)
@@ -1335,14 +1337,27 @@ namespace QtPrivate
enum { Value = sizeof(checkType(static_cast<T*>(0))) == sizeof(yes_type) };
};
- template<typename T, bool = IsPointerToTypeDerivedFromQObject<T>::Value>
+ template<typename T>
+ struct IsGadgetHelper
+ {
+ template<typename X> static typename X::QtGadgetHelper *checkType(X*);
+ static char checkType(void*);
+ enum { Value = sizeof(checkType(static_cast<T*>(0))) == sizeof(void*) };
+ };
+
+ template<typename T, typename Enable = void>
struct MetaObjectForType
{
static inline const QMetaObject *value() { return 0; }
};
template<typename T>
- struct MetaObjectForType<T*, /* isPointerToTypeDerivedFromQObject = */ true>
+ struct MetaObjectForType<T*, typename QEnableIf<IsPointerToTypeDerivedFromQObject<T*>::Value>::Type>
+ {
+ static inline const QMetaObject *value() { return &T::staticMetaObject; }
+ };
+ template<typename T>
+ struct MetaObjectForType<T, typename QEnableIf<IsGadgetHelper<T>::Value>::Type>
{
static inline const QMetaObject *value() { return &T::staticMetaObject; }
};
@@ -1553,6 +1568,7 @@ namespace QtPrivate {
| (IsWeakPointerToTypeDerivedFromQObject<T>::Value ? QMetaType::WeakPointerToQObject : 0)
| (IsTrackingPointerToTypeDerivedFromQObject<T>::Value ? QMetaType::TrackingPointerToQObject : 0)
| (Q_IS_ENUM(T) ? QMetaType::IsEnumeration : 0)
+ | (IsGadgetHelper<T>::Value ? QMetaType::IsGadget : 0)
};
};
diff --git a/src/corelib/kernel/qobjectdefs.h b/src/corelib/kernel/qobjectdefs.h
index 38ee31b250..a495bce7ec 100644
--- a/src/corelib/kernel/qobjectdefs.h
+++ b/src/corelib/kernel/qobjectdefs.h
@@ -159,6 +159,7 @@ private: \
#define Q_GADGET \
public: \
static const QMetaObject staticMetaObject; \
+ typedef void QtGadgetHelper; \
private: \
Q_DECL_HIDDEN_STATIC_METACALL static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **);
#endif // QT_NO_META_MACROS