From 1ba46c9b632731d7d7e791de2b203d0d933245b9 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Mon, 3 Feb 2020 16:18:20 +0100 Subject: Get rid of QMatrix Task-number: QTBUG-81628 Change-Id: Iad66bfdf49b9ee65558a451108c086fc40dc3884 Reviewed-by: Lars Knoll --- tests/auto/gui/painting/CMakeLists.txt | 1 - tests/auto/gui/painting/painting.pro | 1 - tests/auto/gui/painting/qpainter/tst_qpainter.cpp | 44 +-- tests/auto/gui/painting/qwmatrix/qwmatrix.pro | 6 - tests/auto/gui/painting/qwmatrix/tst_qwmatrix.cpp | 334 ---------------------- 5 files changed, 7 insertions(+), 379 deletions(-) delete mode 100644 tests/auto/gui/painting/qwmatrix/qwmatrix.pro delete mode 100644 tests/auto/gui/painting/qwmatrix/tst_qwmatrix.cpp (limited to 'tests/auto/gui/painting') diff --git a/tests/auto/gui/painting/CMakeLists.txt b/tests/auto/gui/painting/CMakeLists.txt index e13679e282..7cb4c55cee 100644 --- a/tests/auto/gui/painting/CMakeLists.txt +++ b/tests/auto/gui/painting/CMakeLists.txt @@ -16,5 +16,4 @@ endif() add_subdirectory("qpen") add_subdirectory("qpaintengine") # add_subdirectory("qtransform") -# add_subdirectory("qwmatrix") # add_subdirectory("qpolygon") diff --git a/tests/auto/gui/painting/painting.pro b/tests/auto/gui/painting/painting.pro index 26e84c1b15..3fdb0db760 100644 --- a/tests/auto/gui/painting/painting.pro +++ b/tests/auto/gui/painting/painting.pro @@ -14,7 +14,6 @@ SUBDIRS=\ qpen \ qpaintengine \ qtransform \ - qwmatrix \ qpolygon \ !qtConfig(private_tests): SUBDIRS -= \ diff --git a/tests/auto/gui/painting/qpainter/tst_qpainter.cpp b/tests/auto/gui/painting/qpainter/tst_qpainter.cpp index 9eb62ceab2..7418f447e6 100644 --- a/tests/auto/gui/painting/qpainter/tst_qpainter.cpp +++ b/tests/auto/gui/painting/qpainter/tst_qpainter.cpp @@ -140,7 +140,7 @@ private slots: void setWindow(); - void combinedMatrix(); + void combinedTransform(); void renderHints(); void disableEnableClipping(); @@ -1692,7 +1692,7 @@ void tst_QPainter::setWindow() QVERIFY(195 < painted.height() && painted.height() < 205); // correct value is around 200 } -void tst_QPainter::combinedMatrix() +void tst_QPainter::combinedTransform() { QPixmap pm(64, 64); @@ -1703,15 +1703,7 @@ void tst_QPainter::combinedMatrix() p.translate(0.5, 0.5); QTransform ct = p.combinedTransform(); -#if QT_DEPRECATED_SINCE(5, 13) -QT_WARNING_PUSH -QT_WARNING_DISABLE_DEPRECATED - QMatrix cm = p.combinedMatrix(); - QCOMPARE(cm, ct.toAffine()); -QT_WARNING_POP -#endif - - QPointF pt = QPointF(0, 0) * ct.toAffine(); + QPointF pt = QPointF(0, 0) * ct; QCOMPARE(pt.x(), 48.0); QCOMPARE(pt.y(), 16.0); @@ -4067,7 +4059,7 @@ void tst_QPainter::drawPolygon() path.moveTo(2, 34); path.lineTo(34, 2); - QPolygonF poly = stroker.createStroke(path).toFillPolygon(QTransform()); + QPolygonF poly = stroker.createStroke(path).toFillPolygon(); img.fill(0xffffffff); QPainter p(&img); @@ -4135,24 +4127,12 @@ void tst_QPainter::inactivePainter() p.setClipRegion(region); p.setClipping(true); -#if QT_DEPRECATED_SINCE(5, 13) -QT_WARNING_PUSH -QT_WARNING_DISABLE_DEPRECATED - p.combinedMatrix(); -QT_WARNING_POP -#endif p.combinedTransform(); p.compositionMode(); p.setCompositionMode(QPainter::CompositionMode_Plus); p.device(); -#if QT_DEPRECATED_SINCE(5, 13) -QT_WARNING_PUSH -QT_WARNING_DISABLE_DEPRECATED - p.deviceMatrix(); -QT_WARNING_POP -#endif p.deviceTransform(); p.font(); @@ -4176,12 +4156,6 @@ QT_WARNING_POP p.setRenderHint(QPainter::Antialiasing, true); p.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform, false); -#if QT_DEPRECATED_SINCE(5, 13) -QT_WARNING_PUSH -QT_WARNING_DISABLE_DEPRECATED - p.resetMatrix(); -QT_WARNING_POP -#endif p.resetTransform(); p.rotate(1); p.scale(2, 2); @@ -4197,13 +4171,9 @@ QT_WARNING_POP p.window(); p.setWindow(QRect(10, 10, 620, 460)); -#if QT_DEPRECATED_SINCE(5, 13) -QT_WARNING_PUSH -QT_WARNING_DISABLE_DEPRECATED - p.worldMatrix(); - p.setWorldMatrix(QMatrix().translate(43, 21), true); -QT_WARNING_POP -#endif + p.worldTransform(); + p.setWorldTransform(QTransform().translate(43, 21), true); + p.setWorldMatrixEnabled(true); p.transform(); diff --git a/tests/auto/gui/painting/qwmatrix/qwmatrix.pro b/tests/auto/gui/painting/qwmatrix/qwmatrix.pro deleted file mode 100644 index de6454025c..0000000000 --- a/tests/auto/gui/painting/qwmatrix/qwmatrix.pro +++ /dev/null @@ -1,6 +0,0 @@ -CONFIG += testcase -TARGET = tst_qwmatrix -SOURCES += tst_qwmatrix.cpp -QT += testlib - -unix:!darwin:!haiku:!integrity: LIBS += -lm diff --git a/tests/auto/gui/painting/qwmatrix/tst_qwmatrix.cpp b/tests/auto/gui/painting/qwmatrix/tst_qwmatrix.cpp deleted file mode 100644 index 281639c27a..0000000000 --- a/tests/auto/gui/painting/qwmatrix/tst_qwmatrix.cpp +++ /dev/null @@ -1,334 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#include -#include -#include -#include - -#if QT_DEPRECATED_SINCE(5, 15) -QT_WARNING_PUSH -QT_WARNING_DISABLE_DEPRECATED - -class tst_QWMatrix : public QObject -{ - Q_OBJECT - -private slots: - void mapRect_data(); - void mapToPolygon_data(); - void mapRect(); - void operator_star_qwmatrix(); - void assignments(); - void mapToPolygon(); - void translate(); - void scale(); - void mapPolygon(); - -private: - void mapping_data(); -}; - -void tst_QWMatrix::mapRect_data() -{ - mapping_data(); -} - -void tst_QWMatrix::mapToPolygon_data() -{ - mapping_data(); -} - -void tst_QWMatrix::mapping_data() -{ - //create the testtable instance and define the elements - QTest::addColumn("matrix"); - QTest::addColumn("src"); - QTest::addColumn("res"); - - //next we fill it with data - - // identity - QTest::newRow( "identity" ) << QMatrix( 1, 0, 0, 1, 0, 0 ) - << QRect( 10, 20, 30, 40 ) - << QPolygon( QRect( 10, 20, 30, 40 ) ); - // scaling - QTest::newRow( "scale 0" ) << QMatrix( 2, 0, 0, 2, 0, 0 ) - << QRect( 10, 20, 30, 40 ) - << QPolygon( QRect( 20, 40, 60, 80 ) ); - QTest::newRow( "scale 1" ) << QMatrix( 10, 0, 0, 10, 0, 0 ) - << QRect( 10, 20, 30, 40 ) - << QPolygon( QRect( 100, 200, 300, 400 ) ); - // mirroring - QTest::newRow( "mirror 0" ) << QMatrix( -1, 0, 0, 1, 0, 0 ) - << QRect( 10, 20, 30, 40 ) - << QPolygon( QRect( -40, 20, 30, 40 ) ); - QTest::newRow( "mirror 1" ) << QMatrix( 1, 0, 0, -1, 0, 0 ) - << QRect( 10, 20, 30, 40 ) - << QPolygon( QRect( 10, -60, 30, 40 ) ); - QTest::newRow( "mirror 2" ) << QMatrix( -1, 0, 0, -1, 0, 0 ) - << QRect( 10, 20, 30, 40 ) - << QPolygon( QRect( -40, -60, 30, 40 ) ); - QTest::newRow( "mirror 3" ) << QMatrix( -2, 0, 0, -2, 0, 0 ) - << QRect( 10, 20, 30, 40 ) - << QPolygon( QRect( -80, -120, 60, 80 ) ); - QTest::newRow( "mirror 4" ) << QMatrix( -10, 0, 0, -10, 0, 0 ) - << QRect( 10, 20, 30, 40 ) - << QPolygon( QRect( -400, -600, 300, 400 ) ); - QTest::newRow( "mirror 5" ) << QMatrix( -1, 0, 0, 1, 0, 0 ) - << QRect( 0, 0, 30, 40 ) - << QPolygon( QRect( -30, 0, 30, 40 ) ); - QTest::newRow( "mirror 6" ) << QMatrix( 1, 0, 0, -1, 0, 0 ) - << QRect( 0, 0, 30, 40 ) - << QPolygon( QRect( 0, -40, 30, 40 ) ); - QTest::newRow( "mirror 7" ) << QMatrix( -1, 0, 0, -1, 0, 0 ) - << QRect( 0, 0, 30, 40 ) - << QPolygon( QRect( -30, -40, 30, 40 ) ); - QTest::newRow( "mirror 8" ) << QMatrix( -2, 0, 0, -2, 0, 0 ) - << QRect( 0, 0, 30, 40 ) - << QPolygon( QRect( -60, -80, 60, 80 ) ); - QTest::newRow( "mirror 9" ) << QMatrix( -10, 0, 0, -10, 0, 0 ) - << QRect( 0, 0, 30, 40 ) - << QPolygon( QRect( -300, -400, 300, 400 ) ); - - const auto rotate = [](qreal degrees) { - const qreal rad = qDegreesToRadians(degrees); - return QMatrix(std::cos(rad), -std::sin(rad), - std::sin(rad), std::cos(rad), 0, 0); - }; - - // rotations - QTest::newRow( "rot 0 a" ) << rotate(0.) - << QRect( 0, 0, 30, 40 ) - << QPolygon ( QRect( 0, 0, 30, 40 ) ); - QTest::newRow( "rot 0 b" ) << rotate(0.00001f) - << QRect( 0, 0, 30, 40 ) - << QPolygon ( QRect( 0, 0, 30, 40 ) ); - QTest::newRow( "rot 0 c" ) << rotate(0.) - << QRect( 10, 20, 30, 40 ) - << QPolygon ( QRect( 10, 20, 30, 40 ) ); - QTest::newRow( "rot 0 d" ) << rotate(0.00001f) - << QRect( 10, 20, 30, 40 ) - << QPolygon ( QRect( 10, 20, 30, 40 ) ); - -#if 0 - const auto rotScale = [](qreal degrees, qreal scale) { - const qreal rad = qDegreesToRadians(degrees); - return QMatrix(scale * std::cos(rad), -scale * std::sin(rad), - scale * std::sin(rad), scale * std::cos(rad), 0, 0); - }; - // rotations with scaling - QTest::newRow( "rotscale 90 a" ) << rotScale(90., 10) - << QRect( 0, 0, 30, 40 ) - << QPolygon( QRect( 0, -299, 400, 300 ) ); - QTest::newRow( "rotscale 90 b" ) << rotScale(90.00001, 10) - << QRect( 0, 0, 30, 40 ) - << QPolygon( QRect( 0, -299, 400, 300 ) ); - QTest::newRow( "rotscale 90 c" ) << rotScale(90., 10) - << QRect( 10, 20, 30, 40 ) - << QPolygon( QRect( 200, -399, 400, 300 ) ); - QTest::newRow( "rotscale 90 d" ) << rotScale(90.00001, 10) - << QRect( 10, 20, 30, 40 ) - << QPolygon( QRect( 200, -399, 400, 300 ) ); - - QTest::newRow( "rotscale 180 a" ) << rotScale(180., 10) - << QRect( 0, 0, 30, 40 ) - << QPolygon( QRect( -299, -399, 300, 400 ) ); - QTest::newRow( "rotscale 180 b" ) << rotScale(180.000001, 10) - << QRect( 0, 0, 30, 40 ) - << QPolygon( QRect( -299, -399, 300, 400 ) ); - QTest::newRow( "rotscale 180 c" ) << rotScale(180., 10) - << QRect( 10, 20, 30, 40 ) - << QPolygon( QRect( -399, -599, 300, 400 ) ); - QTest::newRow( "rotscale 180 d" ) << rotScale(180.000001, 10) - << QRect( 10, 20, 30, 40 ) - << QPolygon( QRect( -399, -599, 300, 400 ) ); - - QTest::newRow( "rotscale 270 a" ) << rotScale(270., 10) - << QRect( 0, 0, 30, 40 ) - << QPolygon( QRect( -399, 00, 400, 300 ) ); - QTest::newRow( "rotscale 270 b" ) << rotScale(270.0000001, 10) - << QRect( 0, 0, 30, 40 ) - << QPolygon( QRect( -399, 00, 400, 300 ) ); - QTest::newRow( "rotscale 270 c" ) << rotScale(270., 10) - << QRect( 10, 20, 30, 40 ) - << QPolygon( QRect( -599, 100, 400, 300 ) ); - QTest::newRow( "rotscale 270 d" ) << rotScale(270.000001, 10) - << QRect( 10, 20, 30, 40 ) - << QPolygon( QRect( -599, 100, 400, 300 ) ); - - // rotations that are not multiples of 90 degrees. mapRect returns the bounding rect here. - QTest::newRow( "rot 45 a" ) << rotate(45) - << QRect( 0, 0, 10, 10 ) - << QPolygon( QRect( 0, -7, 14, 14 ) ); - QTest::newRow( "rot 45 b" ) << rotate(45) - << QRect( 10, 20, 30, 40 ) - << QPolygon( QRect( 21, -14, 49, 49 ) ); - QTest::newRow( "rot 45 c" ) << rotScale(45, 10) - << QRect( 0, 0, 10, 10 ) - << QPolygon( QRect( 0, -70, 141, 141 ) ); - QTest::newRow( "rot 45 d" ) << rotScale(45, 10) - << QRect( 10, 20, 30, 40 ) - << QPolygon( QRect( 212, -141, 495, 495 ) ); - - QTest::newRow( "rot -45 a" ) << rotate(-45) - << QRect( 0, 0, 10, 10 ) - << QPolygon( QRect( -7, 0, 14, 14 ) ); - QTest::newRow( "rot -45 b" ) << rotate(-45) - << QRect( 10, 20, 30, 40 ) - << QPolygon( QRect( -35, 21, 49, 49 ) ); - QTest::newRow( "rot -45 c" ) << rotScale(-45, 10) - << QRect( 0, 0, 10, 10 ) - << QPolygon( QRect( -70, 0, 141, 141 ) ); - QTest::newRow( "rot -45 d" ) << rotScale(-45, 10) - << QRect( 10, 20, 30, 40 ) - << QPolygon( QRect( -353, 212, 495, 495 ) ); -#endif -} - -void tst_QWMatrix::mapRect() -{ - QFETCH( QMatrix, matrix ); - QFETCH( QRect, src ); -// qDebug( "got src: %d/%d (%d/%d), matrix=[ %f %f %f %f %f %f ]", -// src.x(), src.y(), src.width(), src.height(), -// matrix.m11(), matrix.m12(), matrix.m21(), matrix.m22(), matrix.dx(), matrix.dy() ); - QTEST( QPolygon( matrix.mapRect(src) ), "res" ); -} - -void tst_QWMatrix::operator_star_qwmatrix() -{ - QMatrix m1( 2, 3, 4, 5, 6, 7 ); - QMatrix m2( 3, 4, 5, 6, 7, 8 ); - - QMatrix result1x2( 21, 26, 37, 46, 60, 74 ); - QMatrix result2x1( 22, 29, 34, 45, 52, 68); - - QMatrix product12 = m1*m2; - QMatrix product21 = m2*m1; - - QVERIFY( product12==result1x2 ); - QVERIFY( product21==result2x1 ); -} - - -void tst_QWMatrix::assignments() -{ - QMatrix m; - m.scale(2, 3); - m.rotate(45); - m.shear(4, 5); - - QMatrix c1(m); - - QCOMPARE(m.m11(), c1.m11()); - QCOMPARE(m.m12(), c1.m12()); - QCOMPARE(m.m21(), c1.m21()); - QCOMPARE(m.m22(), c1.m22()); - QCOMPARE(m.dx(), c1.dx()); - QCOMPARE(m.dy(), c1.dy()); - - QMatrix c2 = m; - QCOMPARE(m.m11(), c2.m11()); - QCOMPARE(m.m12(), c2.m12()); - QCOMPARE(m.m21(), c2.m21()); - QCOMPARE(m.m22(), c2.m22()); - QCOMPARE(m.dx(), c2.dx()); - QCOMPARE(m.dy(), c2.dy()); -} - - -void tst_QWMatrix::mapToPolygon() -{ - QFETCH( QMatrix, matrix ); - QFETCH( QRect, src ); - QFETCH( QPolygon, res ); - - QCOMPARE( matrix.mapToPolygon( src ), res ); -} - - -void tst_QWMatrix::translate() -{ - QMatrix m( 1, 2, 3, 4, 5, 6 ); - QMatrix res2( m ); - QMatrix res( 1, 2, 3, 4, 75, 106 ); - m.translate( 10, 20 ); - QVERIFY( m == res ); - m.translate( -10, -20 ); - QVERIFY( m == res2 ); -} - -void tst_QWMatrix::scale() -{ - QMatrix m( 1, 2, 3, 4, 5, 6 ); - QMatrix res2( m ); - QMatrix res( 10, 20, 60, 80, 5, 6 ); - m.scale( 10, 20 ); - QVERIFY( m == res ); - m.scale( 1./10., 1./20. ); - QVERIFY( m == res2 ); -} - -void tst_QWMatrix::mapPolygon() -{ - QPolygon poly; - poly << QPoint(0, 0) << QPoint(1, 1) << QPoint(100, 1) << QPoint(1, 100) << QPoint(-1, -1) << QPoint(-1000, 1000); - - { - QMatrix m; - m.rotate(90); - - // rotating 90 degrees four times should result in original poly - QPolygon mapped = m.map(m.map(m.map(m.map(poly)))); - QCOMPARE(mapped, poly); - - QMatrix m2; - m2.scale(10, 10); - QMatrix m3; - m3.scale(0.1, 0.1); - - mapped = m3.map(m2.map(poly)); - QCOMPARE(mapped, poly); - } - - { - QMatrix m(1, 2, 3, 4, 5, 6); - - QPolygon mapped = m.map(poly); - for (int i = 0; i < mapped.size(); ++i) - QCOMPARE(mapped.at(i), m.map(poly.at(i))); - } -} - -QT_WARNING_POP -#endif - -QTEST_APPLESS_MAIN(tst_QWMatrix) -#include "tst_qwmatrix.moc" -- cgit v1.2.3