From 307403f8b4f25f3fa711fb64102c755d50283c2b Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Fri, 5 Jul 2019 17:20:14 +0200 Subject: Stabilize QGraphicsItem::cursor and select_multi tests The tests send QEvent::MouseMove events to the view, but don't fully construct the event with both local and global position. Consequently, QMouseEvent will use QCursor::pos as the global position, which is unreliable, as QTest::mouseMove can not guarantee that the mouse really moves - when running the tests locally on e.g macOS, it never does. So instead construct the QMouseEvent with the trivially calculated global position. Change-Id: Ic4c914e3af7f15751545080d4743b06d3887cce8 Reviewed-by: Andreas Aardal Hanssen --- .../qgraphicsitem/tst_qgraphicsitem.cpp | 26 +++++++++++++--------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'tests/auto/widgets/graphicsview') diff --git a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp index ae0d91dfe3..af4b6c9e4a 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp @@ -1811,7 +1811,8 @@ void tst_QGraphicsItem::selected_multi() { // Ctrl-move on item1 - QMouseEvent event(QEvent::MouseMove, view.mapFromScene(item1->scenePos()) + QPoint(1, 0), Qt::LeftButton, Qt::LeftButton, Qt::ControlModifier); + const QPoint item1Point = view.mapFromScene(item1->scenePos()) + QPoint(1, 0); + QMouseEvent event(QEvent::MouseMove, item1Point, view.viewport()->mapToGlobal(item1Point), Qt::LeftButton, Qt::LeftButton, Qt::ControlModifier); QApplication::sendEvent(view.viewport(), &event); QVERIFY(!item1->isSelected()); QVERIFY(!item2->isSelected()); @@ -1832,7 +1833,8 @@ void tst_QGraphicsItem::selected_multi() { // Ctrl-move on item1 - QMouseEvent event(QEvent::MouseMove, view.mapFromScene(item1->scenePos()) + QPoint(1, 0), Qt::LeftButton, Qt::LeftButton, Qt::ControlModifier); + const QPoint item1Point = view.mapFromScene(item1->scenePos()) + QPoint(1, 0); + QMouseEvent event(QEvent::MouseMove, item1Point, view.viewport()->mapToGlobal(item1Point), Qt::LeftButton, Qt::LeftButton, Qt::ControlModifier); QApplication::sendEvent(view.viewport(), &event); QVERIFY(item1->isSelected()); QVERIFY(!item2->isSelected()); @@ -4178,37 +4180,41 @@ void tst_QGraphicsItem::cursor() item1->setCursor(Qt::IBeamCursor); item2->setCursor(Qt::PointingHandCursor); - QTest::mouseMove(&view, view.rect().center()); + QPoint viewCenter = view.rect().center(); + QPoint item1Center = view.mapFromScene(item1->sceneBoundingRect().center()); + QPoint item2Center = view.mapFromScene(item2->sceneBoundingRect().center()); + + QTest::mouseMove(&view, viewCenter); const Qt::CursorShape viewportShape = view.viewport()->cursor().shape(); { QTest::mouseMove(view.viewport(), QPoint(100, 50)); - QMouseEvent event(QEvent::MouseMove, QPoint(100, 50), Qt::NoButton, 0, 0); + QMouseEvent event(QEvent::MouseMove, QPoint(100, 50), view.viewport()->mapToGlobal(QPoint(100, 50)), Qt::NoButton, 0, 0); QApplication::sendEvent(view.viewport(), &event); } QTRY_COMPARE(view.viewport()->cursor().shape(), viewportShape); { - QTest::mouseMove(view.viewport(), view.mapFromScene(item1->sceneBoundingRect().center())); - QMouseEvent event(QEvent::MouseMove, view.mapFromScene(item1->sceneBoundingRect().center()), Qt::NoButton, 0, 0); + QTest::mouseMove(view.viewport(), item1Center); + QMouseEvent event(QEvent::MouseMove, item1Center, view.viewport()->mapToGlobal(item1Center), Qt::NoButton, 0, 0); QApplication::sendEvent(view.viewport(), &event); } QTRY_COMPARE(view.viewport()->cursor().shape(), item1->cursor().shape()); { - QTest::mouseMove(view.viewport(), view.mapFromScene(item2->sceneBoundingRect().center())); - QMouseEvent event(QEvent::MouseMove, view.mapFromScene(item2->sceneBoundingRect().center()), Qt::NoButton, 0, 0); + QTest::mouseMove(view.viewport(), item2Center); + QMouseEvent event(QEvent::MouseMove, item2Center, view.viewport()->mapToGlobal(item2Center), Qt::NoButton, 0, 0); QApplication::sendEvent(view.viewport(), &event); } QTRY_COMPARE(view.viewport()->cursor().shape(), item2->cursor().shape()); { - QTest::mouseMove(view.viewport(), view.rect().center()); - QMouseEvent event(QEvent::MouseMove, QPoint(100, 25), Qt::NoButton, 0, 0); + QTest::mouseMove(view.viewport(), viewCenter); + QMouseEvent event(QEvent::MouseMove, QPoint(100, 25), view.viewport()->mapToGlobal(QPoint(100, 50)), Qt::NoButton, 0, 0); QApplication::sendEvent(view.viewport(), &event); } -- cgit v1.2.3 From d8688d44840dd3f2324769d10b927c442b42e2c0 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Fri, 5 Jul 2019 17:24:22 +0200 Subject: Don't set the mouse cursor for items that are disabled As with widgets, items that are disabled should not receive any input events. Similar to QGraphicsScene, which ignores disabled items when handling mouse presses, the view should also ignore them when handling mouse moves to update the cursor. Since QGraphicsView only adjusts the cursors on mouse moves, reenabling an item that is currently under the mouse will not change the cursor. This is consistent with other changes of item attributes that would position the item under the mouse (such as moving it). The overhead of hit-testing items for every such attribute change would be too large, and applications can generate a mouse move event if they really need to adjust the cursor in all situations. [ChangeLog][QtWidgets][QGraphicsView] Ignore disabled items when setting the mouse cursor. Fixes: QTBUG-76765 Change-Id: Ifcd31fc0581e8421e58eeb436a55b031909eed7e Reviewed-by: Shawn Rutledge --- .../widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'tests/auto/widgets/graphicsview') diff --git a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp index af4b6c9e4a..3260e09943 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp @@ -4219,6 +4219,15 @@ void tst_QGraphicsItem::cursor() } QTRY_COMPARE(view.viewport()->cursor().shape(), viewportShape); + + item1->setEnabled(false); + { + QTest::mouseMove(view.viewport(), item1Center); + QMouseEvent event(QEvent::MouseMove, item1Center, view.viewport()->mapToGlobal(item1Center), Qt::NoButton, 0, 0); + QApplication::sendEvent(view.viewport(), &event); + } + + QTRY_COMPARE(view.viewport()->cursor().shape(), viewportShape); } #endif /* -- cgit v1.2.3 From 59b29d03b2fff8a138382d45077c81fe0d4b8ea8 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Tue, 9 Jul 2019 15:18:46 +0200 Subject: Further stabilization of QGraphicsItem::cursor test The QTest::mouseMove calls are not reliable, and seem to produce flakiness, at least on WinRT. Removing them, and only depending on handling of the synchronously delivered QMouseEVent for simulated mouse moves. Also, initialize the expected cursor shape from an empty scene; this avoids that showing the view with the cursor accidentially on an item results in the wrong default shape. Remove hard coded coordinates, just test what we know. Fixes: QTBUG-73545 Change-Id: I6f81d6b16bb613ec77aaa776d6a80aac739aeb58 Reviewed-by: Volker Hilsheimer --- .../qgraphicsitem/tst_qgraphicsitem.cpp | 25 ++++++++-------------- 1 file changed, 9 insertions(+), 16 deletions(-) (limited to 'tests/auto/widgets/graphicsview') diff --git a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp index 3260e09943..e071edc332 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp @@ -4153,6 +4153,8 @@ void tst_QGraphicsItem::cursor() QGraphicsView view(&scene); view.showFullScreen(); QVERIFY(QTest::qWaitForWindowExposed(&view)); + const Qt::CursorShape viewportShape = view.viewport()->cursor().shape(); + QGraphicsRectItem *item1 = scene.addRect(QRectF(-100, 0, 50, 50)); QGraphicsRectItem *item2 = scene.addRect(QRectF(50, 0, 50, 50)); @@ -4184,50 +4186,41 @@ void tst_QGraphicsItem::cursor() QPoint item1Center = view.mapFromScene(item1->sceneBoundingRect().center()); QPoint item2Center = view.mapFromScene(item2->sceneBoundingRect().center()); - QTest::mouseMove(&view, viewCenter); - - const Qt::CursorShape viewportShape = view.viewport()->cursor().shape(); - { - QTest::mouseMove(view.viewport(), QPoint(100, 50)); - QMouseEvent event(QEvent::MouseMove, QPoint(100, 50), view.viewport()->mapToGlobal(QPoint(100, 50)), Qt::NoButton, 0, 0); + QMouseEvent event(QEvent::MouseMove, viewCenter, view.viewport()->mapToGlobal(viewCenter), Qt::NoButton, 0, 0); QApplication::sendEvent(view.viewport(), &event); } - QTRY_COMPARE(view.viewport()->cursor().shape(), viewportShape); + QCOMPARE(view.viewport()->cursor().shape(), viewportShape); { - QTest::mouseMove(view.viewport(), item1Center); QMouseEvent event(QEvent::MouseMove, item1Center, view.viewport()->mapToGlobal(item1Center), Qt::NoButton, 0, 0); QApplication::sendEvent(view.viewport(), &event); } - QTRY_COMPARE(view.viewport()->cursor().shape(), item1->cursor().shape()); + QCOMPARE(view.viewport()->cursor().shape(), item1->cursor().shape()); { - QTest::mouseMove(view.viewport(), item2Center); QMouseEvent event(QEvent::MouseMove, item2Center, view.viewport()->mapToGlobal(item2Center), Qt::NoButton, 0, 0); QApplication::sendEvent(view.viewport(), &event); } - QTRY_COMPARE(view.viewport()->cursor().shape(), item2->cursor().shape()); + QCOMPARE(view.viewport()->cursor().shape(), item2->cursor().shape()); { - QTest::mouseMove(view.viewport(), viewCenter); - QMouseEvent event(QEvent::MouseMove, QPoint(100, 25), view.viewport()->mapToGlobal(QPoint(100, 50)), Qt::NoButton, 0, 0); + QMouseEvent event(QEvent::MouseMove, viewCenter, view.viewport()->mapToGlobal(viewCenter), Qt::NoButton, 0, 0); QApplication::sendEvent(view.viewport(), &event); } - QTRY_COMPARE(view.viewport()->cursor().shape(), viewportShape); + QCOMPARE(view.viewport()->cursor().shape(), viewportShape); item1->setEnabled(false); { - QTest::mouseMove(view.viewport(), item1Center); QMouseEvent event(QEvent::MouseMove, item1Center, view.viewport()->mapToGlobal(item1Center), Qt::NoButton, 0, 0); QApplication::sendEvent(view.viewport(), &event); } - QTRY_COMPARE(view.viewport()->cursor().shape(), viewportShape); + QCOMPARE(view.viewport()->cursor().shape(), viewportShape); } #endif /* -- cgit v1.2.3 From b426cff1e0363b350f98bc64691b9b279bc6c757 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Wed, 3 Jul 2019 16:25:54 +0200 Subject: Make tst_QGraphicsItem painting tests most robust Counting absolute paint events is fragile, as there are no guarantees that a single call to QApp::processEvents only delivers a single paint event to a widget. As of QTBUG-76566, we see that the items occasionally receive three calls to paint, which can be simulated by activating other windows while the test is running and waiting for events to be processed. Instead, verify that we do receive any paint events as the first test, and then verify increments when we expect updates. This also reverts change 24b9424adcda1ab083fae4ae857007227ba5fee2. Change-Id: Ib51853e918f31acd3aea10d4109c95f34012a29f Fixes: QTBUG-76566 Reviewed-by: Dimitrios Apostolou Reviewed-by: Andreas Aardal Hanssen --- .../qgraphicsitem/tst_qgraphicsitem.cpp | 25 ++++++++++------------ 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'tests/auto/widgets/graphicsview') diff --git a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp index e071edc332..872e0b62c5 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp @@ -5057,12 +5057,6 @@ public: void tst_QGraphicsItem::paint() { -#if defined(Q_OS_MACOS) - if (QSysInfo::productVersion() == QLatin1String("10.12")) { - QSKIP("Test is very flaky on MacOS_10_12, see QTBUG-76566"); - } -#endif - QGraphicsScene scene; PaintTester paintTester; @@ -5092,22 +5086,25 @@ void tst_QGraphicsItem::paint() PaintTester tester2; scene2.addItem(&tester2); - //First show one paint - QTRY_COMPARE(tester2.painted, 1); + //First show at least one paint + QCOMPARE(tester2.painted, 0); + QTRY_VERIFY(tester2.painted > 0); + int painted = tester2.painted; //nominal case, update call paint tester2.update(); - QTRY_COMPARE(tester2.painted, 2); + QTRY_COMPARE(tester2.painted, painted + 1); + painted = tester2.painted; //we remove the item from the scene, number of updates is still the same tester2.update(); scene2.removeItem(&tester2); - QTRY_COMPARE(tester2.painted, 2); + QTRY_COMPARE(tester2.painted, painted); //We re-add the item, the number of paint should increase scene2.addItem(&tester2); tester2.update(); - QTRY_COMPARE(tester2.painted, 3); + QTRY_COMPARE(tester2.painted, painted + 1); } class HarakiriItem : public QGraphicsRectItem @@ -11377,7 +11374,7 @@ void tst_QGraphicsItem::QTBUG_7714_fullUpdateDiscardingOpacityUpdate2() origView.reset(); childYellow->setOpacity(0.0); - QTRY_COMPARE(origView.repaints, 1); + QTRY_VERIFY(origView.repaints > 0); view.show(); qApp->setActiveWindow(&view); @@ -11392,8 +11389,8 @@ void tst_QGraphicsItem::QTBUG_7714_fullUpdateDiscardingOpacityUpdate2() QEXPECT_FAIL("", "Fails on WinRT. Figure out why - QTBUG-68297", Abort); #endif - QTRY_COMPARE(origView.repaints, 1); - QTRY_COMPARE(view.repaints, 1); + QTRY_VERIFY(origView.repaints > 0); + QTRY_VERIFY(view.repaints > 0); } void tst_QGraphicsItem::QT_2649_focusScope() -- cgit v1.2.3