summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Ehrlicher <ch.ehrlicher@gmx.de>2019-03-21 19:51:44 +0100
committerChristian Ehrlicher <ch.ehrlicher@gmx.de>2019-03-31 12:25:46 +0000
commitc19d556863d931f5fd04d9e27ee7a47aafeaca2a (patch)
tree0f44472370c890213d878483dae0fb0bbe6bcbb3
parent300940a6c9eb0f74cefda7d76a5d19f56ec50253 (diff)
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>
-rw-r--r--examples/corelib/tools/doc/src/customtype.qdoc7
-rw-r--r--src/corelib/kernel/qvariant.cpp2
-rw-r--r--src/corelib/kernel/qvariant.h58
3 files changed, 37 insertions, 30 deletions
diff --git a/examples/corelib/tools/doc/src/customtype.qdoc b/examples/corelib/tools/doc/src/customtype.qdoc
index 91b814808a..7ccfc95c70 100644
--- a/examples/corelib/tools/doc/src/customtype.qdoc
+++ b/examples/corelib/tools/doc/src/customtype.qdoc
@@ -117,8 +117,8 @@
\snippet tools/customtype/main.cpp storing a custom value
- Alternatively, the QVariant::fromValue() and qVariantSetValue() functions
- can be used if you are using a compiler without support for member template
+ Alternatively, the QVariant::fromValue() function can be used if
+ you are using a compiler without support for member template
functions.
The value can be retrieved using the QVariant::value() member template
@@ -126,9 +126,6 @@
\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
The custom \c Message type can also be used with direct signal-slot
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<typename T> 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<typename T> 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 <typename T>
-inline QVariant qVariantFromValue(const T &);
-
template<typename T>
inline T qvariant_cast(const QVariant &);
@@ -365,7 +362,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>
@@ -516,50 +513,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);