QEasyingCurve: fix data stream operators
Until now, QEasingCurve was not streaming all it's internal state. Therefore, doing store/reload operation through QDataStream would not yield the same curve as the original. This patch fixes it. [ChangeLog][QtCore][QEasingCurve] QEasingCurve now properly streams all the data needed to QDataStream. Change-Id: I1619501f5b4237983c8c68e148745a5e58863f55 Fixes: QTBUG-68181 Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
This commit is contained in:
parent
5c90a96998
commit
946d868619
@ -339,6 +339,23 @@ struct TCBPoint {
|
||||
};
|
||||
Q_DECLARE_TYPEINFO(TCBPoint, Q_PRIMITIVE_TYPE);
|
||||
|
||||
QDataStream &operator<<(QDataStream &stream, const TCBPoint &point)
|
||||
{
|
||||
stream << point._point
|
||||
<< point._t
|
||||
<< point._c
|
||||
<< point._b;
|
||||
return stream;
|
||||
}
|
||||
|
||||
QDataStream &operator>>(QDataStream &stream, TCBPoint &point)
|
||||
{
|
||||
stream >> point._point
|
||||
>> point._t
|
||||
>> point._c
|
||||
>> point._b;
|
||||
return stream;
|
||||
}
|
||||
|
||||
typedef QVector<TCBPoint> TCBPoints;
|
||||
|
||||
@ -363,6 +380,34 @@ public:
|
||||
|
||||
};
|
||||
|
||||
QDataStream &operator<<(QDataStream &stream, QEasingCurveFunction *func)
|
||||
{
|
||||
if (func) {
|
||||
stream << func->_p;
|
||||
stream << func->_a;
|
||||
stream << func->_o;
|
||||
if (stream.version() > QDataStream::Qt_5_12) {
|
||||
stream << func->_bezierCurves;
|
||||
stream << func->_tcbPoints;
|
||||
}
|
||||
}
|
||||
return stream;
|
||||
}
|
||||
|
||||
QDataStream &operator>>(QDataStream &stream, QEasingCurveFunction *func)
|
||||
{
|
||||
if (func) {
|
||||
stream >> func->_p;
|
||||
stream >> func->_a;
|
||||
stream >> func->_o;
|
||||
if (stream.version() > QDataStream::Qt_5_12) {
|
||||
stream >> func->_bezierCurves;
|
||||
stream >> func->_tcbPoints;
|
||||
}
|
||||
}
|
||||
return stream;
|
||||
}
|
||||
|
||||
static QEasingCurve::EasingFunction curveToFunc(QEasingCurve::Type curve);
|
||||
|
||||
qreal QEasingCurveFunction::value(qreal t)
|
||||
@ -1480,9 +1525,7 @@ QDataStream &operator<<(QDataStream &stream, const QEasingCurve &easing)
|
||||
bool hasConfig = easing.d_ptr->config;
|
||||
stream << hasConfig;
|
||||
if (hasConfig) {
|
||||
stream << easing.d_ptr->config->_p;
|
||||
stream << easing.d_ptr->config->_a;
|
||||
stream << easing.d_ptr->config->_o;
|
||||
stream << easing.d_ptr->config;
|
||||
}
|
||||
return stream;
|
||||
}
|
||||
@ -1515,9 +1558,7 @@ QDataStream &operator>>(QDataStream &stream, QEasingCurve &easing)
|
||||
easing.d_ptr->config = nullptr;
|
||||
if (hasConfig) {
|
||||
QEasingCurveFunction *config = curveToFunctionObject(type);
|
||||
stream >> config->_p;
|
||||
stream >> config->_a;
|
||||
stream >> config->_o;
|
||||
stream >> config;
|
||||
easing.d_ptr->config = config;
|
||||
}
|
||||
return stream;
|
||||
|
@ -55,6 +55,8 @@ private slots:
|
||||
void testCbrtFloat();
|
||||
void cpp11();
|
||||
void quadraticEquation();
|
||||
void streamInOut_data();
|
||||
void streamInOut();
|
||||
};
|
||||
|
||||
void tst_QEasingCurve::type()
|
||||
@ -879,5 +881,36 @@ void tst_QEasingCurve::quadraticEquation() {
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QEasingCurve::streamInOut_data()
|
||||
{
|
||||
QTest::addColumn<int>("version");
|
||||
QTest::addColumn<bool>("equality");
|
||||
|
||||
QTest::newRow("5.11") << int(QDataStream::Qt_5_11) << false;
|
||||
QTest::newRow("5.13") << int(QDataStream::Qt_5_13) << true;
|
||||
}
|
||||
|
||||
void tst_QEasingCurve::streamInOut()
|
||||
{
|
||||
QFETCH(int, version);
|
||||
QFETCH(bool, equality);
|
||||
|
||||
QEasingCurve orig;
|
||||
orig.addCubicBezierSegment(QPointF(0.43, 0.0025), QPointF(0.38, 0.51), QPointF(0.57, 0.99));
|
||||
|
||||
QEasingCurve copy;
|
||||
|
||||
QByteArray data;
|
||||
QDataStream dsw(&data,QIODevice::WriteOnly);
|
||||
QDataStream dsr(&data,QIODevice::ReadOnly);
|
||||
|
||||
dsw.setVersion(version);
|
||||
dsr.setVersion(version);
|
||||
dsw << orig;
|
||||
dsr >> copy;
|
||||
|
||||
QCOMPARE(copy == orig, equality);
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QEasingCurve)
|
||||
#include "tst_qeasingcurve.moc"
|
||||
|
Loading…
Reference in New Issue
Block a user