aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmltest
diff options
context:
space:
mode:
authorFilippo Cucchetto <filippocucchetto@gmail.com>2015-08-04 19:29:51 +0200
committerFilippo Cucchetto <filippocucchetto@gmail.com>2015-08-16 16:53:42 +0000
commit7b8050c0d3bc1e4743f5d5a3f6d688ff71ffb5b6 (patch)
treedb2c23fa62dbb406a4c2fcd40e937771c2d77172 /src/qmltest
parent6e3c6458cad5078c2bde44d73220510dfc8ebfce (diff)
Change TestEvent key default event routing behavior
The current behavior of the TestEvent is to send all the key events to the test window. For this reason is not possible routing events to custom windows created inside the test suite. The new behavior is to send the key events to the current focused window [Change][QuickTest][TestCase] Changed default routing behavior for key events in TestCase. The key events are sent to the window with active focus Change-Id: I6ff3113eb9f1cbc25f6cfd2dd7bfdff178ee6ac3 Reviewed-by: Filippo Cucchetto <filippocucchetto@gmail.com> Reviewed-by: Mitch Curtis <mitch.curtis@theqtcompany.com>
Diffstat (limited to 'src/qmltest')
-rw-r--r--src/qmltest/quicktestevent.cpp19
-rw-r--r--src/qmltest/quicktestevent_p.h1
2 files changed, 14 insertions, 6 deletions
diff --git a/src/qmltest/quicktestevent.cpp b/src/qmltest/quicktestevent.cpp
index 237bbe76e9..cfa80c4f19 100644
--- a/src/qmltest/quicktestevent.cpp
+++ b/src/qmltest/quicktestevent.cpp
@@ -50,7 +50,7 @@ QuickTestEvent::~QuickTestEvent()
bool QuickTestEvent::keyPress(int key, int modifiers, int delay)
{
- QWindow *window = eventWindow();
+ QWindow *window = activeWindow();
if (!window)
return false;
QTest::keyPress(window, Qt::Key(key), Qt::KeyboardModifiers(modifiers), delay);
@@ -59,7 +59,7 @@ bool QuickTestEvent::keyPress(int key, int modifiers, int delay)
bool QuickTestEvent::keyRelease(int key, int modifiers, int delay)
{
- QWindow *window = eventWindow();
+ QWindow *window = activeWindow();
if (!window)
return false;
QTest::keyRelease(window, Qt::Key(key), Qt::KeyboardModifiers(modifiers), delay);
@@ -68,7 +68,7 @@ bool QuickTestEvent::keyRelease(int key, int modifiers, int delay)
bool QuickTestEvent::keyClick(int key, int modifiers, int delay)
{
- QWindow *window = eventWindow();
+ QWindow *window = activeWindow();
if (!window)
return false;
QTest::keyClick(window, Qt::Key(key), Qt::KeyboardModifiers(modifiers), delay);
@@ -78,7 +78,7 @@ bool QuickTestEvent::keyClick(int key, int modifiers, int delay)
bool QuickTestEvent::keyPressChar(const QString &character, int modifiers, int delay)
{
QTEST_ASSERT(character.length() == 1);
- QWindow *window = eventWindow();
+ QWindow *window = activeWindow();
if (!window)
return false;
QTest::keyPress(window, character[0].toLatin1(), Qt::KeyboardModifiers(modifiers), delay);
@@ -88,7 +88,7 @@ bool QuickTestEvent::keyPressChar(const QString &character, int modifiers, int d
bool QuickTestEvent::keyReleaseChar(const QString &character, int modifiers, int delay)
{
QTEST_ASSERT(character.length() == 1);
- QWindow *window = eventWindow();
+ QWindow *window = activeWindow();
if (!window)
return false;
QTest::keyRelease(window, character[0].toLatin1(), Qt::KeyboardModifiers(modifiers), delay);
@@ -98,7 +98,7 @@ bool QuickTestEvent::keyReleaseChar(const QString &character, int modifiers, int
bool QuickTestEvent::keyClickChar(const QString &character, int modifiers, int delay)
{
QTEST_ASSERT(character.length() == 1);
- QWindow *window = eventWindow();
+ QWindow *window = activeWindow();
if (!window)
return false;
QTest::keyClick(window, character[0].toLatin1(), Qt::KeyboardModifiers(modifiers), delay);
@@ -316,4 +316,11 @@ QWindow *QuickTestEvent::eventWindow(QObject *item)
return 0;
}
+QWindow *QuickTestEvent::activeWindow()
+{
+ if (QWindow *window = QGuiApplication::focusWindow())
+ return window;
+ return eventWindow();
+}
+
QT_END_NAMESPACE
diff --git a/src/qmltest/quicktestevent_p.h b/src/qmltest/quicktestevent_p.h
index e11674f66a..338464c6b3 100644
--- a/src/qmltest/quicktestevent_p.h
+++ b/src/qmltest/quicktestevent_p.h
@@ -74,6 +74,7 @@ public Q_SLOTS:
private:
QWindow *eventWindow(QObject *item = 0);
+ QWindow *activeWindow();
};
QT_END_NAMESPACE