diff options
author | Jonathan Liu <net147@gmail.com> | 2012-02-23 13:53:56 (GMT) |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-02-28 14:35:06 (GMT) |
commit | aaa46755dcc15b8baaa0d1b928828eb60e0babbc (patch) | |
tree | abe10c256b0a741a25db5762ded89da19f432182 /tests | |
parent | 15c14584199dc43e4a309fc331f3144009008128 (diff) | |
download | Qt-aaa46755dcc15b8baaa0d1b928828eb60e0babbc.zip Qt-aaa46755dcc15b8baaa0d1b928828eb60e0babbc.tar.gz Qt-aaa46755dcc15b8baaa0d1b928828eb60e0babbc.tar.bz2 |
Add additional QGraphicsView tests for regression
Add additional tests for graphics view tooltip regression introduced by
7c0d15a22266a425c9e9ac0120d6774e120fe01e.
Task-number: QTBUG-17517
Task-number: QTBUG-22663
Change-Id: I5e0d0e19504730a3e14ac84712a366dbebe688e6
Reviewed-by: Robin Burchell <robin+qt@viroteck.net>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qgraphicsview/tst_qgraphicsview.cpp | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/tests/auto/qgraphicsview/tst_qgraphicsview.cpp b/tests/auto/qgraphicsview/tst_qgraphicsview.cpp index ce7841d..68b7174 100644 --- a/tests/auto/qgraphicsview/tst_qgraphicsview.cpp +++ b/tests/auto/qgraphicsview/tst_qgraphicsview.cpp @@ -70,6 +70,7 @@ #include <QtGui/QPushButton> #include <QtGui/QInputContext> #include <QtGui/QDesktopWidget> +#include <private/qgraphicsscene_p.h> #include <private/qgraphicsview_p.h> #include "../../shared/util.h" #include "../platformquirks.h" @@ -138,6 +139,14 @@ protected: QEvent::Type spied; }; +#if defined QT_BUILD_INTERNAL +class FriendlyGraphicsScene : public QGraphicsScene +{ + friend class tst_QGraphicsView; + Q_DECLARE_PRIVATE(QGraphicsScene); +}; +#endif + class tst_QGraphicsView : public QObject { Q_OBJECT @@ -168,6 +177,10 @@ private slots: void ensureVisibleRect(); void fitInView(); void itemsAtPoint(); +#if defined QT_BUILD_INTERNAL + void itemsAtPosition_data(); + void itemsAtPosition(); +#endif void itemsInRect(); void itemsInRect_cosmeticAdjust_data(); void itemsInRect_cosmeticAdjust(); @@ -1346,6 +1359,54 @@ void tst_QGraphicsView::itemsAtPoint() QCOMPARE(items.takeFirst()->zValue(), qreal(-1)); } +#if defined QT_BUILD_INTERNAL +void tst_QGraphicsView::itemsAtPosition_data() +{ + QTest::addColumn<float>("rotation"); + QTest::addColumn<float>("scale"); + QTest::addColumn<QPoint>("viewPos"); + QTest::addColumn<bool>("ignoreTransform"); + QTest::addColumn<bool>("hit"); + QTest::newRow("scaled + ignore transform, no hit") << 0.0f << 1000.0f << QPoint(0, 0) << true << false; + QTest::newRow("scaled + ignore transform, hit") << 0.0f << 1000.0f << QPoint(100, 100) << true << true; + QTest::newRow("rotated + scaled, no hit") << 45.0f << 2.0f << QPoint(90, 90) << false << false; + QTest::newRow("rotated + scaled, hit") << 45.0f << 2.0f << QPoint(100, 100) << false << true; +} + +void tst_QGraphicsView::itemsAtPosition() +{ + QFETCH(float, rotation); + QFETCH(float, scale); + QFETCH(QPoint, viewPos); + QFETCH(bool, ignoreTransform); + QFETCH(bool, hit); + + FriendlyGraphicsScene scene; + scene.setSceneRect(QRect(-100, -100, 200, 200)); + QGraphicsItem *item = scene.addRect(-5, -5, 10, 10); + + if (ignoreTransform) + item->setFlag(QGraphicsItem::ItemIgnoresTransformations); + + QGraphicsView view; + view.resize(200, 200); + view.scale(scale, scale); + view.rotate(rotation); + view.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + view.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + view.setScene(&scene); + view.show(); + QTest::qWaitForWindowShown(&view); + + QPoint screenPos = view.viewport()->mapToGlobal(viewPos); + QPointF scenePos = view.mapToScene(viewPos); + QGraphicsScenePrivate *viewPrivate = scene.d_func(); + QList<QGraphicsItem *> items; + items = viewPrivate->itemsAtPosition(screenPos, scenePos, view.viewport()); + QCOMPARE(!items.empty(), hit); +} +#endif + void tst_QGraphicsView::itemsInRect() { QGraphicsScene scene; |