diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2024-02-23 19:41:30 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2024-03-27 06:38:45 +0000 |
commit | de6b76229f688960d354b8deb1b21ba2b4ad3e8b (patch) | |
tree | 2e9bcf3d0156a74f6c4d277c3fb866a1a80f1b38 | |
parent | 2255d843969536901823b98ff8ca9dfb9450b05b (diff) |
QPolygonF: delegate QDataStream marshalling to QList
Like the QPolygon code. This fixes a mistake in failing to clear the
list before de-marshalling in operator>>.
Updated most of the QDataStream tests to have data in the objects
they're streaming into, to ensure that the stream overwrites everything.
Fixes: QTBUG-122684
Task-number: QTBUG-122704
Pick-to: 6.5 5.15
Change-Id: I01ec3c774d9943adb903fffd17b6920c72f5042b
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
(cherry picked from commit 1ebee8980ba31514079a01989168914bfd1e9f4f)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit 113ecff9f229dffa37bf099aa22718272dfae52d)
-rw-r--r-- | src/gui/painting/qpolygon.cpp | 20 | ||||
-rw-r--r-- | tests/auto/corelib/serialization/qdatastream/tst_qdatastream.cpp | 35 |
2 files changed, 25 insertions, 30 deletions
diff --git a/src/gui/painting/qpolygon.cpp b/src/gui/painting/qpolygon.cpp index 7795e9dc5a..d615245eb4 100644 --- a/src/gui/painting/qpolygon.cpp +++ b/src/gui/painting/qpolygon.cpp @@ -697,13 +697,7 @@ QDataStream &operator>>(QDataStream &s, QPolygon &a) QDataStream &operator<<(QDataStream &s, const QPolygonF &a) { - quint32 len = a.size(); - uint i; - - s << len; - for (i = 0; i < len; ++i) - s << a.at(i); - return s; + return s << static_cast<const QList<QPointF> &>(a); } /*! @@ -718,17 +712,7 @@ QDataStream &operator<<(QDataStream &s, const QPolygonF &a) QDataStream &operator>>(QDataStream &s, QPolygonF &a) { - quint32 len; - uint i; - - s >> len; - a.reserve(a.size() + (int)len); - QPointF p; - for (i = 0; i < len; ++i) { - s >> p; - a.insert(i, p); - } - return s; + return s >> static_cast<QList<QPointF> &>(a); } #endif //QT_NO_DATASTREAM diff --git a/tests/auto/corelib/serialization/qdatastream/tst_qdatastream.cpp b/tests/auto/corelib/serialization/qdatastream/tst_qdatastream.cpp index 8fa17a96f2..b88634dcdd 100644 --- a/tests/auto/corelib/serialization/qdatastream/tst_qdatastream.cpp +++ b/tests/auto/corelib/serialization/qdatastream/tst_qdatastream.cpp @@ -2828,7 +2828,7 @@ void tst_QDataStream::status_charptr_QByteArray() } { QDataStream stream(&data, QIODevice::ReadOnly); - QByteArray buf; + QByteArray buf = "Content to be overwritten"; stream >> buf; if (data.startsWith("\xff\xff\xff\xff")) { @@ -2912,7 +2912,7 @@ void tst_QDataStream::status_QString() QFETCH(QString, expectedString); QDataStream stream(&data, QIODevice::ReadOnly); - QString str; + QString str = "Content to be overwritten"; stream >> str; QCOMPARE(str.size(), expectedString.size()); @@ -3007,7 +3007,7 @@ void tst_QDataStream::status_QBitArray() QDataStream stream(&data, QIODevice::ReadOnly); stream.setVersion(version); - QBitArray str; + QBitArray str(255, true); stream >> str; if (sizeof(qsizetype) == sizeof(int)) @@ -3074,7 +3074,9 @@ void tst_QDataStream::status_QHash_QMap() hash2.insert("L", "MN"); // ok + hash = hash2; MAP_TEST(QByteArray("\x00\x00\x00\x00", 4), QDataStream::Ok, QDataStream::Ok, StringHash()); + hash = hash2; MAP_TEST(QByteArray("\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00", 12), QDataStream::Ok, QDataStream::Ok, hash1); MAP_TEST(QByteArray("\x00\x00\x00\x02\x00\x00\x00\x02\x00J\x00\x00\x00\x02\x00K" "\x00\x00\x00\x02\x00L\x00\x00\x00\x04\x00M\x00N", 30), QDataStream::Ok, QDataStream::Ok, hash2); @@ -3155,7 +3157,9 @@ void tst_QDataStream::status_QList_QVector() someList.append("J"); someList.append("MN"); + list = someList; LIST_TEST(QByteArray("\x00\x00\x00\x00", 4), QDataStream::Ok, QDataStream::Ok, List()); + list = someList; LIST_TEST(QByteArray("\x00\x00\x00\x01\x00\x00\x00\x00", 8), QDataStream::Ok, QDataStream::Ok, listWithEmptyString); LIST_TEST(QByteArray("\x00\x00\x00\x02\x00\x00\x00\x02\x00J" "\x00\x00\x00\x04\x00M\x00N", 18), QDataStream::Ok, QDataStream::Ok, someList); @@ -3223,6 +3227,13 @@ void tst_QDataStream::streamRealDataTypes() path.arcTo(4, 5, 6, 7, 8, 9); path.quadTo(1, 2, 3, 4); + QPainterPath otherPath; + otherPath.arcTo(10, 4, 5, 6, 7, 8); + otherPath.lineTo(9, 0); + otherPath.cubicTo(0, 0, 10, 10, 20, 20); + otherPath.quadTo(2, 4, 5, 6); + QCOMPARE(otherPath.elementCount(), 12); + QColor color(64, 64, 64); color.setAlphaF(0.5); QRadialGradient radialGradient(5, 6, 7, 8, 9); @@ -3254,17 +3265,17 @@ void tst_QDataStream::streamRealDataTypes() file.close(); } - QPointF point; - QRectF rect; - QPolygonF polygon; + QPointF point(1, 2); + QRectF rect(1, 2, 5, 6); + QPolygonF polygon {{3, 4}, {5, 6}}; QTransform transform; - QPainterPath p; + QPainterPath p = otherPath; QPicture pict; - QTextLength textLength; - QColor col; - QBrush rGrad; - QBrush cGrad; - QPen pen; + QTextLength textLength(QTextLength::FixedLength, 2.5); + QColor col(128, 128, 127); + QBrush rGrad(Qt::CrossPattern); + QBrush cGrad(Qt::CrossPattern); + QPen pen(conicalBrush, 10); QVERIFY(file.open(QIODevice::ReadOnly)); QDataStream stream(&file); |