diff options
author | David Faure <faure@kde.org> | 2012-06-23 21:48:53 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-07-20 18:34:08 +0200 |
commit | 1603ba23656c8c31dc05fe9b3f1e12b22e29989a (patch) | |
tree | 5e507db7a34023b9236c982257923a2242c1693a /src/testlib/qbenchmarkevent.cpp | |
parent | 981ea7a1aa602cebfdd43b7dc6efd3abf5a1cba3 (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 'src/testlib/qbenchmarkevent.cpp')
-rw-r--r-- | src/testlib/qbenchmarkevent.cpp | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/src/testlib/qbenchmarkevent.cpp b/src/testlib/qbenchmarkevent.cpp index bbba0ba5d9..f37162ae9d 100644 --- a/src/testlib/qbenchmarkevent.cpp +++ b/src/testlib/qbenchmarkevent.cpp @@ -46,8 +46,10 @@ QT_BEGIN_NAMESPACE -QAbstractEventDispatcher::EventFilter oldEventFilter = 0; -qint64 QBenchmarkEvent::eventCounter = 0; +QBenchmarkEvent::QBenchmarkEvent() + : eventCounter(0) +{ +} QBenchmarkEvent::~QBenchmarkEvent() { @@ -55,21 +57,19 @@ QBenchmarkEvent::~QBenchmarkEvent() void QBenchmarkEvent::start() { - QBenchmarkEvent::eventCounter = 0; - QAbstractEventDispatcher *parent = QAbstractEventDispatcher::instance(); - oldEventFilter = parent->setEventFilter(QBenchmarkEvent::eventCountingMechanism); + eventCounter = 0; + QAbstractEventDispatcher::instance()->installNativeEventFilter(this); } qint64 QBenchmarkEvent::checkpoint() { - return QBenchmarkEvent::eventCounter; + return eventCounter; } qint64 QBenchmarkEvent::stop() { - QAbstractEventDispatcher *parent = QAbstractEventDispatcher::instance(); - parent->setEventFilter(oldEventFilter); - return QBenchmarkEvent::eventCounter; + QAbstractEventDispatcher::instance()->removeNativeEventFilter(this); + return eventCounter; } // It's very tempting to simply reject a measurement if 0 events @@ -98,10 +98,13 @@ QTest::QBenchmarkMetric QBenchmarkEvent::metricType() } // This could be done in a much better way, this is just the beginning. -bool QBenchmarkEvent::eventCountingMechanism(void *message) +bool QBenchmarkEvent::nativeEventFilter(const QByteArray &eventType, void *message, long *result) { + Q_UNUSED(eventType); Q_UNUSED(message); - QBenchmarkEvent::eventCounter++; + Q_UNUSED(result); + + eventCounter++; return false; } |