summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <[email protected]>2025-06-27 10:58:05 +0200
committerMarc Mutz <[email protected]>2025-06-27 22:34:25 +0200
commit943df16c72065cb7f0d13b9f0bceab06abfe3f71 (patch)
treec12bf87f2798d2d48ebca973af7ed6bbe926121c
parent4ec8b1096cbe5f888754fcd6de2b549f67a58914 (diff)
qWaitForWidgetWindow: fix excessive genericity
The first argument was the same in all callers; instead of passing token-by-token-identical lambdas (which have all distinct types), we can pass the lambda's captured variables instead and inline the lambdas into the function. The third argument was always either int or QDeadlineTimer, so standardize on QDeadlineTimer. A follow-up change will change all arguments to QDeadlineTimer in the public API, too, so this is the future-proof and chrono-first-compatible version. Note 73c52ba2687c2035a40141f2a5236399f8331f4b for the QDeadlineTimer construction. Amends 7e4c2ac711c0b68133f06ab997a33f8bf7c4f734 and 3f2a9523a442e44ef52ebca30da9b5d3188df6bc. Pick-to: 6.10 6.9 6.8 Change-Id: I75f84abbf60cd77ce48c7ab0ee797e5e8a0879de Reviewed-by: Volker Hilsheimer <[email protected]>
-rw-r--r--src/widgets/kernel/qtestsupport_widgets.cpp25
1 files changed, 12 insertions, 13 deletions
diff --git a/src/widgets/kernel/qtestsupport_widgets.cpp b/src/widgets/kernel/qtestsupport_widgets.cpp
index f7b25b6643b..5a7200e58aa 100644
--- a/src/widgets/kernel/qtestsupport_widgets.cpp
+++ b/src/widgets/kernel/qtestsupport_widgets.cpp
@@ -16,14 +16,14 @@
QT_BEGIN_NAMESPACE
-template <typename FunctorWindowGetter, typename FunctorPredicate, typename Timeout>
-static bool qWaitForWidgetWindow(FunctorWindowGetter windowGetter, FunctorPredicate predicate, Timeout timeout)
+template <typename Predicate>
+static bool qWaitForWidgetWindow(QWidget *w, Predicate predicate, QDeadlineTimer timeout)
{
- if (!windowGetter())
+ if (!w->window()->windowHandle())
return false;
return QTest::qWaitFor([&]() {
- if (QWindow *window = windowGetter())
+ if (QWindow *window = w->window()->windowHandle())
return predicate(window);
return false;
}, timeout);
@@ -55,9 +55,9 @@ Q_WIDGETS_EXPORT bool QTest::qWaitForWindowActive(QWidget *widget, int timeout)
<< "Falling back to qWaitForWindowExposed.";
return qWaitForWindowExposed(widget, timeout);
}
- return qWaitForWidgetWindow([&]() { return widget->window()->windowHandle(); },
+ return qWaitForWidgetWindow(widget,
[&](QWindow *window) { return window->isActive(); },
- timeout);
+ QDeadlineTimer{timeout, Qt::TimerType::PreciseTimer});
}
@@ -79,11 +79,10 @@ Q_WIDGETS_EXPORT bool QTest::qWaitForWindowActive(QWidget *widget, int timeout)
*/
Q_WIDGETS_EXPORT bool QTest::qWaitForWindowFocused(QWidget *widget, QDeadlineTimer timeout)
{
- return qWaitForWidgetWindow([&]() {
- return widget->window()->windowHandle();
- }, [&](QWindow *window) {
- return qGuiApp->focusWindow() == window;
- }, timeout);
+ return qWaitForWidgetWindow(widget,
+ [&](QWindow *window) {
+ return qGuiApp->focusWindow() == window;
+ }, timeout);
}
/*!
@@ -102,9 +101,9 @@ Q_WIDGETS_EXPORT bool QTest::qWaitForWindowFocused(QWidget *widget, QDeadlineTim
*/
Q_WIDGETS_EXPORT bool QTest::qWaitForWindowExposed(QWidget *widget, int timeout)
{
- return qWaitForWidgetWindow([&]() { return widget->window()->windowHandle(); },
+ return qWaitForWidgetWindow(widget,
[&](QWindow *window) { return window->isExposed(); },
- timeout);
+ QDeadlineTimer{timeout, Qt::TimerType::PreciseTimer});
}
namespace QTest {