diff options
author | Jędrzej Nowacki <jedrzej.nowacki@nokia.com> | 2012-01-30 12:21:43 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-02-07 08:52:32 +0100 |
commit | 56265031b763736163f1a229a7e7e6b7aaec8a36 (patch) | |
tree | 74adf46c46a98ddda122f7bcc150af67af2388a1 /src/corelib | |
parent | a6505007295c7363ef1b0ee4aa81d15a2b470a7e (diff) |
Align QVariant::UserType and QMetaType::User
There is no point in keeping separate values which should mean the
same.
QVariant::UserType was used also to construct a valid, null QVariant,
containing an instance of unknown custom type. The concept was strange
and useless as there was no operation that could be done on such
QVariant. Therefore it was dropped.
Please note that the patch slightly changes behavior of different
functions accepting a type id as parameter. Before QVariant::UserType
was an invalid type from QMetaType perspective (id 127 was not assigned
to any built-in type), but QMetaType::User points to the first registered
custom type.
Change-Id: I5c7d541a9affdcdacf53a4eda2272bdafaa87b71
Reviewed-by: Kent Hansen <kent.hansen@nokia.com>
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Reviewed-by: João Abecasis <joao.abecasis@nokia.com>
Reviewed-by: Andrew Stanley-Jones <andrew.stanley-jones@nokia.com>
Reviewed-by: Aaron Kennedy <aaron.kennedy@nokia.com>
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/kernel/qmetaobject.cpp | 5 | ||||
-rw-r--r-- | src/corelib/kernel/qvariant.cpp | 12 | ||||
-rw-r--r-- | src/corelib/kernel/qvariant.h | 2 | ||||
-rw-r--r-- | src/corelib/kernel/qvariant_p.h | 15 |
4 files changed, 12 insertions, 22 deletions
diff --git a/src/corelib/kernel/qmetaobject.cpp b/src/corelib/kernel/qmetaobject.cpp index 400fe54c7f..7975fc2628 100644 --- a/src/corelib/kernel/qmetaobject.cpp +++ b/src/corelib/kernel/qmetaobject.cpp @@ -2243,9 +2243,8 @@ QVariant QMetaProperty::read(const QObject *object) const t = QMetaType::type(typeName); if (t == QVariant::Invalid) t = QVariant::nameToType(typeName); - if (t == QVariant::Invalid || t == QVariant::UserType) { - if (t == QVariant::Invalid) - qWarning("QMetaProperty::read: Unable to handle unregistered datatype '%s' for property '%s::%s'", typeName, mobj->className(), name()); + if (t == QVariant::Invalid) { + qWarning("QMetaProperty::read: Unable to handle unregistered datatype '%s' for property '%s::%s'", typeName, mobj->className(), name()); return QVariant(); } } diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp index cfaf22c146..4197fe9093 100644 --- a/src/corelib/kernel/qvariant.cpp +++ b/src/corelib/kernel/qvariant.cpp @@ -1608,7 +1608,7 @@ QVariant::Type QVariant::nameToType(const char *name) return Invalid; int metaType = QMetaType::type(name); - return metaType <= int(LastGuiType) ? QVariant::Type(metaType) : UserType; + return metaType <= int(UserType) ? QVariant::Type(metaType) : UserType; } #ifndef QT_NO_DATASTREAM @@ -1670,7 +1670,9 @@ void QVariant::load(QDataStream &s) return; typeId = mapIdFromQt3ToCurrent[typeId]; } else if (s.version() < QDataStream::Qt_5_0) { - if (typeId >= 128 && typeId != QVariant::UserType) { + if (typeId == 127 /* QVariant::UserType */) { + typeId = QMetaType::User; + } else if (typeId >= 128 && typeId != QVariant::UserType) { // In Qt4 id == 128 was FirstExtCoreType. In Qt5 ExtCoreTypes set was merged to CoreTypes // by moving all ids down by 97. typeId -= 97; @@ -1741,7 +1743,9 @@ void QVariant::save(QDataStream &s) const return; } } else if (s.version() < QDataStream::Qt_5_0) { - if (typeId >= 128 - 97 && typeId <= LastCoreType) { + if (typeId == QMetaType::User) { + typeId = 127; // QVariant::UserType had this value in Qt4 + } else if (typeId >= 128 - 97 && typeId <= LastCoreType) { // In Qt4 id == 128 was FirstExtCoreType. In Qt5 ExtCoreTypes set was merged to CoreTypes // by moving all ids down by 97. typeId += 97; @@ -1762,7 +1766,7 @@ void QVariant::save(QDataStream &s) const s << typeId; if (s.version() >= QDataStream::Qt_4_2) s << qint8(d.is_null); - if (typeId == QVariant::UserType) { + if (d.type >= QVariant::UserType) { s << QMetaType::typeName(userType()); } diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h index 07ef4dc41e..b61b0cc33c 100644 --- a/src/corelib/kernel/qvariant.h +++ b/src/corelib/kernel/qvariant.h @@ -153,7 +153,7 @@ class Q_CORE_EXPORT QVariant Icon = QMetaType::QIcon, SizePolicy = QMetaType::QSizePolicy, - UserType = 127, + UserType = QMetaType::User, LastType = 0xffffffff // need this so that gcc >= 3.4 allocates 32 bits for Type }; diff --git a/src/corelib/kernel/qvariant_p.h b/src/corelib/kernel/qvariant_p.h index 7065bcfd6b..30159f1831 100644 --- a/src/corelib/kernel/qvariant_p.h +++ b/src/corelib/kernel/qvariant_p.h @@ -348,14 +348,6 @@ public: void delegate(const QMetaTypeSwitcher::UnknownType*) { - if (m_x->type == QVariant::UserType) { - // TODO get rid of it - // And yes! we can support historical magic, unkonwn/unconstructed user type isn't that - // awesome? this QVariant::isValid will be true! - m_x->is_null = !m_copy; - m_x->is_shared = false; - return; - } qWarning("Trying to construct an instance of an invalid type, type id: %i", m_x->type); m_x->type = QVariant::Invalid; } @@ -406,8 +398,6 @@ public: void delegate(const QMetaTypeSwitcher::UnknownType*) { - if (m_d->type == QVariant::UserType) - return; qWarning("Trying to destruct an instance of an invalid type, type id: %i", m_d->type); } // Ignore nonconstructible type @@ -454,10 +444,7 @@ public: void delegate(const QMetaTypeSwitcher::UnknownType*) { - if (m_d->type == QVariant::UserType) - m_debugStream.nospace() << "QVariant::UserType"; - else - qWarning("Trying to stream an instance of an invalid type, type id: %i", m_d->type); + qWarning("Trying to stream an instance of an invalid type, type id: %i", m_d->type); } void delegate(const void*) { |