Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-55878

QQuickFlickable is hard to test with wheel events on macOS

    XMLWordPrintable

Details

    • macOS
    • e09f5b17865a09dac41d0f30ef2ea238f38873eb

    Description

      Because of the movementEndingTimer thing that is internally used by QQuickFlickable, it emits movementEnded() even while the content is moving:

      #include <QtTest>
      #include <QtQuick>
      
      class tst_Flickable : public QObject
      {
          Q_OBJECT
      
      private slots:
          void wheel();
      };
      
      static bool sendWheelEvent(QQuickItem *item, const QPoint &localPos, int degrees)
      {
          QQuickWindow *window = item->window();
          QWheelEvent wheelEvent(localPos, item->window()->mapToGlobal(localPos), QPoint(0, 0), QPoint(0, 8 * degrees), 0, Qt::Vertical, Qt::NoButton, 0);
          QSpontaneKeyEvent::setSpontaneous(&wheelEvent);
          return qGuiApp->notify(window, &wheelEvent);
      }
      
      void tst_Flickable::wheel()
      {
          QQmlEngine engine;
          QQmlComponent component(&engine);
      
          component.setData("import QtQuick 2.6;"
                            "import QtQuick.Window 2.2;"
                            "Window {"
                            "    width: 400; height: 400;"
                            "    property alias listView: listView;"
                            "    ListView {"
                            "        id: listView;"
                            "        model: 100;"
                            "        anchors.fill: parent;"
                            "        delegate: Text {"
                            "            width: parent.width;"
                            "            text: index;"
                            "        }"
                            "        onContentYChanged: console.log('onContentYChanged', contentY, this);"
                            "        onMovementStarted: console.log('onMovementStarted', this);"
                            "        onMovementEnded: console.log('onMovementEnded', this);"
                            "        onMovingChanged: console.log('onMovingChanged', moving, this);"
                            "    }"
                            "}", QUrl());
      
          QQuickWindow *window = qobject_cast<QQuickWindow *>(component.create());
          QVERIFY(window);
          window->show();
          QVERIFY(QTest::qWaitForWindowExposed(window));
      
          QQuickItem *listView = window->property("listView").value<QQuickItem*>();
          QVERIFY(listView);
      
          QSignalSpy movingChanged(listView, SIGNAL(movingChanged()));
          QSignalSpy movementStartedSpy(listView, SIGNAL(movementStarted()));
          QSignalSpy movementEndedSpy(listView, SIGNAL(movementEnded()));
          QVERIFY(movingChanged.isValid() && movementStartedSpy.isValid() && movementEndedSpy.isValid());
      
          // send a wheel event
          QVERIFY(sendWheelEvent(listView, QPoint(listView->width() / 2, listView->height() / 2), -15));
      
          // check that the content starts moving
          QVERIFY(listView->property("moving").toBool());
          QCOMPARE(movingChanged.count(), 1);
          QCOMPARE(movementStartedSpy.count(), 1);
          QCOMPARE(movementEndedSpy.count(), 0);
      
          // wait until the movement ends
          QTRY_VERIFY(!listView->property("moving").toBool());
          QCOMPARE(movingChanged.count(), 2);
          QCOMPARE(movementStartedSpy.count(), 1);
          QCOMPARE(movementEndedSpy.count(), 1);
      
          // wait a bit and see if it still moves
          qreal before = listView->property("contentY").toReal();
          QTest::qWait(500);
          qreal after = listView->property("contentY").toReal();
      
          QCOMPARE(after, before); // fail
      }
      
      QTEST_MAIN(tst_Flickable)
      
      #include "tst_flickable.moc"
      

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              srutledg Shawn Rutledge
              jpnurmi J-P Nurmi
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes