Account for QPolygonF type when loading/saving the QVariant
When the QPolygonF type was added to QMetaType it did not bump up the values in load() and save() for QVariant. Task-number: QTBUG-33981 Change-Id: I7ad99cda70620c5449c15527c3daf920972d047f Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com> Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
This commit is contained in:
parent
cd13fe44cd
commit
5c301f4121
@ -1892,6 +1892,7 @@ void QVariant::load(QDataStream &s)
|
||||
void QVariant::save(QDataStream &s) const
|
||||
{
|
||||
quint32 typeId = type();
|
||||
bool fakeUserType = false;
|
||||
if (s.version() < QDataStream::Qt_4_0) {
|
||||
int i;
|
||||
for (i = 0; i <= MapFromThreeCount - 1; ++i) {
|
||||
@ -1916,12 +1917,16 @@ void QVariant::save(QDataStream &s) const
|
||||
} else if (typeId >= QMetaType::QKeySequence && typeId <= QMetaType::QQuaternion) {
|
||||
// and as a result these types received lower ids too
|
||||
typeId +=1;
|
||||
} else if (typeId == QMetaType::QPolygonF) {
|
||||
// This existed in Qt 4 only as a custom type
|
||||
typeId = 127;
|
||||
fakeUserType = true;
|
||||
}
|
||||
}
|
||||
s << typeId;
|
||||
if (s.version() >= QDataStream::Qt_4_2)
|
||||
s << qint8(d.is_null);
|
||||
if (d.type >= QVariant::UserType) {
|
||||
if (d.type >= QVariant::UserType || fakeUserType) {
|
||||
s << QMetaType::typeName(userType());
|
||||
}
|
||||
|
||||
|
BIN
tests/auto/gui/kernel/qguivariant/test/data/qpolygonf.bin
Normal file
BIN
tests/auto/gui/kernel/qguivariant/test/data/qpolygonf.bin
Normal file
Binary file not shown.
5
tests/auto/gui/kernel/qguivariant/test/qguivariant.qrc
Normal file
5
tests/auto/gui/kernel/qguivariant/test/qguivariant.qrc
Normal file
@ -0,0 +1,5 @@
|
||||
<!DOCTYPE RCC><RCC version="1.0">
|
||||
<qresource>
|
||||
<file>data</file>
|
||||
</qresource>
|
||||
</RCC>
|
@ -4,3 +4,4 @@ TARGET = tst_qguivariant
|
||||
SOURCES += tst_qguivariant.cpp
|
||||
INCLUDEPATH += $$PWD/../../../../other/qvariant_common
|
||||
QT += testlib
|
||||
RESOURCES += qguivariant.qrc
|
||||
|
@ -114,6 +114,7 @@ private slots:
|
||||
|
||||
void writeToReadFromDataStream_data();
|
||||
void writeToReadFromDataStream();
|
||||
void writeToReadFromOldDataStream();
|
||||
|
||||
void colorInteger();
|
||||
void invalidQColor();
|
||||
@ -525,6 +526,7 @@ void tst_QGuiVariant::writeToReadFromDataStream_data()
|
||||
QTest::newRow( "pointarray_valid" ) << QVariant::fromValue( QPolygon( QRect( 10, 10, 20, 20 ) ) ) << false;
|
||||
QTest::newRow( "region_invalid" ) << QVariant::fromValue( QRegion() ) << true;
|
||||
QTest::newRow( "region_valid" ) << QVariant::fromValue( QRegion( 10, 10, 20, 20 ) ) << false;
|
||||
QTest::newRow("polygonf_valid") << QVariant::fromValue(QPolygonF(QRectF(10, 10, 20, 20))) << false;
|
||||
}
|
||||
|
||||
void tst_QGuiVariant::invalidQColor()
|
||||
@ -609,6 +611,46 @@ void tst_QGuiVariant::writeToReadFromDataStream()
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QGuiVariant::writeToReadFromOldDataStream()
|
||||
{
|
||||
QPolygonF polyF(QRectF(10, 10, 50, 50));
|
||||
QVariant testVariant(polyF);
|
||||
{
|
||||
// Read into a variant and compare
|
||||
QFile file(":/data/qpolygonf.bin");
|
||||
QVERIFY(file.open(QIODevice::ReadOnly));
|
||||
QDataStream dataFileStream(&file);
|
||||
dataFileStream.setVersion(QDataStream::Qt_4_9);
|
||||
QVariant readVariant;
|
||||
dataFileStream >> readVariant;
|
||||
QVERIFY(readVariant.type() == QMetaType::QPolygonF);
|
||||
QCOMPARE(testVariant, readVariant);
|
||||
file.close();
|
||||
}
|
||||
{
|
||||
QByteArray variantData;
|
||||
{
|
||||
QDataStream varDataStream(&variantData, QIODevice::WriteOnly);
|
||||
varDataStream << testVariant;
|
||||
}
|
||||
// Read into a bytearray and compare
|
||||
QFile file(":/data/qpolygonf.bin");
|
||||
QVERIFY(file.open(QIODevice::ReadOnly));
|
||||
QDataStream dataFileStream(&file);
|
||||
dataFileStream.setVersion(QDataStream::Qt_4_9);
|
||||
int dummy;
|
||||
dataFileStream >> dummy;
|
||||
QByteArray polyData49;
|
||||
dataFileStream >> polyData49;
|
||||
file.close();
|
||||
QByteArray polyData50;
|
||||
QDataStream readVarData(variantData);
|
||||
readVarData >> dummy;
|
||||
readVarData >> polyData50;
|
||||
QVERIFY(polyData49 == polyData50);
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QGuiVariant::debugStream_data()
|
||||
{
|
||||
QTest::addColumn<QVariant>("variant");
|
||||
|
Loading…
Reference in New Issue
Block a user