diff options
author | Bea Lam <bea.lam@nokia.com> | 2010-03-04 23:46:34 (GMT) |
---|---|---|
committer | Bea Lam <bea.lam@nokia.com> | 2010-03-04 23:46:34 (GMT) |
commit | 81952293be3328dc2f62f557478042d1e8d04e0d (patch) | |
tree | f1d12875e61e6a530bb0f3abfde1e8e07203780c /tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp | |
parent | 564baee7e729f1c6f766cecabc4fcc62291e0d0f (diff) | |
download | Qt-81952293be3328dc2f62f557478042d1e8d04e0d.zip Qt-81952293be3328dc2f62f557478042d1e8d04e0d.tar.gz Qt-81952293be3328dc2f62f557478042d1e8d04e0d.tar.bz2 |
Add mapFromItem() and mapToItem() in QDeclarativeItem.
Task-number: QT-2385
Diffstat (limited to 'tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp')
-rw-r--r-- | tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp b/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp index 36dcf1f..3e69db9 100644 --- a/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp +++ b/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp @@ -58,6 +58,8 @@ private slots: void keyNavigation(); void smooth(); void clip(); + void mapCoordinates(); + void mapCoordinates_data(); private: template<typename T> @@ -288,6 +290,62 @@ void tst_QDeclarativeItem::clip() QCOMPARE(spy.count(),2); } +void tst_QDeclarativeItem::mapCoordinates() +{ + QFETCH(int, x); + QFETCH(int, y); + + QDeclarativeView *canvas = new QDeclarativeView(0); + canvas->setFixedSize(300, 300); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/mapCoordinates.qml")); + canvas->show(); + qApp->processEvents(); + + QDeclarativeItem *root = qobject_cast<QDeclarativeItem*>(canvas->rootObject()); + QVERIFY(root != 0); + QDeclarativeItem *a = findItem<QDeclarativeItem>(canvas->rootObject(), "itemA"); + QVERIFY(a != 0); + QDeclarativeItem *b = findItem<QDeclarativeItem>(canvas->rootObject(), "itemB"); + QVERIFY(b != 0); + + QVariant result; + + QVERIFY(QMetaObject::invokeMethod(root, "mapAToB", + Q_RETURN_ARG(QVariant, result), Q_ARG(QVariant, x), Q_ARG(QVariant, y))); + QCOMPARE(result.value<QPointF>(), qobject_cast<QGraphicsItem*>(a)->mapToItem(b, x, y)); + + QVERIFY(QMetaObject::invokeMethod(root, "mapAFromB", + Q_RETURN_ARG(QVariant, result), Q_ARG(QVariant, x), Q_ARG(QVariant, y))); + QCOMPARE(result.value<QPointF>(), qobject_cast<QGraphicsItem*>(a)->mapFromItem(b, x, y)); + + QVERIFY(QMetaObject::invokeMethod(root, "mapAToNull", + Q_RETURN_ARG(QVariant, result), Q_ARG(QVariant, x), Q_ARG(QVariant, y))); + QCOMPARE(result.value<QPointF>(), qobject_cast<QGraphicsItem*>(a)->mapToScene(x, y)); + + QVERIFY(QMetaObject::invokeMethod(root, "mapAFromNull", + Q_RETURN_ARG(QVariant, result), Q_ARG(QVariant, x), Q_ARG(QVariant, y))); + QCOMPARE(result.value<QPointF>(), qobject_cast<QGraphicsItem*>(a)->mapFromScene(x, y)); + + QTest::ignoreMessage(QtWarningMsg, "mapToItem() given argument \"1122\" which is neither null nor an Item"); + QVERIFY(QMetaObject::invokeMethod(root, "checkMapAToInvalid", + Q_RETURN_ARG(QVariant, result), Q_ARG(QVariant, x), Q_ARG(QVariant, y))); + QVERIFY(result.toBool()); + + QTest::ignoreMessage(QtWarningMsg, "mapFromItem() given argument \"1122\" which is neither null nor an Item"); + QVERIFY(QMetaObject::invokeMethod(root, "checkMapAFromInvalid", + Q_RETURN_ARG(QVariant, result), Q_ARG(QVariant, x), Q_ARG(QVariant, y))); + QVERIFY(result.toBool()); +} + +void tst_QDeclarativeItem::mapCoordinates_data() +{ + QTest::addColumn<int>("x"); + QTest::addColumn<int>("y"); + + for (int i=-20; i<=20; i+=10) + QTest::newRow(QTest::toString(i)) << i << i; +} + template<typename T> T *tst_QDeclarativeItem::findItem(QGraphicsObject *parent, const QString &objectName) { |