diff options
author | Olivier Goffart <ogoffart@trolltech.com> | 2009-05-20 14:38:47 (GMT) |
---|---|---|
committer | Olivier Goffart <ogoffart@trolltech.com> | 2009-05-22 09:09:27 (GMT) |
commit | 8ad5020940f10d4ecc5c5e8b3b9656531cb84ef3 (patch) | |
tree | 08d6a137fb06db2c7e78de36d94f146ffd460d76 /tests/benchmarks | |
parent | ab1b7f137350d6eeafec2a64e3c25a4b02be65a9 (diff) | |
download | Qt-8ad5020940f10d4ecc5c5e8b3b9656531cb84ef3.zip Qt-8ad5020940f10d4ecc5c5e8b3b9656531cb84ef3.tar.gz Qt-8ad5020940f10d4ecc5c5e8b3b9656531cb84ef3.tar.bz2 |
Add properties to QGraphicsItem to change the transformations component
With the new properties it is possible to easily animate.
Setting a transform using setTransform is incompatible with thoses
properties. Accessing thoses propeties if you set previously a
transform will give you the default values.
Acknowledged-by: Code made with Andreas. Documentation written with Thierry.
This still need a more in depth code review and documentation review.
But it is urgent to commit now because the Animation API integration depends on it.
Diffstat (limited to 'tests/benchmarks')
-rw-r--r-- | tests/benchmarks/qgraphicsitem/qgraphicsitem.pro | 6 | ||||
-rw-r--r-- | tests/benchmarks/qgraphicsitem/tst_qgraphicsitem.cpp | 170 |
2 files changed, 176 insertions, 0 deletions
diff --git a/tests/benchmarks/qgraphicsitem/qgraphicsitem.pro b/tests/benchmarks/qgraphicsitem/qgraphicsitem.pro new file mode 100644 index 0000000..c8fc07b --- /dev/null +++ b/tests/benchmarks/qgraphicsitem/qgraphicsitem.pro @@ -0,0 +1,6 @@ +load(qttest_p4) +TEMPLATE = app +TARGET = tst_qgraphicsitem + +SOURCES += tst_qgraphicsitem.cpp + diff --git a/tests/benchmarks/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/benchmarks/qgraphicsitem/tst_qgraphicsitem.cpp new file mode 100644 index 0000000..68e3aa1 --- /dev/null +++ b/tests/benchmarks/qgraphicsitem/tst_qgraphicsitem.cpp @@ -0,0 +1,170 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +****************************************************************************/ + +#include <qtest.h> +#include <QGraphicsItem> +#include <QGraphicsScene> +#include <QGraphicsView> + +//TESTED_FILES= + +class tst_QGraphicsItem : public QObject +{ + Q_OBJECT + +public: + tst_QGraphicsItem(); + virtual ~tst_QGraphicsItem(); + +public slots: + void init(); + void cleanup(); + +private slots: + void setPos_data(); + void setPos(); + void setTransform_data(); + void setTransform(); + void rotate(); + void scale(); + void shear(); + void translate(); + void setRotation(); + void setRotationXYZ(); +}; + +tst_QGraphicsItem::tst_QGraphicsItem() +{ +} + +tst_QGraphicsItem::~tst_QGraphicsItem() +{ +} + +void tst_QGraphicsItem::init() +{ +} + +void tst_QGraphicsItem::cleanup() +{ +} + +void tst_QGraphicsItem::setPos_data() +{ + QTest::addColumn<QPointF>("pos"); + + QTest::newRow("0, 0") << QPointF(0, 0); + QTest::newRow("10, 10") << QPointF(10, 10); + QTest::newRow("-10, -10") << QPointF(-10, -10); +} + +void tst_QGraphicsItem::setPos() +{ + QFETCH(QPointF, pos); + + QGraphicsScene scene; + QGraphicsRectItem *rect = scene.addRect(QRectF(0, 0, 100, 100)); + + QBENCHMARK { + rect->setPos(10, 10); + rect->transform(); // prevent lazy optimizing + } +} + +void tst_QGraphicsItem::setTransform_data() +{ + QTest::addColumn<QTransform>("transform"); + + QTest::newRow("id") << QTransform(); + QTest::newRow("rotate 45z") << QTransform().rotate(45); + QTest::newRow("scale 2x2") << QTransform().scale(2, 2); + QTest::newRow("translate 100, 100") << QTransform().translate(100, 100); + QTest::newRow("rotate 45x 45y 45z") << QTransform().rotate(45, Qt::XAxis) + .rotate(45, Qt::YAxis).rotate(45, Qt::ZAxis); +} + +void tst_QGraphicsItem::setTransform() +{ + QFETCH(QTransform, transform); + + QGraphicsScene scene; + QGraphicsRectItem *item = scene.addRect(QRectF(0, 0, 100, 100)); + + QBENCHMARK { + item->setTransform(transform); + item->transform(); // prevent lazy optimizing + } +} + +void tst_QGraphicsItem::rotate() +{ + QGraphicsScene scene; + QGraphicsItem *item = scene.addRect(QRectF(0, 0, 100, 100)); + + QBENCHMARK { + item->rotate(45); + item->transform(); // prevent lazy optimizing + } +} + +void tst_QGraphicsItem::scale() +{ + QGraphicsScene scene; + QGraphicsItem *item = scene.addRect(QRectF(0, 0, 100, 100)); + + QBENCHMARK { + item->scale(2, 2); + item->transform(); // prevent lazy optimizing + } +} + +void tst_QGraphicsItem::shear() +{ + QGraphicsScene scene; + QGraphicsItem *item = scene.addRect(QRectF(0, 0, 100, 100)); + + QBENCHMARK { + item->shear(1.5, 1.5); + item->transform(); // prevent lazy optimizing + } +} + +void tst_QGraphicsItem::translate() +{ + QGraphicsScene scene; + QGraphicsItem *item = scene.addRect(QRectF(0, 0, 100, 100)); + + QBENCHMARK { + item->translate(100, 100); + item->transform(); // prevent lazy optimizing + } +} + +void tst_QGraphicsItem::setRotation() +{ + QGraphicsScene scene; + QGraphicsItem *item = scene.addRect(QRectF(0, 0, 100, 100)); + + QBENCHMARK { + item->setXRotation(45); + item->transform(); // prevent lazy optimizing + } +} + +void tst_QGraphicsItem::setRotationXYZ() +{ + QGraphicsScene scene; + QGraphicsItem *item = scene.addRect(QRectF(0, 0, 100, 100)); + + QBENCHMARK { + item->setRotation(45, 45, 45); + item->transform(); // prevent lazy optimizing + } +} + +QTEST_MAIN(tst_QGraphicsItem) +#include "tst_qgraphicsitem.moc" |