diff options
Diffstat (limited to 'src/gui/kernel/qtestsupport_gui.cpp')
-rw-r--r-- | src/gui/kernel/qtestsupport_gui.cpp | 59 |
1 files changed, 44 insertions, 15 deletions
diff --git a/src/gui/kernel/qtestsupport_gui.cpp b/src/gui/kernel/qtestsupport_gui.cpp index f8c4631f05..869eddce49 100644 --- a/src/gui/kernel/qtestsupport_gui.cpp +++ b/src/gui/kernel/qtestsupport_gui.cpp @@ -18,11 +18,18 @@ QT_BEGIN_NAMESPACE /*! \since 5.0 - Waits for \a timeout milliseconds or until the \a window is active. + Returns \c true, if \a window is active within \a timeout milliseconds. Otherwise returns \c false. - Returns \c true if \c window is active within \a timeout milliseconds, otherwise returns \c false. + The method is useful in tests that call QWindow::show() and rely on the window actually being + active (i.e. being visible and having focus) before proceeding. - \sa qWaitForWindowExposed(), QWindow::isActive() + \note The method will time out and return \c false if another window prevents \a window from + becoming active. + + \note Since focus is an exclusive property, \a window may loose its focus to another window at + any time - even after the method has returned \c true. + + \sa qWaitForWindowExposed(), qWaitForWindowFocused(), QWindow::isActive() */ Q_GUI_EXPORT bool QTest::qWaitForWindowActive(QWindow *window, int timeout) { @@ -38,17 +45,37 @@ Q_GUI_EXPORT bool QTest::qWaitForWindowActive(QWindow *window, int timeout) } /*! + \since 6.7 + + Returns \c true, if \a window is the focus window within \a timeout. Otherwise returns \c false. + + The method is useful in tests that call QWindow::show() and rely on the window + having focus (for receiving keyboard events e.g.) before proceeding. + + \note The method will time out and return \c false if another window prevents \a window from + becoming focused. + + \note Since focus is an exclusive property, \a window may loose its focus to another window at + any time - even after the method has returned \c true. + + \sa qWaitForWindowExposed(), qWaitForWindowActive(), QGuiApplication::focusWindow() +*/ +Q_GUI_EXPORT bool QTest::qWaitForWindowFocused(QWindow *window, QDeadlineTimer timeout) +{ + return QTest::qWaitFor([&]() { return qGuiApp->focusWindow() == window; }, timeout); +} + +/*! \since 5.0 - Waits for \a timeout milliseconds or until the \a window is exposed. - Returns \c true if \c window is exposed within \a timeout milliseconds, otherwise returns \c false. + Returns \c true, if \a window is exposed within \a timeout milliseconds. Otherwise returns \c false. - This is mainly useful for asynchronous systems like X11, where a window will be mapped to screen some - time after being asked to show itself on the screen. + The method is useful in tests that call QWindow::show() and rely on the window actually being + being visible before proceeding. - Note that a window that is mapped to screen may still not be considered exposed if the window client - area is completely covered by other windows, or if the window is otherwise not visible. This function - will then time out when waiting for such a window. + \note A window mapped to screen may still not be considered exposed, if the window client area is + not visible, e.g. because it is completely covered by other windows. + In such cases, the method will time out and return \c false. \sa qWaitForWindowActive(), QWindow::isExposed() */ @@ -62,7 +89,7 @@ namespace QTest { QTouchEventSequence::~QTouchEventSequence() { if (commitWhenDestroyed) - commit(); + QTouchEventSequence::commit(); } QTouchEventSequence& QTouchEventSequence::press(int touchId, const QPoint &pt, QWindow *window) { @@ -92,17 +119,19 @@ QTouchEventSequence& QTouchEventSequence::stationary(int touchId) return *this; } -void QTouchEventSequence::commit(bool processEvents) +bool QTouchEventSequence::commit(bool processEvents) { if (points.isEmpty()) - return; - QThread::msleep(1); + return false; + QThread::sleep(std::chrono::milliseconds{1}); + bool ret = false; if (targetWindow) - qt_handleTouchEvent(targetWindow, device, points.values()); + ret = qt_handleTouchEventv2(targetWindow, device, points.values()); if (processEvents) QCoreApplication::processEvents(); previousPoints = points; points.clear(); + return ret; } QTouchEventSequence::QTouchEventSequence(QWindow *window, QPointingDevice *aDevice, bool autoCommit) |