summaryrefslogtreecommitdiffstats
path: root/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@nokia.com>2009-07-29 02:26:43 +0200
committerLars Knoll <lars.knoll@nokia.com>2009-07-29 02:26:44 +0200
commita6ea9ce6990003856ecadcca8ce9ddf37949363d (patch)
tree32bce99c4cf28cb922feca329f848ac0c5c47f42 /tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
parent62d81d9955f39bac327affd703b9df006ee8f6f7 (diff)
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/auto/qgraphicsitem/tst_qgraphicsitem.cpp')
-rw-r--r--tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp158
1 files changed, 37 insertions, 121 deletions
diff --git a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
index 9f1693dc87..7f6f322261 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