diff options
Diffstat (limited to 'src/corelib/kernel/qvariant.h')
-rw-r--r-- | src/corelib/kernel/qvariant.h | 90 |
1 files changed, 48 insertions, 42 deletions
diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h index 3cc6d559c1..e094ebff52 100644 --- a/src/corelib/kernel/qvariant.h +++ b/src/corelib/kernel/qvariant.h @@ -92,9 +92,6 @@ class QUrl; class QVariant; class QVariantComparisonHelper; -template <typename T> -inline QVariant qVariantFromValue(const T &); - template<typename T> inline T qvariant_cast(const QVariant &); @@ -204,7 +201,7 @@ class Q_CORE_EXPORT QVariant LastType = 0xffffffff // need this so that gcc >= 3.4 allocates 32 bits for Type }; - QVariant() Q_DECL_NOTHROW : d() {} + QVariant() noexcept : d() {} ~QVariant(); QVariant(Type type); QVariant(int typeId, const void *copy); @@ -270,14 +267,12 @@ class Q_CORE_EXPORT QVariant #endif QVariant& operator=(const QVariant &other); -#ifdef Q_COMPILER_RVALUE_REFS - inline QVariant(QVariant &&other) Q_DECL_NOTHROW : d(other.d) + inline QVariant(QVariant &&other) noexcept : d(other.d) { other.d = Private(); } - inline QVariant &operator=(QVariant &&other) Q_DECL_NOTHROW + inline QVariant &operator=(QVariant &&other) noexcept { qSwap(d, other.d); return *this; } -#endif - inline void swap(QVariant &other) Q_DECL_NOTHROW { qSwap(d, other.d); } + inline void swap(QVariant &other) noexcept { qSwap(d, other.d); } Type type() const; int userType() const; @@ -365,7 +360,7 @@ class Q_CORE_EXPORT QVariant template<typename T> static inline QVariant fromValue(const T &value) - { return qVariantFromValue(value); } + { return QVariant(qMetaTypeId<T>(), &value, QTypeInfo<T>::isPointer); } #if QT_HAS_INCLUDE(<variant>) && __cplusplus >= 201703L template<typename... Types> @@ -390,20 +385,20 @@ class Q_CORE_EXPORT QVariant }; struct Private { - inline Private() Q_DECL_NOTHROW : type(Invalid), is_shared(false), is_null(true) + inline Private() noexcept : type(Invalid), is_shared(false), is_null(true) { data.ptr = nullptr; } // Internal constructor for initialized variants. - explicit inline Private(uint variantType) Q_DECL_NOTHROW + explicit inline Private(uint variantType) noexcept : type(variantType), is_shared(false), is_null(false) {} #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) - Private(const Private &other) Q_DECL_NOTHROW + Private(const Private &other) noexcept : data(other.data), type(other.type), is_shared(other.is_shared), is_null(other.is_null) {} - Private &operator=(const Private &other) Q_DECL_NOTHROW = default; + Private &operator=(const Private &other) noexcept = default; #endif union Data { @@ -491,27 +486,27 @@ public: private: // force compile error, prevent QVariant(bool) to be called - inline QVariant(void *) Q_DECL_EQ_DELETE; + inline QVariant(void *) = delete; // QVariant::Type is marked as \obsolete, but we don't want to // provide a constructor from its intended replacement, // QMetaType::Type, instead, because the idea behind these // constructors is flawed in the first place. But we also don't // want QVariant(QMetaType::String) to compile and falsely be an // int variant, so delete this constructor: - QVariant(QMetaType::Type) Q_DECL_EQ_DELETE; + QVariant(QMetaType::Type) = delete; // These constructors don't create QVariants of the type associcated // with the enum, as expected, but they would create a QVariant of // type int with the value of the enum value. // Use QVariant v = QColor(Qt::red) instead of QVariant v = Qt::red for // example. - QVariant(Qt::GlobalColor) Q_DECL_EQ_DELETE; - QVariant(Qt::BrushStyle) Q_DECL_EQ_DELETE; - QVariant(Qt::PenStyle) Q_DECL_EQ_DELETE; - QVariant(Qt::CursorShape) Q_DECL_EQ_DELETE; + QVariant(Qt::GlobalColor) = delete; + QVariant(Qt::BrushStyle) = delete; + QVariant(Qt::PenStyle) = delete; + QVariant(Qt::CursorShape) = delete; #ifdef QT_NO_CAST_FROM_ASCII // force compile error when implicit conversion is not wanted - inline QVariant(const char *) Q_DECL_EQ_DELETE; + inline QVariant(const char *) = delete; #endif public: typedef Private DataPtr; @@ -519,50 +514,61 @@ public: inline const DataPtr &data_ptr() const { return d; } }; +#if QT_DEPRECATED_SINCE(5, 14) template <typename T> +QT_DEPRECATED_X("Use QVariant::fromValue() instead.") inline QVariant qVariantFromValue(const T &t) { - return QVariant(qMetaTypeId<T>(), &t, QTypeInfo<T>::isPointer); + return QVariant::fromValue(t); +} + +template <typename T> +QT_DEPRECATED_X("Use QVariant::setValue() instead.") +inline void qVariantSetValue(QVariant &v, const T &t) +{ + v.setValue(t); } +#endif -template <> -inline QVariant qVariantFromValue(const QVariant &t) { return t; } +template<> +inline QVariant QVariant::fromValue(const QVariant &value) +{ + return value; +} #if QT_HAS_INCLUDE(<variant>) && __cplusplus >= 201703L -template <> -inline QVariant qVariantFromValue(const std::monostate &) { return QVariant(); } +template<> +inline QVariant QVariant::fromValue(const std::monostate &) +{ + return QVariant(); +} #endif -template <typename T> -inline void qVariantSetValue(QVariant &v, const T &t) +inline bool QVariant::isValid() const { return d.type != Invalid; } + +template<typename T> +inline void QVariant::setValue(const T &avalue) { - //if possible we reuse the current QVariant private + // If possible we reuse the current QVariant private. const uint type = qMetaTypeId<T>(); - QVariant::Private &d = v.data_ptr(); - if (v.isDetached() && (type == d.type || (type <= uint(QVariant::Char) && d.type <= uint(QVariant::Char)))) { + if (isDetached() && (type == d.type || (type <= uint(QVariant::Char) && d.type <= uint(QVariant::Char)))) { d.type = type; d.is_null = false; T *old = reinterpret_cast<T*>(d.is_shared ? d.data.shared->ptr : &d.data.ptr); if (QTypeInfo<T>::isComplex) old->~T(); - new (old) T(t); //call the copy constructor + new (old) T(avalue); // call the copy constructor } else { - v = QVariant(type, &t, QTypeInfo<T>::isPointer); + *this = QVariant(type, &avalue, QTypeInfo<T>::isPointer); } } -template <> -inline void qVariantSetValue<QVariant>(QVariant &v, const QVariant &t) +template<> +inline void QVariant::setValue(const QVariant &avalue) { - v = t; + *this = avalue; } -inline bool QVariant::isValid() const { return d.type != Invalid; } - -template<typename T> -inline void QVariant::setValue(const T &avalue) -{ qVariantSetValue(*this, avalue); } - #ifndef QT_NO_DATASTREAM Q_CORE_EXPORT QDataStream& operator>> (QDataStream& s, QVariant& p); Q_CORE_EXPORT QDataStream& operator<< (QDataStream& s, const QVariant& p); |