diff options
author | Oswald Buddenhagen <oswald.buddenhagen@nokia.com> | 2009-11-02 17:01:13 (GMT) |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@nokia.com> | 2009-11-02 17:01:13 (GMT) |
commit | 20cfe1e790295254370cf472df39813f864de7ea (patch) | |
tree | 98ac008f7c468ed37a61c051870810db2bbf2360 /src/corelib/kernel/qvariant.h | |
parent | 83e497fdae56e11c79d913cdc665e78615291e9c (diff) | |
parent | 2ed925753cb194970712330edca4da8e91fa8f28 (diff) | |
download | Qt-20cfe1e790295254370cf472df39813f864de7ea.zip Qt-20cfe1e790295254370cf472df39813f864de7ea.tar.gz Qt-20cfe1e790295254370cf472df39813f864de7ea.tar.bz2 |
Merge remote branch 'mainline/4.6' into 4.6
Diffstat (limited to 'src/corelib/kernel/qvariant.h')
-rw-r--r-- | src/corelib/kernel/qvariant.h | 41 |
1 files changed, 15 insertions, 26 deletions
diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h index eb4fb56..3c10788 100644 --- a/src/corelib/kernel/qvariant.h +++ b/src/corelib/kernel/qvariant.h @@ -456,10 +456,11 @@ template <typename T> inline void qVariantSetValue(QVariant &v, const T &t) { //if possible we reuse the current QVariant private - const int type = qMetaTypeId<T>(reinterpret_cast<T *>(0)); + const uint type = qMetaTypeId<T>(reinterpret_cast<T *>(0)); QVariant::Private &d = v.data_ptr(); - if (v.isDetached() && (type <= int(QVariant::Char) || type == d.type)) { + if (v.isDetached() && (type <= uint(QVariant::Char) || type == d.type)) { 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(); @@ -469,6 +470,13 @@ inline void qVariantSetValue(QVariant &v, const T &t) } } +template <> +inline void qVariantSetValue<QVariant>(QVariant &v, const QVariant &t) +{ + v = t; +} + + inline QVariant::QVariant() {} inline bool QVariant::isValid() const { return d.type != Invalid; } @@ -558,9 +566,7 @@ inline bool operator!=(const QVariant &v1, const QVariantComparisonHelper &v2) #endif #ifndef QT_MOC -#if !defined qdoc && defined Q_CC_MSVC && _MSC_VER < 1300 - -template<typename T> T qvariant_cast(const QVariant &v, T * = 0) +template<typename T> inline T qvariant_cast(const QVariant &v) { const int vid = qMetaTypeId<T>(static_cast<T *>(0)); if (vid == v.userType()) @@ -573,28 +579,12 @@ template<typename T> T qvariant_cast(const QVariant &v, T * = 0) return T(); } -template<typename T> -inline T qVariantValue(const QVariant &variant, T *t = 0) -{ return qvariant_cast<T>(variant, t); } - -template<typename T> -inline bool qVariantCanConvert(const QVariant &variant, T *t = 0) -{ - return variant.canConvert(static_cast<QVariant::Type>(qMetaTypeId<T>(t))); -} -#else - -template<typename T> T qvariant_cast(const QVariant &v) +template<> inline QVariant qvariant_cast<QVariant>(const QVariant &v) { - const int vid = qMetaTypeId<T>(static_cast<T *>(0)); + static const int vid = qRegisterMetaType<QVariant>("QVariant"); if (vid == v.userType()) - return *reinterpret_cast<const T *>(v.constData()); - if (vid < int(QMetaType::User)) { - T t; - if (qvariant_cast_helper(v, QVariant::Type(vid), &t)) - return t; - } - return T(); + return *reinterpret_cast<const QVariant *>(v.constData()); + return v; } template<typename T> @@ -608,7 +598,6 @@ inline bool qVariantCanConvert(const QVariant &variant) qMetaTypeId<T>(static_cast<T *>(0)))); } #endif -#endif Q_DECLARE_SHARED(QVariant) Q_DECLARE_TYPEINFO(QVariant, Q_MOVABLE_TYPE); |