diff options
Diffstat (limited to 'src/corelib/kernel/qmetatype.h')
-rw-r--r-- | src/corelib/kernel/qmetatype.h | 158 |
1 files changed, 103 insertions, 55 deletions
diff --git a/src/corelib/kernel/qmetatype.h b/src/corelib/kernel/qmetatype.h index d88f469e0f..455d0350e0 100644 --- a/src/corelib/kernel/qmetatype.h +++ b/src/corelib/kernel/qmetatype.h @@ -234,7 +234,7 @@ struct AbstractDebugStreamFunction { typedef void (*Stream)(const AbstractDebugStreamFunction *, QDebug&, const void *); typedef void (*Destroy)(AbstractDebugStreamFunction *); - explicit AbstractDebugStreamFunction(Stream s = Q_NULLPTR, Destroy d = Q_NULLPTR) + explicit AbstractDebugStreamFunction(Stream s = nullptr, Destroy d = nullptr) : stream(s), destroy(d) {} Q_DISABLE_COPY(AbstractDebugStreamFunction) Stream stream; @@ -264,7 +264,7 @@ struct AbstractComparatorFunction typedef bool (*LessThan)(const AbstractComparatorFunction *, const void *, const void *); typedef bool (*Equals)(const AbstractComparatorFunction *, const void *, const void *); typedef void (*Destroy)(AbstractComparatorFunction *); - explicit AbstractComparatorFunction(LessThan lt = Q_NULLPTR, Equals e = Q_NULLPTR, Destroy d = Q_NULLPTR) + explicit AbstractComparatorFunction(LessThan lt = nullptr, Equals e = nullptr, Destroy d = nullptr) : lessThan(lt), equals(e), destroy(d) {} Q_DISABLE_COPY(AbstractComparatorFunction) LessThan lessThan; @@ -301,7 +301,7 @@ template<typename T> struct BuiltInEqualsComparatorFunction : public AbstractComparatorFunction { BuiltInEqualsComparatorFunction() - : AbstractComparatorFunction(Q_NULLPTR, equals, destroy) {} + : AbstractComparatorFunction(nullptr, equals, destroy) {} static bool equals(const AbstractComparatorFunction *, const void *l, const void *r) { const T *lhs = static_cast<const T *>(l); @@ -318,7 +318,7 @@ struct BuiltInEqualsComparatorFunction : public AbstractComparatorFunction struct AbstractConverterFunction { typedef bool (*Converter)(const AbstractConverterFunction *, const void *, void*); - explicit AbstractConverterFunction(Converter c = Q_NULLPTR) + explicit AbstractConverterFunction(Converter c = nullptr) : convert(c) {} Q_DISABLE_COPY(AbstractConverterFunction) Converter convert; @@ -406,7 +406,7 @@ class Q_CORE_EXPORT QMetaType { FlagsEx = 0x100, MetaObjectEx = 0x200 }; public: -#ifndef Q_QDOC +#ifndef Q_CLANG_QDOC // The code that actually gets compiled. enum Type { // these are merged with QVariant @@ -441,6 +441,7 @@ public: QJsonValue = 45, QJsonObject = 46, QJsonArray = 47, QJsonDocument = 48, QByteArrayList = 49, QObjectStar = 39, SChar = 40, Void = 43, + Nullptr = 51, QVariantMap = 8, QVariantList = 9, QVariantHash = 28, QFont = 64, QPixmap = 65, QBrush = 66, QColor = 67, QPalette = 68, QIcon = 69, QImage = 70, QPolygon = 71, QRegion = 72, QBitmap = 73, @@ -448,6 +449,8 @@ public: QMatrix = 79, QTransform = 80, QMatrix4x4 = 81, QVector2D = 82, QVector3D = 83, QVector4D = 84, QQuaternion = 85, QPolygonF = 86, QSizePolicy = 121, + LastCoreType = Nullptr, + LastGuiType = QPolygonF, User = 1024 }; #endif @@ -462,7 +465,8 @@ public: WeakPointerToQObject = 0x40, TrackingPointerToQObject = 0x80, WasDeclaredAsMetaType = 0x100, - IsGadget = 0x200 + IsGadget = 0x200, + PointerToGadget = 0x400 }; Q_DECLARE_FLAGS(TypeFlags, TypeFlag) @@ -512,9 +516,9 @@ public: static TypeFlags typeFlags(int type); static const QMetaObject *metaObjectForType(int type); static bool isRegistered(int type); - static void *create(int type, const void *copy = Q_NULLPTR); + static void *create(int type, const void *copy = nullptr); #if QT_DEPRECATED_SINCE(5, 0) - QT_DEPRECATED static void *construct(int type, const void *copy = Q_NULLPTR) + QT_DEPRECATED static void *construct(int type, const void *copy = nullptr) { return create(type, copy); } #endif static void destroy(int type, void *data); @@ -535,9 +539,9 @@ public: inline TypeFlags flags() const; inline const QMetaObject *metaObject() const; - inline void *create(const void *copy = Q_NULLPTR) const; + inline void *create(const void *copy = nullptr) const; inline void destroy(void *data) const; - inline void *construct(void *where, const void *copy = Q_NULLPTR) const; + inline void *construct(void *where, const void *copy = nullptr) const; inline void destruct(void *data) const; public: @@ -595,7 +599,7 @@ public: return registerConverter<From, To>(QtPrivate::convertImplicit<From, To>); } -#ifdef Q_QDOC +#ifdef Q_CLANG_QDOC template<typename MemberFunction, int> static bool registerConverter(MemberFunction function); template<typename MemberFunctionOk, char> @@ -616,7 +620,7 @@ public: return registerConverterFunction(&f, fromTypeId, toTypeId); } - // member function as in "double QString::toDouble(bool *ok = Q_NULLPTR) const" + // member function as in "double QString::toDouble(bool *ok = nullptr) const" template<typename From, typename To> static bool registerConverter(To(From::*function)(bool*) const) { @@ -679,9 +683,9 @@ private: uint sizeExtended() const; QMetaType::TypeFlags flagsExtended() const; const QMetaObject *metaObjectExtended() const; - void *createExtended(const void *copy = Q_NULLPTR) const; + void *createExtended(const void *copy = nullptr) const; void destroyExtended(void *data) const; - void *constructExtended(void *where, const void *copy = Q_NULLPTR) const; + void *constructExtended(void *where, const void *copy = nullptr) const; void destructExtended(void *data) const; static bool registerComparatorFunction(const QtPrivate::AbstractComparatorFunction *f, int type); @@ -691,7 +695,7 @@ private: // ### Qt6: FIXME: Remove the special Q_CC_MSVC handling, it was introduced to maintain BC. #if !defined(Q_NO_TEMPLATE_FRIENDS) && !defined(Q_CC_MSVC) -#ifndef Q_QDOC +#ifndef Q_CLANG_QDOC template<typename, bool> friend struct QtPrivate::ValueTypeIsMetaType; template<typename, typename> friend struct QtPrivate::ConverterMemberFunction; template<typename, typename> friend struct QtPrivate::ConverterMemberFunctionOk; @@ -781,7 +785,7 @@ struct QMetaTypeFunctionHelper { template <typename T> struct QMetaTypeFunctionHelper<T, /* Accepted */ false> { static void Destruct(void *) {} - static void *Construct(void *, const void *) { return Q_NULLPTR; } + static void *Construct(void *, const void *) { return nullptr; } #ifndef QT_NO_DATASTREAM static void Save(QDataStream &, const void *) {} static void Load(QDataStream &, void *) {} @@ -1019,7 +1023,7 @@ public: public: template<class T> QSequentialIterableImpl(const T*p) : _iterable(p) - , _iterator(Q_NULLPTR) + , _iterator(nullptr) , _metaType_id(qMetaTypeId<typename T::value_type>()) , _metaType_flags(QTypeInfo<typename T::value_type>::isPointer) , _iteratorCapabilities(ContainerAPI<T>::IteratorCapabilities) @@ -1036,20 +1040,20 @@ public: } QSequentialIterableImpl() - : _iterable(Q_NULLPTR) - , _iterator(Q_NULLPTR) + : _iterable(nullptr) + , _iterator(nullptr) , _metaType_id(QMetaType::UnknownType) , _metaType_flags(0) , _iteratorCapabilities(0) - , _size(Q_NULLPTR) - , _at(Q_NULLPTR) - , _moveToBegin(Q_NULLPTR) - , _moveToEnd(Q_NULLPTR) - , _advance(Q_NULLPTR) - , _get(Q_NULLPTR) - , _destroyIter(Q_NULLPTR) - , _equalIter(Q_NULLPTR) - , _copyIter(Q_NULLPTR) + , _size(nullptr) + , _at(nullptr) + , _moveToBegin(nullptr) + , _moveToEnd(nullptr) + , _advance(nullptr) + , _get(nullptr) + , _destroyIter(nullptr) + , _equalIter(nullptr) + , _copyIter(nullptr) { } @@ -1188,7 +1192,7 @@ public: public: template<class T> QAssociativeIterableImpl(const T*p) : _iterable(p) - , _iterator(Q_NULLPTR) + , _iterator(nullptr) , _metaType_id_key(qMetaTypeId<typename T::key_type>()) , _metaType_flags_key(QTypeInfo<typename T::key_type>::isPointer) , _metaType_id_value(qMetaTypeId<typename T::mapped_type>()) @@ -1207,22 +1211,22 @@ public: } QAssociativeIterableImpl() - : _iterable(Q_NULLPTR) - , _iterator(Q_NULLPTR) + : _iterable(nullptr) + , _iterator(nullptr) , _metaType_id_key(QMetaType::UnknownType) , _metaType_flags_key(0) , _metaType_id_value(QMetaType::UnknownType) , _metaType_flags_value(0) - , _size(Q_NULLPTR) - , _find(Q_NULLPTR) - , _begin(Q_NULLPTR) - , _end(Q_NULLPTR) - , _advance(Q_NULLPTR) - , _getKey(Q_NULLPTR) - , _getValue(Q_NULLPTR) - , _destroyIter(Q_NULLPTR) - , _equalIter(Q_NULLPTR) - , _copyIter(Q_NULLPTR) + , _size(nullptr) + , _find(nullptr) + , _begin(nullptr) + , _end(nullptr) + , _advance(nullptr) + , _getKey(nullptr) + , _getValue(nullptr) + , _destroyIter(nullptr) + , _equalIter(nullptr) + , _copyIter(nullptr) { } @@ -1291,13 +1295,13 @@ public: } QPairVariantInterfaceImpl() - : _pair(Q_NULLPTR) + : _pair(nullptr) , _metaType_id_first(QMetaType::UnknownType) , _metaType_flags_first(0) , _metaType_id_second(QMetaType::UnknownType) , _metaType_flags_second(0) - , _getFirst(Q_NULLPTR) - , _getSecond(Q_NULLPTR) + , _getFirst(nullptr) + , _getSecond(nullptr) { } @@ -1373,7 +1377,7 @@ namespace QtPrivate #endif static no_type checkType(...); Q_STATIC_ASSERT_X(sizeof(T), "Type argument of Q_DECLARE_METATYPE(T*) must be fully defined"); - enum { Value = sizeof(checkType(static_cast<T*>(Q_NULLPTR))) == sizeof(yes_type) }; + enum { Value = sizeof(checkType(static_cast<T*>(nullptr))) == sizeof(yes_type) }; }; template<typename T, typename Enable = void> @@ -1388,6 +1392,19 @@ namespace QtPrivate enum { Value = sizeof(checkType(&T::qt_check_for_QGADGET_macro)) == sizeof(void *) }; }; + template<typename T, typename Enable = void> + struct IsPointerToGadgetHelper { enum { Value = false }; }; + + template<typename T> + struct IsPointerToGadgetHelper<T*, typename T::QtGadgetHelper> + { + using BaseType = T; + template <typename X> + static char checkType(void (X::*)()); + static void *checkType(void (T::*)()); + enum { Value = sizeof(checkType(&T::qt_check_for_QGADGET_macro)) == sizeof(void *) }; + }; + template<typename T> char qt_getEnumMetaObject(const T&); @@ -1405,12 +1422,12 @@ namespace QtPrivate template<typename T, typename Enable = void> struct MetaObjectForType { - static inline const QMetaObject *value() { return Q_NULLPTR; } + static inline const QMetaObject *value() { return nullptr; } }; template<> struct MetaObjectForType<void> { - static inline const QMetaObject *value() { return Q_NULLPTR; } + static inline const QMetaObject *value() { return nullptr; } }; template<typename T> struct MetaObjectForType<T*, typename std::enable_if<IsPointerToTypeDerivedFromQObject<T*>::Value>::type> @@ -1423,6 +1440,11 @@ namespace QtPrivate static inline const QMetaObject *value() { return &T::staticMetaObject; } }; template<typename T> + struct MetaObjectForType<T, typename QEnableIf<IsPointerToGadgetHelper<T>::Value>::Type> + { + static inline const QMetaObject *value() { return &IsPointerToGadgetHelper<T>::BaseType::staticMetaObject; } + }; + template<typename T> struct MetaObjectForType<T, typename std::enable_if<IsQEnumHelper<T>::Value>::type > { static inline const QMetaObject *value() { return qt_getEnumMetaObject(T()); } @@ -1578,6 +1600,7 @@ namespace QtPrivate template <typename T, int = QtPrivate::IsPointerToTypeDerivedFromQObject<T>::Value ? QMetaType::PointerToQObject : QtPrivate::IsGadgetHelper<T>::Value ? QMetaType::IsGadget : + QtPrivate::IsPointerToGadgetHelper<T>::Value ? QMetaType::PointerToGadget : QtPrivate::IsQEnumHelper<T>::Value ? QMetaType::IsEnumeration : 0> struct QMetaTypeIdQObject { @@ -1631,6 +1654,7 @@ namespace QtPrivate { | (IsTrackingPointerToTypeDerivedFromQObject<T>::Value ? QMetaType::TrackingPointerToQObject : 0) | (std::is_enum<T>::value ? QMetaType::IsEnumeration : 0) | (IsGadgetHelper<T>::Value ? QMetaType::IsGadget : 0) + | (IsPointerToGadgetHelper<T>::Value ? QMetaType::PointerToGadget : 0) }; }; @@ -1661,7 +1685,7 @@ namespace QtPrivate { template <typename T> int qRegisterNormalizedMetaType(const QT_PREPEND_NAMESPACE(QByteArray) &normalizedTypeName -#ifndef Q_QDOC +#ifndef Q_CLANG_QDOC , T * dummy = 0 , typename QtPrivate::MetaTypeDefinedHelper<T, QMetaTypeId2<T>::Defined && !QMetaTypeId2<T>::IsBuiltIn>::DefinedType defined = QtPrivate::MetaTypeDefinedHelper<T, QMetaTypeId2<T>::Defined && !QMetaTypeId2<T>::IsBuiltIn>::Defined #endif @@ -1698,8 +1722,8 @@ int qRegisterNormalizedMetaType(const QT_PREPEND_NAMESPACE(QByteArray) &normaliz template <typename T> int qRegisterMetaType(const char *typeName -#ifndef Q_QDOC - , T * dummy = Q_NULLPTR +#ifndef Q_CLANG_QDOC + , T * dummy = nullptr , typename QtPrivate::MetaTypeDefinedHelper<T, QMetaTypeId2<T>::Defined && !QMetaTypeId2<T>::IsBuiltIn>::DefinedType defined = QtPrivate::MetaTypeDefinedHelper<T, QMetaTypeId2<T>::Defined && !QMetaTypeId2<T>::IsBuiltIn>::Defined #endif ) @@ -1715,8 +1739,8 @@ int qRegisterMetaType(const char *typeName #ifndef QT_NO_DATASTREAM template <typename T> void qRegisterMetaTypeStreamOperators(const char *typeName -#ifndef Q_QDOC - , T * /* dummy */ = Q_NULLPTR +#ifndef Q_CLANG_QDOC + , T * /* dummy */ = nullptr #endif ) { @@ -1739,7 +1763,7 @@ inline Q_DECL_CONSTEXPR int qRegisterMetaType() return qMetaTypeId<T>(); } -#if QT_DEPRECATED_SINCE(5, 1) && !defined(Q_QDOC) +#if QT_DEPRECATED_SINCE(5, 1) && !defined(Q_CLANG_QDOC) // There used to be a T *dummy = 0 argument in Qt 4.0 to support MSVC6 template <typename T> QT_DEPRECATED inline Q_DECL_CONSTEXPR int qMetaTypeId(T *) @@ -1798,6 +1822,30 @@ struct QMetaTypeIdQObject<T, QMetaType::IsGadget> }; template <typename T> +struct QMetaTypeIdQObject<T*, QMetaType::PointerToGadget> +{ + enum { + Defined = 1 + }; + + static int qt_metatype_id() + { + static QBasicAtomicInt metatype_id = Q_BASIC_ATOMIC_INITIALIZER(0); + if (const int id = metatype_id.loadAcquire()) + return id; + const char * const cName = T::staticMetaObject.className(); + QByteArray typeName; + typeName.reserve(int(strlen(cName)) + 1); + typeName.append(cName).append('*'); + const int newId = qRegisterNormalizedMetaType<T*>( + typeName, + reinterpret_cast<T**>(quintptr(-1))); + metatype_id.storeRelease(newId); + return newId; + } +}; + +template <typename T> struct QMetaTypeIdQObject<T, QMetaType::IsEnumeration> { enum { @@ -1887,7 +1935,7 @@ QT_FOR_EACH_STATIC_WIDGETS_CLASS(QT_FORWARD_DECLARE_STATIC_TYPES_ITER) typedef QList<QVariant> QVariantList; typedef QMap<QString, QVariant> QVariantMap; typedef QHash<QString, QVariant> QVariantHash; -#ifndef Q_QDOC +#ifndef Q_CLANG_QDOC typedef QList<QByteArray> QByteArrayList; #endif @@ -2105,7 +2153,7 @@ inline QMetaType::QMetaType(const ExtensionFlag extensionFlags, const QMetaTypeI , m_loadOp(loadOp) , m_constructor(constructor) , m_destructor(destructor) - , m_extension(Q_NULLPTR) + , m_extension(nullptr) , m_size(size) , m_typeFlags(theTypeFlags) , m_extensionFlags(extensionFlags) |