summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qvariant.cpp
diff options
context:
space:
mode:
authorJędrzej Nowacki <jedrzej.nowacki@nokia.com>2012-01-13 10:41:02 +0100
committerQt by Nokia <qt-info@nokia.com>2012-01-25 21:08:08 +0100
commitaee1f6cc413f56bf4962324799ee3887c3dd037f (patch)
treec0be4eb34dc8fc64a050f8943cbf9d9e1007f0b2 /src/corelib/kernel/qvariant.cpp
parent4df34f055a152657b30d64128dacc82c075cbd74 (diff)
Cleanup mess in public type ids.
There is no reason to keep two separated core types sets. It couldn't be fixed before Qt5 because of binary compatibility promise. This patch merges QMetaType core types with ext core types. This "simple" operation consists of: - QDataStream version was incremented, because type ids are saved in QVariant's data stream. - QMetaType LastExtCoreType and FirstExtCoreType were replaced by LastCoreType, FirstCoreType and new QMetaType::HighestInternalId. - New tests checking QVariant data stream for Qt4 and for Qt5 versions were added. Change-Id: I02dd74d29317365c297a789a4eb7c9c5edc3b231 Reviewed-by: João Abecasis <joao.abecasis@nokia.com>
Diffstat (limited to 'src/corelib/kernel/qvariant.cpp')
-rw-r--r--src/corelib/kernel/qvariant.cpp73
1 files changed, 54 insertions, 19 deletions
diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp
index e0d1114622..c14e6ffd17 100644
--- a/src/corelib/kernel/qvariant.cpp
+++ b/src/corelib/kernel/qvariant.cpp
@@ -1625,7 +1625,7 @@ QVariant::Type QVariant::nameToType(const char *name)
#ifndef QT_NO_DATASTREAM
enum { MapFromThreeCount = 36 };
-static const ushort map_from_three[MapFromThreeCount] =
+static const ushort mapIdFromQt3ToCurrent[MapFromThreeCount] =
{
QVariant::Invalid,
QVariant::Map,
@@ -1675,26 +1675,45 @@ void QVariant::load(QDataStream &s)
{
clear();
- quint32 u;
- s >> u;
+ quint32 typeId;
+ s >> typeId;
if (s.version() < QDataStream::Qt_4_0) {
- if (u >= MapFromThreeCount)
+ if (typeId >= MapFromThreeCount)
return;
- u = map_from_three[u];
+ typeId = mapIdFromQt3ToCurrent[typeId];
+ } else if (s.version() < QDataStream::Qt_5_0) {
+ 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;
+ } else if (typeId == 69 /* QIcon */) {
+ // In Qt5 after modularization project this types where moved to a separate module (and ids were downgraded)
+ typeId = QMetaType::QIcon;
+ } else if (typeId == 75 /* QSizePolicy */) {
+ typeId = QMetaType::QSizePolicy;
+ } else if (typeId >= 70) {
+ // and as a result this types recieved lower ids too
+ if (typeId <= 74) { // QImage QPolygon QRegion QBitmap QCursor
+ typeId -=1;
+ } else if (typeId <= 86) { // QKeySequence QPen QTextLength QTextFormat QMatrix QTransform QMatrix4x4 QVector2D QVector3D QVector4D QQuaternion
+ typeId -=2;
+ }
+ }
}
+
qint8 is_null = false;
if (s.version() >= QDataStream::Qt_4_2)
s >> is_null;
- if (u == QVariant::UserType) {
+ if (typeId == QVariant::UserType) {
QByteArray name;
s >> name;
- u = QMetaType::type(name);
- if (!u) {
+ typeId = QMetaType::type(name);
+ if (!typeId) {
s.setStatus(QDataStream::ReadCorruptData);
return;
}
}
- create(static_cast<int>(u), 0);
+ create(static_cast<int>(typeId), 0);
d.is_null = is_null;
if (!isValid()) {
@@ -1720,12 +1739,12 @@ void QVariant::load(QDataStream &s)
*/
void QVariant::save(QDataStream &s) const
{
- quint32 tp = type();
+ quint32 typeId = type();
if (s.version() < QDataStream::Qt_4_0) {
int i;
for (i = MapFromThreeCount - 1; i >= 0; i--) {
- if (map_from_three[i] == tp) {
- tp = i;
+ if (mapIdFromQt3ToCurrent[i] == typeId) {
+ typeId = i;
break;
}
}
@@ -1733,11 +1752,29 @@ void QVariant::save(QDataStream &s) const
s << QVariant();
return;
}
+ } else if (s.version() < QDataStream::Qt_5_0) {
+ 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;
+ } else if (typeId == QMetaType::QIcon) {
+ // In Qt5 after modularization project this types where moved to a separate module (and ids were downgraded)
+ typeId = 69;
+ } else if (typeId == QMetaType::QSizePolicy) {
+ typeId = 75;
+ } else if (typeId >= QMetaType::QImage) {
+ // and as a result this types recieved lower ids too
+ if (typeId <= QMetaType::QCursor) {
+ typeId +=1;
+ } else if (typeId <= QMetaType::QQuaternion) {
+ typeId +=2;
+ }
+ }
}
- s << tp;
+ s << typeId;
if (s.version() >= QDataStream::Qt_4_2)
s << qint8(d.is_null);
- if (tp == QVariant::UserType) {
+ if (typeId == QVariant::UserType) {
s << QMetaType::typeName(userType());
}
@@ -2411,17 +2448,15 @@ static const quint32 qCanConvertMatrix[QVariant::LastCoreType + 1] =
*/
bool QVariant::canConvert(Type t) const
{
- //we can treat floats as double
- //the reason for not doing it the "proper" way is that QMetaType::Float's value is 135,
- //which can't be handled by qCanConvertMatrix
- //In addition QVariant::Type doesn't have a Float value, so we're using QMetaType::Float
+ // TODO Reimplement this function, currently it works but it is a historical mess.
const uint currentType = ((d.type == QMetaType::Float) ? QVariant::Double : d.type);
if (uint(t) == uint(QMetaType::Float)) t = QVariant::Double;
if (currentType == uint(t))
return true;
- if (currentType > QVariant::LastCoreType || t > QVariant::LastCoreType) {
+ // FIXME It should be LastCoreType intead of Uuid
+ if (currentType > QVariant::Uuid || t > QVariant::Uuid) {
switch (uint(t)) {
case QVariant::Int:
return currentType == QVariant::KeySequence