From d9d77e8680f4fcb1afacbcea3830adccf77957c4 Mon Sep 17 00:00:00 2001 From: Eirik Aavitsland Date: Tue, 5 Jun 2018 11:06:59 +0200 Subject: [PATCH] Fix QTransform::transposed() result having wrong transformation type The implementation of QTransform::transposed() had a wrong assumption about the type of the result. Task-number: QTBUG-68630 Change-Id: Ia5ce794efe773d74fb5fdaff3da8cae2b452e7e5 Reviewed-by: Friedemann Kleint Reviewed-by: Allan Sandfeld Jensen --- src/gui/painting/qtransform.cpp | 2 -- .../painting/qtransform/tst_qtransform.cpp | 35 +++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/gui/painting/qtransform.cpp b/src/gui/painting/qtransform.cpp index 7a53c44bc4..c5e296b293 100644 --- a/src/gui/painting/qtransform.cpp +++ b/src/gui/painting/qtransform.cpp @@ -352,8 +352,6 @@ QTransform QTransform::transposed() const QTransform t(affine._m11, affine._m21, affine._dx, affine._m12, affine._m22, affine._dy, m_13, m_23, m_33, true); - t.m_type = m_type; - t.m_dirty = m_dirty; return t; } diff --git a/tests/auto/gui/painting/qtransform/tst_qtransform.cpp b/tests/auto/gui/painting/qtransform/tst_qtransform.cpp index 0a6a95daca..f9366c9227 100644 --- a/tests/auto/gui/painting/qtransform/tst_qtransform.cpp +++ b/tests/auto/gui/painting/qtransform/tst_qtransform.cpp @@ -49,6 +49,8 @@ private slots: void matrix(); void testOffset(); void types(); + void types2_data(); + void types2(); void scalarOps(); void transform(); void mapEmptyPath(); @@ -65,6 +67,7 @@ private: }; Q_DECLARE_METATYPE(QTransform) +Q_DECLARE_METATYPE(QTransform::TransformationType) void tst_QTransform::mapRect_data() { @@ -568,6 +571,38 @@ void tst_QTransform::types() QCOMPARE(m5.type(), QTransform::TxScale); } +void tst_QTransform::types2_data() +{ + QTest::addColumn("t1"); + QTest::addColumn("type"); + + QTest::newRow( "identity" ) << QTransform() << QTransform::TxNone; + QTest::newRow( "translate" ) << QTransform().translate(10, -0.1) << QTransform::TxTranslate; + QTest::newRow( "scale" ) << QTransform().scale(10, -0.1) << QTransform::TxScale; + QTest::newRow( "rotate" ) << QTransform().rotate(10) << QTransform::TxRotate; + QTest::newRow( "shear" ) << QTransform().shear(10, -0.1) << QTransform::TxShear; + QTest::newRow( "project" ) << QTransform().rotate(10, Qt::XAxis) << QTransform::TxProject; + QTest::newRow( "combined" ) << QTransform().translate(10, -0.1).scale(10, -0.1).rotate(10, Qt::YAxis) << QTransform::TxProject; +} + +void tst_QTransform::types2() +{ +#define CHECKTXTYPE(func) { QTransform t2(func); \ + QTransform t3(t2.m11(), t2.m12(), t2.m13(), t2.m21(), t2.m22(), t2.m23(), t2.m31(), t2.m32(), t2.m33()); \ + QVERIFY2(t3.type() == t2.type(), #func); \ + } + + QFETCH( QTransform, t1 ); + QFETCH( QTransform::TransformationType, type ); + + Q_ASSERT(t1.type() == type); + + CHECKTXTYPE(t1.adjoint()); + CHECKTXTYPE(t1.inverted()); + CHECKTXTYPE(t1.transposed()); + +#undef CHECKTXTYPE +} void tst_QTransform::scalarOps() {