summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@nokia.com>2009-07-29 00:26:43 (GMT)
committerLars Knoll <lars.knoll@nokia.com>2009-07-29 00:26:44 (GMT)
commita6ea9ce6990003856ecadcca8ce9ddf37949363d (patch)
tree32bce99c4cf28cb922feca329f848ac0c5c47f42 /tests
parent62d81d9955f39bac327affd703b9df006ee8f6f7 (diff)
downloadQt-a6ea9ce6990003856ecadcca8ce9ddf37949363d.zip
Qt-a6ea9ce6990003856ecadcca8ce9ddf37949363d.tar.gz
Qt-a6ea9ce6990003856ecadcca8ce9ddf37949363d.tar.bz2
Implement new transformation handling for graphics items.
The idea of having separate rotationX/Y/Z, shearX/Y, etc. methods in QGraphicsItem turned out to be not giving us the flexibility we need and wanted. The new code now implements a different scheme, where we keep simple rotate (around z-axis), scale and transformOriginPoint methods, but remove the other ones. Instead we now have an additional list of QGraphicsTransform object. QGraphicsTransform is an abstract class that inherits QObject. Several specializations are provided and can be used to transform (and through property bindings animate) the item. Reviewed-By: Andreas
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp158
-rw-r--r--tests/auto/qgraphicstransform/qgraphicstransform.pro2
-rw-r--r--tests/auto/qgraphicstransform/tst_qgraphicstransform.cpp162
3 files changed, 201 insertions, 121 deletions
diff --git a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
index 9f1693d..7f6f322 100644
--- a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
+++ b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
@@ -44,6 +44,7 @@
#include <private/qtextcontrol_p.h>
#include <private/qgraphicsitem_p.h>
+#include <private/qgraphicsview_p.h>
#include <QStyleOptionGraphicsItem>
#include <QAbstractTextDocumentLayout>
#include <QBitmap>
@@ -6884,44 +6885,21 @@ void tst_QGraphicsItem::update()
void tst_QGraphicsItem::setTransformProperties_data()
{
QTest::addColumn<QPointF>("origin");
- QTest::addColumn<qreal>("rotationX");
- QTest::addColumn<qreal>("rotationY");
- QTest::addColumn<qreal>("rotationZ");
- QTest::addColumn<qreal>("scaleX");
- QTest::addColumn<qreal>("scaleY");
- QTest::addColumn<qreal>("shearX");
- QTest::addColumn<qreal>("shearY");
+ QTest::addColumn<qreal>("rotation");
+ QTest::addColumn<qreal>("scale");
- QTest::newRow("nothing") << QPointF() << qreal(0.0) << qreal(0.0) << qreal(0.0)
- << qreal(1.0) << qreal(1.0) << qreal(0.0) << qreal(0.0);
+ QTest::newRow("nothing") << QPointF() << qreal(0.0) << qreal(1.0);
- QTest::newRow("rotationZ") << QPointF() << qreal(0.0) << qreal(0.0) << qreal(42.2)
- << qreal(1.0) << qreal(1.0) << qreal(0.0) << qreal(0.0);
+ QTest::newRow("rotation") << QPointF() << qreal(42.2) << qreal(1.0);
- QTest::newRow("rotationXY") << QPointF() << qreal(12.5) << qreal(53.6) << qreal(0.0)
- << qreal(1.0) << qreal(1.0) << qreal(0.0) << qreal(0.0);
+ QTest::newRow("rotation dicentred") << QPointF(qreal(22.3), qreal(-56.2))
+ << qreal(-2578.2)
+ << qreal(1.0);
- QTest::newRow("rotationXYZ") << QPointF() << qreal(-25) << qreal(12) << qreal(556)
- << qreal(1.0) << qreal(1.0) << qreal(0.0) << qreal(0.0);
+ QTest::newRow("Scale") << QPointF() << qreal(0.0)
+ << qreal(6);
- QTest::newRow("rotationXYZ dicentred") << QPointF(-53, 25.2)
- << qreal(-2578.2) << qreal(4565.2) << qreal(56)
- << qreal(1.0) << qreal(1.0) << qreal(0.0) << qreal(0.0);
-
- QTest::newRow("Scale") << QPointF() << qreal(0.0) << qreal(0.0) << qreal(0.0)
- << qreal(6) << qreal(0.5) << qreal(0.0) << qreal(0.0);
-
- QTest::newRow("Shear") << QPointF() << qreal(0.0) << qreal(0.0) << qreal(0.0)
- << qreal(1.0) << qreal(1.0) << qreal(2.2) << qreal(0.5);
-
- QTest::newRow("Scale and Shear") << QPointF() << qreal(0.0) << qreal(0.0) << qreal(0.0)
- << qreal(5.2) << qreal(2.1) << qreal(5.2) << qreal(5.5);
-
- QTest::newRow("Everything") << QPointF() << qreal(41) << qreal(-23) << qreal(0.56)
- << qreal(8.2) << qreal(-0.2) << qreal(-12) << qreal(-0.8);
-
- QTest::newRow("Everything dicentred") << QPointF(qreal(22.3), qreal(-56.2)) << qreal(-175) << qreal(196) << qreal(-1260)
- << qreal(4) << qreal(2) << qreal(2.56) << qreal(0.8);
+ QTest::newRow("Everything dicentred") << QPointF(qreal(22.3), qreal(-56.2)) << qreal(-175) << qreal(196);
}
/**
@@ -6932,92 +6910,61 @@ void tst_QGraphicsItem::setTransformProperties_data()
void tst_QGraphicsItem::setTransformProperties()
{
QFETCH(QPointF,origin);
- QFETCH(qreal,rotationX);
- QFETCH(qreal,rotationY);
- QFETCH(qreal,rotationZ);
- QFETCH(qreal,scaleX);
- QFETCH(qreal,scaleY);
- QFETCH(qreal,shearX);
- QFETCH(qreal,shearY);
+ QFETCH(qreal,rotation);
+ QFETCH(qreal,scale);
QTransform result;
result.translate(origin.x(), origin.y());
- result.rotate(rotationX, Qt::XAxis);
- result.rotate(rotationY, Qt::YAxis);
- result.rotate(rotationZ, Qt::ZAxis);
- result.shear(shearX, shearY);
- result.scale(scaleX, scaleY);
+ result.rotate(rotation, Qt::ZAxis);
+ result.scale(scale, scale);
result.translate(-origin.x(), -origin.y());
QGraphicsScene scene;
QGraphicsRectItem *item = new QGraphicsRectItem(QRectF(0, 0, 100, 100));
scene.addItem(item);
- item->setRotation(rotationX, rotationY, rotationZ);
- item->setScale(scaleX, scaleY);
- item->setShear(shearX, shearY);
- item->setTransformOrigin(origin);
+ item->setRotation(rotation);
+ item->setScale(scale);
+ item->setTransformOriginPoint(origin);
- QCOMPARE(item->xRotation(), rotationX);
- QCOMPARE(item->yRotation(), rotationY);
- QCOMPARE(item->zRotation(), rotationZ);
- QCOMPARE(item->xScale(), scaleX);
- QCOMPARE(item->yScale(), scaleY);
- QCOMPARE(item->horizontalShear(), shearX);
- QCOMPARE(item->verticalShear(), shearY);
- QCOMPARE(item->transformOrigin(), origin);
+ QCOMPARE(item->rotation(), rotation);
+ QCOMPARE(item->scale(), scale);
+ QCOMPARE(item->transformOriginPoint(), origin);
QCOMPARE(QTransform(), item->transform());
QCOMPARE(result, item->sceneTransform());
//-----------------------------------------------------------------
//Change the rotation Z
- item->setZRotation(45);
+ item->setRotation(45);
QTransform result2;
result2.translate(origin.x(), origin.y());
- result2.rotate(rotationX, Qt::XAxis);
- result2.rotate(rotationY, Qt::YAxis);
- result2.rotate(45, Qt::ZAxis);
- result2.shear(shearX, shearY);
- result2.scale(scaleX, scaleY);
+ result2.rotate(45);
+ result2.scale(scale, scale);
result2.translate(-origin.x(), -origin.y());
- QCOMPARE(item->xRotation(), rotationX);
- QCOMPARE(item->yRotation(), rotationY);
- QCOMPARE(item->zRotation(), 45.0);
- QCOMPARE(item->xScale(), scaleX);
- QCOMPARE(item->yScale(), scaleY);
- QCOMPARE(item->horizontalShear(), shearX);
- QCOMPARE(item->verticalShear(), shearY);
- QCOMPARE(item->transformOrigin(), origin);
+ QCOMPARE(item->rotation(), 45.);
+ QCOMPARE(item->scale(), scale);
+ QCOMPARE(item->transformOriginPoint(), origin);
QCOMPARE(QTransform(), item->transform());
QCOMPARE(result2, item->sceneTransform());
//-----------------------------------------------------------------
- // calling setTransform() and setPos shoukld change the sceneTransform
+ // calling setTransform() and setPos should change the sceneTransform
item->setTransform(result);
item->setPos(100, -150.5);
- QCOMPARE(item->xRotation(), rotationX);
- QCOMPARE(item->yRotation(), rotationY);
- QCOMPARE(item->zRotation(), 45.0);
- QCOMPARE(item->xScale(), scaleX);
- QCOMPARE(item->yScale(), scaleY);
- QCOMPARE(item->horizontalShear(), shearX);
- QCOMPARE(item->verticalShear(), shearY);
- QCOMPARE(item->transformOrigin(), origin);
+ QCOMPARE(item->rotation(), 45.);
+ QCOMPARE(item->scale(), scale);
+ QCOMPARE(item->transformOriginPoint(), origin);
QCOMPARE(result, item->transform());
- QTransform result3;
+ QTransform result3(result);
result3.translate(origin.x(), origin.y());
- result3 = result * result3;
- result3.rotate(rotationX, Qt::XAxis);
- result3.rotate(rotationY, Qt::YAxis);
- result3.rotate(45, Qt::ZAxis);
- result3.shear(shearX, shearY);
- result3.scale(scaleX, scaleY);
+ result3.rotate(45);
+ result3.scale(scale, scale);
result3.translate(-origin.x(), -origin.y());
result3 *= QTransform::fromTranslate(100, -150.5); //the pos;
@@ -7034,10 +6981,9 @@ void tst_QGraphicsItem::setTransformProperties()
item1->setPos(12.3, -5);
item2->setPos(12.3, -5);
- item1->setRotation(rotationX, rotationY, rotationZ);
- item1->setScale(scaleX, scaleY);
- item1->setShear(shearX, shearY);
- item1->setTransformOrigin(origin);
+ item1->setRotation(rotation);
+ item1->setScale(scale);
+ item1->setTransformOriginPoint(origin);
item2->setTransform(result);
@@ -7046,36 +6992,6 @@ void tst_QGraphicsItem::setTransformProperties()
QCOMPARE_TRANSFORM(item1->itemTransform(item2), QTransform());
QCOMPARE_TRANSFORM(item2->itemTransform(item1), QTransform());
}
-
- {//with center origin on the item
- QGraphicsRectItem *item1 = new QGraphicsRectItem(QRectF(50.2, -150, 230.5, 119));
- scene.addItem(item1);
- QGraphicsRectItem *item2 = new QGraphicsRectItem(QRectF(50.2, -150, 230.5, 119));
- scene.addItem(item2);
-
- item1->setPos(12.3, -5);
- item2->setPos(12.3, -5);
- item1->setTransformOrigin(origin);
- item2->setTransformOrigin(origin);
-
- item1->setRotation(rotationX, rotationY, rotationZ);
- item1->setScale(scaleX, scaleY);
- item1->setShear(shearX, shearY);
-
- QTransform tr;
- tr.rotate(rotationX, Qt::XAxis);
- tr.rotate(rotationY, Qt::YAxis);
- tr.rotate(rotationZ, Qt::ZAxis);
- tr.shear(shearX, shearY);
- tr.scale(scaleX, scaleY);
-
- item2->setTransform(tr);
-
- QCOMPARE_TRANSFORM(item1->sceneTransform(), item2->sceneTransform());
-
- QCOMPARE_TRANSFORM(item1->itemTransform(item2), QTransform());
- QCOMPARE_TRANSFORM(item2->itemTransform(item1), QTransform());
- }
}
class MyStyleOptionTester : public QGraphicsRectItem
diff --git a/tests/auto/qgraphicstransform/qgraphicstransform.pro b/tests/auto/qgraphicstransform/qgraphicstransform.pro
new file mode 100644
index 0000000..709cff6
--- /dev/null
+++ b/tests/auto/qgraphicstransform/qgraphicstransform.pro
@@ -0,0 +1,2 @@
+load(qttest_p4)
+SOURCES += tst_qgraphicstransform.cpp
diff --git a/tests/auto/qgraphicstransform/tst_qgraphicstransform.cpp b/tests/auto/qgraphicstransform/tst_qgraphicstransform.cpp
new file mode 100644
index 0000000..672b1f1
--- /dev/null
+++ b/tests/auto/qgraphicstransform/tst_qgraphicstransform.cpp
@@ -0,0 +1,162 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://www.qtsoftware.com/contact.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#include <QtTest/QtTest>
+#include <qgraphicsitem.h>
+#include <qgraphicstransform.h>
+#include "../../shared/util.h"
+
+class tst_QGraphicsTransform : public QObject {
+ Q_OBJECT
+
+public slots:
+ void initTestCase();
+ void cleanupTestCase();
+ void init();
+ void cleanup();
+
+private slots:
+ void scale();
+ void rotation();
+ void rotation3d();
+};
+
+
+// This will be called before the first test function is executed.
+// It is only called once.
+void tst_QGraphicsTransform::initTestCase()
+{
+}
+
+// This will be called after the last test function is executed.
+// It is only called once.
+void tst_QGraphicsTransform::cleanupTestCase()
+{
+}
+
+// This will be called before each test function is executed.
+void tst_QGraphicsTransform::init()
+{
+}
+
+// This will be called after every test function.
+void tst_QGraphicsTransform::cleanup()
+{
+}
+
+
+void tst_QGraphicsTransform::scale()
+{
+ QGraphicsScale scale;
+ scale.setOrigin(QPointF(10, 10));
+
+ QTransform t;
+ scale.applyTo(&t);
+
+ QCOMPARE(t, QTransform());
+ QCOMPARE(scale.transform(), QTransform());
+
+ scale.setXScale(10);
+ scale.setOrigin(QPointF(0, 0));
+
+ QTransform res;
+ res.scale(10, 1);
+
+ QCOMPARE(scale.transform(), res);
+ QCOMPARE(scale.transform().map(QPointF(10, 10)), QPointF(100, 10));
+
+ scale.setOrigin(QPointF(10, 10));
+ QCOMPARE(scale.transform().map(QPointF(10, 10)), QPointF(10, 10));
+ QCOMPARE(scale.transform().map(QPointF(11, 10)), QPointF(20, 10));
+}
+
+void tst_QGraphicsTransform::rotation()
+{
+ QGraphicsRotation rotation;
+ rotation.setOrigin(QPointF(10, 10));
+
+ QTransform t;
+ rotation.applyTo(&t);
+
+ QCOMPARE(t, QTransform());
+ QCOMPARE(rotation.transform(), QTransform());
+
+ rotation.setAngle(40);
+ rotation.setOrigin(QPointF(0, 0));
+
+ QTransform res;
+ res.rotate(40);
+
+ QCOMPARE(rotation.transform(), res);
+
+ rotation.setOrigin(QPointF(10, 10));
+ rotation.setAngle(90);
+ QCOMPARE(rotation.transform().map(QPointF(10, 10)), QPointF(10, 10));
+ QCOMPARE(rotation.transform().map(QPointF(20, 10)), QPointF(10, 20));
+}
+
+void tst_QGraphicsTransform::rotation3d()
+{
+ QGraphicsRotation3D rotation;
+ rotation.setOrigin(QPointF(10, 10));
+
+ QTransform t;
+ rotation.applyTo(&t);
+
+ QCOMPARE(t, QTransform());
+ QCOMPARE(rotation.transform(), QTransform());
+
+ rotation.setAngle(180);
+
+ QCOMPARE(t, QTransform());
+ QCOMPARE(rotation.transform(), QTransform());
+
+ rotation.setOrigin(QPointF(0, 0));
+
+ QCOMPARE(t, QTransform());
+ QCOMPARE(rotation.transform(), QTransform());
+}
+
+
+QTEST_MAIN(tst_QGraphicsTransform)
+#include "tst_qgraphicstransform.moc"
+