summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDavid Faure <faure@kde.org>2012-06-23 21:48:53 +0200
committerQt by Nokia <qt-info@nokia.com>2012-07-20 18:34:08 +0200
commit1603ba23656c8c31dc05fe9b3f1e12b22e29989a (patch)
tree5e507db7a34023b9236c982257923a2242c1693a /tests
parent981ea7a1aa602cebfdd43b7dc6efd3abf5a1cba3 (diff)
Provide public API for native event filtering, moved up from QPA.
The previous API was hard to use (global function, no type safety, manual chaining), and confusing (app vs dispatcher split only made sense on Windows). Installing and removing out of order would have the risk of setting back a dangling pointer (crash). Meanwhile QPA added type safety, and this new API models the QObject::installEventFilter API for ease of use. The virtual method is in a new interface, QAbstractNativeEventFilter. QPA was even calling the dispatcher event filter with QPA-private event classes, which made no sense (refactoring leftover from when the code was in the dispatcher). Now the QPA plugins trigger the qcoreapp event filters with the actual native events directly. Change-Id: Ie35e47c59c862383bcaf857b28d54f7c72547882 Reviewed-by: Marius Storm-Olsen <marius.storm-olsen@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/testlib/selftests/benchlibeventcounter/tst_benchlibeventcounter.cpp2
-rw-r--r--tests/auto/testlib/selftests/benchliboptions/tst_benchliboptions.cpp6
-rw-r--r--tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp30
3 files changed, 28 insertions, 10 deletions
diff --git a/tests/auto/testlib/selftests/benchlibeventcounter/tst_benchlibeventcounter.cpp b/tests/auto/testlib/selftests/benchlibeventcounter/tst_benchlibeventcounter.cpp
index b077291cc6..966c81ec30 100644
--- a/tests/auto/testlib/selftests/benchlibeventcounter/tst_benchlibeventcounter.cpp
+++ b/tests/auto/testlib/selftests/benchlibeventcounter/tst_benchlibeventcounter.cpp
@@ -87,7 +87,7 @@ void tst_BenchlibEventCounter::events()
QAbstractEventDispatcher* ed = QAbstractEventDispatcher::instance();
QBENCHMARK {
for (int i = 0; i < eventCount; ++i) {
- ed->filterEvent(0);
+ ed->filterNativeEvent("", 0, 0);
}
}
}
diff --git a/tests/auto/testlib/selftests/benchliboptions/tst_benchliboptions.cpp b/tests/auto/testlib/selftests/benchliboptions/tst_benchliboptions.cpp
index 7673aa396e..c60addf972 100644
--- a/tests/auto/testlib/selftests/benchliboptions/tst_benchliboptions.cpp
+++ b/tests/auto/testlib/selftests/benchliboptions/tst_benchliboptions.cpp
@@ -88,9 +88,9 @@ void tst_BenchlibOptions::threeEvents()
{
QAbstractEventDispatcher* ed = QAbstractEventDispatcher::instance();
QBENCHMARK {
- ed->filterEvent(0);
- ed->filterEvent(0);
- ed->filterEvent(0);
+ ed->filterNativeEvent("", 0, 0);
+ ed->filterNativeEvent("", 0, 0);
+ ed->filterNativeEvent("", 0, 0);
}
}
diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
index 37e945ddb1..c670c5bf72 100644
--- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
+++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
@@ -71,6 +71,7 @@
#include <qcompleter.h>
#include <qtableview.h>
#include <qtreewidget.h>
+#include <qabstractnativeeventfilter.h>
#include <QtWidgets/QGraphicsView>
#include <QtWidgets/QGraphicsProxyWidget>
@@ -5505,16 +5506,17 @@ void tst_QWidget::minAndMaxSizeWithX11BypassWindowManagerHint()
}
}
-class ShowHideShowWidget : public QWidget
+class ShowHideShowWidget : public QWidget, public QAbstractNativeEventFilter
{
Q_OBJECT
int state;
public:
bool gotExpectedMapNotify;
+ bool gotExpectedGlobalEvent;
ShowHideShowWidget()
- : state(0), gotExpectedMapNotify(false)
+ : state(0), gotExpectedMapNotify(false), gotExpectedGlobalEvent(false)
{
startTimer(1000);
}
@@ -5531,19 +5533,32 @@ public:
}
}
- bool nativeEvent(const QByteArray &eventType, void *message, long *)
+ bool isMapNotify(const QByteArray &eventType, void *message)
{
enum { XCB_MAP_NOTIFY = 19 };
-
if (state == 1 && eventType == QByteArrayLiteral("xcb_generic_event_t")) {
// XCB events have a uint8 response_type member at the beginning.
const unsigned char responseType = *(const unsigned char *)(message);
- if ((responseType & ~0x80) == XCB_MAP_NOTIFY)
- gotExpectedMapNotify = true;
+ return ((responseType & ~0x80) == XCB_MAP_NOTIFY);
}
return false;
}
+ bool nativeEvent(const QByteArray &eventType, void *message, long *)
+ {
+ if (isMapNotify(eventType, message))
+ gotExpectedMapNotify = true;
+ return false;
+ }
+
+ // QAbstractNativeEventFilter interface
+ virtual bool nativeEventFilter(const QByteArray &eventType, void *message, long *) Q_DECL_OVERRIDE
+ {
+ if (isMapNotify(eventType, message))
+ gotExpectedGlobalEvent = true;
+ return false;
+ }
+
signals:
void done();
};
@@ -5554,6 +5569,8 @@ void tst_QWidget::showHideShowX11()
QSKIP("This test is for X11 only.");
ShowHideShowWidget w;
+ qApp->installNativeEventFilter(&w);
+
w.show();
w.hide();
@@ -5561,6 +5578,7 @@ void tst_QWidget::showHideShowX11()
connect(&w, SIGNAL(done()), &eventLoop, SLOT(quit()));
eventLoop.exec();
+ QVERIFY(w.gotExpectedGlobalEvent);
QVERIFY(w.gotExpectedMapNotify);
}