diff options
author | Daniel d'Andrada <daniel.dandrada@canonical.com> | 2013-11-12 11:47:32 -0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-11-29 09:23:24 +0100 |
commit | 536e1cccf15963b586f3112a0654ddc0d101fa69 (patch) | |
tree | 93809227cde9608ee662faa9c31259f73414bd89 /tests/auto/quick/qquickwindow | |
parent | 9e345ab3c549851a273df62497f93ad9593385c9 (diff) |
Fix delivery of QEvents to QQuickItems
Make them go through QObject::event() and comply to filtering
from objects passsed to QObject::installEventFilter()
Task-number: QTBUG-32004
Change-Id: Ib6972e7f5e588bee986ae5f2d69aa6fccb58af95
Reviewed-by: J-P Nurmi <jpnurmi@digia.com>
Reviewed-by: Alan Alpert <aalpert@blackberry.com>
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@digia.com>
Diffstat (limited to 'tests/auto/quick/qquickwindow')
-rw-r--r-- | tests/auto/quick/qquickwindow/tst_qquickwindow.cpp | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp b/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp index 984881c8da..1d9beedbab 100644 --- a/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp +++ b/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp @@ -250,6 +250,18 @@ int TestTouchItem::mousePressNum = 0; int TestTouchItem::mouseMoveNum = 0; int TestTouchItem::mouseReleaseNum = 0; +class EventFilter : public QObject +{ +public: + bool eventFilter(QObject *watched, QEvent *event) { + Q_UNUSED(watched); + events.append(event->type()); + return false; + } + + QList<int> events; +}; + class ConstantUpdateItem : public QQuickItem { Q_OBJECT @@ -330,6 +342,10 @@ private slots: void crashWhenHoverItemDeleted(); + void qobjectEventFilter_touch(); + void qobjectEventFilter_key(); + void qobjectEventFilter_mouse(); + #ifndef QT_NO_CURSOR void cursor(); #endif @@ -922,6 +938,9 @@ void tst_qquickwindow::mouseFiltering() QTRY_COMPARE(middleItem->mousePressId, 1); QTRY_COMPARE(bottomItem->mousePressId, 2); QTRY_COMPARE(topItem->mousePressId, 3); + + // clean up mouse press state for the next tests + QTest::mouseRelease(window, Qt::LeftButton, 0, pos); } void tst_qquickwindow::qmlCreation() @@ -1525,6 +1544,84 @@ void tst_qquickwindow::crashWhenHoverItemDeleted() } } +// QTBUG-32004 +void tst_qquickwindow::qobjectEventFilter_touch() +{ + QQuickWindow window; + + window.resize(250, 250); + window.setPosition(100, 100); + window.show(); + QVERIFY(QTest::qWaitForWindowExposed(&window)); + + TestTouchItem *item = new TestTouchItem(window.contentItem()); + item->setSize(QSizeF(150, 150)); + + EventFilter eventFilter; + item->installEventFilter(&eventFilter); + + QPointF pos(10, 10); + + // press single point + QTest::touchEvent(&window, touchDevice).press(0, item->mapToScene(pos).toPoint(), &window); + + QCOMPARE(eventFilter.events.count(), 1); + QCOMPARE(eventFilter.events.first(), (int)QEvent::TouchBegin); +} + +// QTBUG-32004 +void tst_qquickwindow::qobjectEventFilter_key() +{ + QQuickWindow window; + + window.resize(250, 250); + window.setPosition(100, 100); + window.show(); + QVERIFY(QTest::qWaitForWindowExposed(&window)); + + TestTouchItem *item = new TestTouchItem(window.contentItem()); + item->setSize(QSizeF(150, 150)); + item->setFocus(true); + + EventFilter eventFilter; + item->installEventFilter(&eventFilter); + + QTest::keyPress(&window, Qt::Key_A); + + // NB: It may also receive some QKeyEvent(ShortcutOverride) which we're not interested in + QVERIFY(eventFilter.events.contains((int)QEvent::KeyPress)); + eventFilter.events.clear(); + + QTest::keyRelease(&window, Qt::Key_A); + + QVERIFY(eventFilter.events.contains((int)QEvent::KeyRelease)); +} + +// QTBUG-32004 +void tst_qquickwindow::qobjectEventFilter_mouse() +{ + QQuickWindow window; + + window.resize(250, 250); + window.setPosition(100, 100); + window.show(); + QVERIFY(QTest::qWaitForWindowExposed(&window)); + + TestTouchItem *item = new TestTouchItem(window.contentItem()); + item->setSize(QSizeF(150, 150)); + + EventFilter eventFilter; + item->installEventFilter(&eventFilter); + + QPoint point = item->mapToScene(QPointF(10, 10)).toPoint(); + QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, point); + + QVERIFY(eventFilter.events.contains((int)QEvent::MouseButtonPress)); + + // clean up mouse press state for the next tests + QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, point); +} + QTEST_MAIN(tst_qquickwindow) #include "tst_qquickwindow.moc" |