QVariant: deprecate qVariantFromValue/qVariantSetValue()
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 <jedrzej.nowacki@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
parent
300940a6c9
commit
c19d556863
@ -117,8 +117,8 @@
|
|||||||
|
|
||||||
\snippet tools/customtype/main.cpp storing a custom value
|
\snippet tools/customtype/main.cpp storing a custom value
|
||||||
|
|
||||||
Alternatively, the QVariant::fromValue() and qVariantSetValue() functions
|
Alternatively, the QVariant::fromValue() function can be used if
|
||||||
can be used if you are using a compiler without support for member template
|
you are using a compiler without support for member template
|
||||||
functions.
|
functions.
|
||||||
|
|
||||||
The value can be retrieved using the QVariant::value() member template
|
The value can be retrieved using the QVariant::value() member template
|
||||||
@ -126,9 +126,6 @@
|
|||||||
|
|
||||||
\snippet tools/customtype/main.cpp retrieving a custom value
|
\snippet tools/customtype/main.cpp retrieving a custom value
|
||||||
|
|
||||||
Alternatively, the qVariantValue() template function can be used if
|
|
||||||
you are using a compiler without support for member template functions.
|
|
||||||
|
|
||||||
\section1 Further Reading
|
\section1 Further Reading
|
||||||
|
|
||||||
The custom \c Message type can also be used with direct signal-slot
|
The custom \c Message type can also be used with direct signal-slot
|
||||||
|
@ -4282,6 +4282,7 @@ QDebug operator<<(QDebug dbg, const QVariant::Type p)
|
|||||||
\sa fromValue()
|
\sa fromValue()
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#if QT_DEPRECATED_SINCE(5, 14)
|
||||||
/*!
|
/*!
|
||||||
\fn template<typename T> QVariant qVariantFromValue(const T &value)
|
\fn template<typename T> QVariant qVariantFromValue(const T &value)
|
||||||
\relates QVariant
|
\relates QVariant
|
||||||
@ -4319,6 +4320,7 @@ QDebug operator<<(QDebug dbg, const QVariant::Type p)
|
|||||||
|
|
||||||
\sa QVariant::setValue()
|
\sa QVariant::setValue()
|
||||||
*/
|
*/
|
||||||
|
#endif
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\fn template<typename T> T qvariant_cast(const QVariant &value)
|
\fn template<typename T> T qvariant_cast(const QVariant &value)
|
||||||
|
@ -92,9 +92,6 @@ class QUrl;
|
|||||||
class QVariant;
|
class QVariant;
|
||||||
class QVariantComparisonHelper;
|
class QVariantComparisonHelper;
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
inline QVariant qVariantFromValue(const T &);
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline T qvariant_cast(const QVariant &);
|
inline T qvariant_cast(const QVariant &);
|
||||||
|
|
||||||
@ -365,7 +362,7 @@ class Q_CORE_EXPORT QVariant
|
|||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static inline QVariant fromValue(const T &value)
|
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
|
#if QT_HAS_INCLUDE(<variant>) && __cplusplus >= 201703L
|
||||||
template<typename... Types>
|
template<typename... Types>
|
||||||
@ -516,49 +513,60 @@ public:
|
|||||||
inline const DataPtr &data_ptr() const { return d; }
|
inline const DataPtr &data_ptr() const { return d; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if QT_DEPRECATED_SINCE(5, 14)
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
QT_DEPRECATED_X("Use QVariant::fromValue() instead.")
|
||||||
inline QVariant qVariantFromValue(const T &t)
|
inline QVariant qVariantFromValue(const T &t)
|
||||||
{
|
{
|
||||||
return QVariant(qMetaTypeId<T>(), &t, QTypeInfo<T>::isPointer);
|
return QVariant::fromValue(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
|
||||||
inline QVariant qVariantFromValue(const QVariant &t) { return t; }
|
|
||||||
|
|
||||||
#if QT_HAS_INCLUDE(<variant>) && __cplusplus >= 201703L
|
|
||||||
template <>
|
|
||||||
inline QVariant qVariantFromValue(const std::monostate &) { return QVariant(); }
|
|
||||||
#endif
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
QT_DEPRECATED_X("Use QVariant::setValue() instead.")
|
||||||
inline void qVariantSetValue(QVariant &v, const T &t)
|
inline void qVariantSetValue(QVariant &v, const T &t)
|
||||||
{
|
{
|
||||||
//if possible we reuse the current QVariant private
|
v.setValue(t);
|
||||||
const uint type = qMetaTypeId<T>();
|
}
|
||||||
QVariant::Private &d = v.data_ptr();
|
#endif
|
||||||
if (v.isDetached() && (type == d.type || (type <= uint(QVariant::Char) && d.type <= uint(QVariant::Char)))) {
|
|
||||||
d.type = type;
|
template<>
|
||||||
d.is_null = false;
|
inline QVariant QVariant::fromValue(const QVariant &value)
|
||||||
T *old = reinterpret_cast<T*>(d.is_shared ? d.data.shared->ptr : &d.data.ptr);
|
{
|
||||||
if (QTypeInfo<T>::isComplex)
|
return value;
|
||||||
old->~T();
|
|
||||||
new (old) T(t); //call the copy constructor
|
|
||||||
} else {
|
|
||||||
v = QVariant(type, &t, QTypeInfo<T>::isPointer);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
#if QT_HAS_INCLUDE(<variant>) && __cplusplus >= 201703L
|
||||||
inline void qVariantSetValue<QVariant>(QVariant &v, const QVariant &t)
|
template<>
|
||||||
|
inline QVariant QVariant::fromValue(const std::monostate &)
|
||||||
{
|
{
|
||||||
v = t;
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
inline bool QVariant::isValid() const { return d.type != Invalid; }
|
inline bool QVariant::isValid() const { return d.type != Invalid; }
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline void QVariant::setValue(const T &avalue)
|
inline void QVariant::setValue(const T &avalue)
|
||||||
{ qVariantSetValue(*this, avalue); }
|
{
|
||||||
|
// If possible we reuse the current QVariant private.
|
||||||
|
const uint type = qMetaTypeId<T>();
|
||||||
|
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(avalue); // call the copy constructor
|
||||||
|
} else {
|
||||||
|
*this = QVariant(type, &avalue, QTypeInfo<T>::isPointer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
|
inline void QVariant::setValue(const QVariant &avalue)
|
||||||
|
{
|
||||||
|
*this = avalue;
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef QT_NO_DATASTREAM
|
#ifndef QT_NO_DATASTREAM
|
||||||
Q_CORE_EXPORT QDataStream& operator>> (QDataStream& s, QVariant& p);
|
Q_CORE_EXPORT QDataStream& operator>> (QDataStream& s, QVariant& p);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user