From c19d556863d931f5fd04d9e27ee7a47aafeaca2a Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Thu, 21 Mar 2019 19:51:44 +0100 Subject: QVariant: deprecate qVariantFromValue/qVariantSetValue() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit qVariantFromValue/qVariantSetValue() was marked as obsolete since Qt4. Therefore mark them as deprecated with Qt5.14. Since QVariant::setValue/fromValue() were using the now deprecated functions move the implementation to them and let qVariantFromValue/qVariantSetValue() call QVariant::setValue/fromValue(). Fixes: QTBUG-74043 Change-Id: I46617cc4d5c1e8c162d0f1f7ae32e4cfe9ce915c Reviewed-by: Jędrzej Nowacki Reviewed-by: Edward Welbourne --- src/corelib/kernel/qvariant.cpp | 2 ++ src/corelib/kernel/qvariant.h | 58 +++++++++++++++++++++++------------------ 2 files changed, 35 insertions(+), 25 deletions(-) (limited to 'src/corelib/kernel') diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp index 77d2c8cbe1..cd4e233af0 100644 --- a/src/corelib/kernel/qvariant.cpp +++ b/src/corelib/kernel/qvariant.cpp @@ -4282,6 +4282,7 @@ QDebug operator<<(QDebug dbg, const QVariant::Type p) \sa fromValue() */ +#if QT_DEPRECATED_SINCE(5, 14) /*! \fn template QVariant qVariantFromValue(const T &value) \relates QVariant @@ -4319,6 +4320,7 @@ QDebug operator<<(QDebug dbg, const QVariant::Type p) \sa QVariant::setValue() */ +#endif /*! \fn template T qvariant_cast(const QVariant &value) diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h index f95502e75f..90f5f5fc34 100644 --- a/src/corelib/kernel/qvariant.h +++ b/src/corelib/kernel/qvariant.h @@ -92,9 +92,6 @@ class QUrl; class QVariant; class QVariantComparisonHelper; -template -inline QVariant qVariantFromValue(const T &); - template inline T qvariant_cast(const QVariant &); @@ -365,7 +362,7 @@ class Q_CORE_EXPORT QVariant template static inline QVariant fromValue(const T &value) - { return qVariantFromValue(value); } + { return QVariant(qMetaTypeId(), &value, QTypeInfo::isPointer); } #if QT_HAS_INCLUDE() && __cplusplus >= 201703L template @@ -516,50 +513,61 @@ public: inline const DataPtr &data_ptr() const { return d; } }; +#if QT_DEPRECATED_SINCE(5, 14) template +QT_DEPRECATED_X("Use QVariant::fromValue() instead.") inline QVariant qVariantFromValue(const T &t) { - return QVariant(qMetaTypeId(), &t, QTypeInfo::isPointer); + return QVariant::fromValue(t); +} + +template +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() && __cplusplus >= 201703L -template <> -inline QVariant qVariantFromValue(const std::monostate &) { return QVariant(); } +template<> +inline QVariant QVariant::fromValue(const std::monostate &) +{ + return QVariant(); +} #endif -template -inline void qVariantSetValue(QVariant &v, const T &t) +inline bool QVariant::isValid() const { return d.type != Invalid; } + +template +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(); - 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(d.is_shared ? d.data.shared->ptr : &d.data.ptr); if (QTypeInfo::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::isPointer); + *this = QVariant(type, &avalue, QTypeInfo::isPointer); } } -template <> -inline void qVariantSetValue(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 -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); -- cgit v1.2.3