From 7b5e37cab738804d47b78582aa3d0f3bb6933e70 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Thu, 5 Aug 2010 10:10:50 +0200 Subject: Deprecate qVariantValue qVariantCanConvert qVariantFromValue qVariantSetValue The template member equivalent should be used instead. qVariantFromValue and qVariantSetValue does not have the QT_DEPRECATED macro, as they have template specialisation which is not possible to acheive as member function. So they are called by the non-deprecated implementation. Rev-by: dev mailing list --- src/corelib/kernel/qvariant.cpp | 16 ++++++++++------ src/corelib/kernel/qvariant.h | 24 +++++++++--------------- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp index bbfbce8..feb85ce 100644 --- a/src/corelib/kernel/qvariant.cpp +++ b/src/corelib/kernel/qvariant.cpp @@ -1076,7 +1076,7 @@ static void streamDebug(QDebug dbg, const QVariant &v) dbg.nospace() << v.toFloat(); break; case QMetaType::QObjectStar: - dbg.nospace() << qVariantValue(v); + dbg.nospace() << qvariant_cast(v); break; case QVariant::Double: dbg.nospace() << v.toDouble(); @@ -1237,7 +1237,7 @@ const QVariant::Handler *QVariant::handler = &qt_kernel_variant_handler; conversion functions to data types defined in QtGui, such as QColor, QImage, and QPixmap. In other words, there is no \c toColor() function. Instead, you can use the QVariant::value() or - the qVariantValue() template function. For example: + the qvariant_cast() template function. For example: \snippet doc/src/snippets/code/src_corelib_kernel_qvariant.cpp 2 @@ -1352,12 +1352,12 @@ const QVariant::Handler *QVariant::handler = &qt_kernel_variant_handler; Note that you have to pass the address of the variable you want stored. - Usually, you never have to use this constructor, use qVariantFromValue() + Usually, you never have to use this constructor, use QVariant::fromValue() instead to construct variants from the pointer types represented by \c QMetaType::VoidStar, \c QMetaType::QObjectStar and \c QMetaType::QWidgetStar. - \sa qVariantFromValue(), Type + \sa QVariant::fromValue(), Type */ /*! @@ -3116,6 +3116,7 @@ QDebug operator<<(QDebug dbg, const QVariant::Type p) /*! \fn QVariant qVariantFromValue(const T &value) \relates QVariant + \obsolete Returns a variant containing a copy of the given \a value with template type \c{T}. @@ -3136,6 +3137,7 @@ QDebug operator<<(QDebug dbg, const QVariant::Type p) /*! \fn void qVariantSetValue(QVariant &variant, const T &value) \relates QVariant + \obsolete Sets the contents of the given \a variant to a copy of the \a value with the specified template type \c{T}. @@ -3155,13 +3157,14 @@ QDebug operator<<(QDebug dbg, const QVariant::Type p) Returns the given \a value converted to the template type \c{T}. - This function is equivalent to qVariantValue(). + This function is equivalent to QVariant::value(). - \sa qVariantValue(), QVariant::value() + \sa QVariant::value() */ /*! \fn T qVariantValue(const QVariant &value) \relates QVariant + \obsolete Returns the given \a value converted to the template type \c{T}. @@ -3177,6 +3180,7 @@ QDebug operator<<(QDebug dbg, const QVariant::Type p) /*! \fn bool qVariantCanConvert(const QVariant &value) \relates QVariant + \obsolete Returns true if the given \a value can be converted to the template type specified; otherwise returns false. diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h index 73b00e9..432b708 100644 --- a/src/corelib/kernel/qvariant.h +++ b/src/corelib/kernel/qvariant.h @@ -86,14 +86,8 @@ class QVariantComparisonHelper; template inline QVariant qVariantFromValue(const T &); -template -inline void qVariantSetValue(QVariant &, const T &); - -template -inline T qVariantValue(const QVariant &); - template -inline bool qVariantCanConvert(const QVariant &); +inline T qvariant_cast(const QVariant &); class Q_CORE_EXPORT QVariant { @@ -330,7 +324,7 @@ class Q_CORE_EXPORT QVariant template inline T value() const - { return qVariantValue(*this); } + { return qvariant_cast(*this); } template static inline QVariant fromValue(const T &value) @@ -338,7 +332,7 @@ class Q_CORE_EXPORT QVariant template bool canConvert() const - { return qVariantCanConvert(*this); } + { return canConvert(Type(qMetaTypeId())); } public: #ifndef qdoc @@ -588,16 +582,16 @@ template<> inline QVariant qvariant_cast(const QVariant &v) return v; } +#ifdef QT_DEPRECATED template -inline T qVariantValue(const QVariant &variant) +inline QT_DEPRECATED T qVariantValue(const QVariant &variant) { return qvariant_cast(variant); } template -inline bool qVariantCanConvert(const QVariant &variant) -{ - return variant.canConvert(static_cast( - qMetaTypeId(static_cast(0)))); -} +inline QT_DEPRECATED bool qVariantCanConvert(const QVariant &variant) +{ return variant.canConvert(); } +#endif + #endif Q_DECLARE_SHARED(QVariant) Q_DECLARE_TYPEINFO(QVariant, Q_MOVABLE_TYPE); -- cgit v0.12