diff options
author | Simon Hausmann <simon.hausmann@digia.com> | 2012-09-26 14:15:39 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2012-09-26 19:54:19 +0200 |
commit | c4e736cf9d0ff9cecfa03c1e6386957c7de706da (patch) | |
tree | 40fb086f84cab70f7ca850e8d0008c8f87cdb0b3 /tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp | |
parent | aad58ac87e371129ee61168effd9daa491b476ab (diff) |
Fix events being processed on application start
Commit ef2efafcc6b28791df6258fa1c5d565090a9577a introduced a call to
QWindowSystemInterface::sendWindowSystemEvents() in
QGuiApplicationPrivate::init(), which in its implementation ends up calling
sendPostedEvents() before flushing and processing any pending (internal) window
system events.
This patch changes the call in init() to use
QWindowSystemInterface::flushWindowSystemEvents() instead, which is more gentle
in that regard.
The provided unit test verifies that no posted events are processed during the
execution of the QGuiApplication constructor while at the same time verifying
what the original changed tried to do: Allow a generic plugin to provide window
system specific defaults that are implemented using the event queue of
QWindowSystemInterface.
Task-number: QTBUG-26886
Change-Id: I129a907c00d947df60fe1a02efc67857580fce24
Reviewed-by: David Faure <faure@kde.org>
Diffstat (limited to 'tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp')
-rw-r--r-- | tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp | 72 |
1 files changed, 71 insertions, 1 deletions
diff --git a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp index de5e049289..82d1b17dad 100644 --- a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp +++ b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp @@ -44,6 +44,7 @@ #include <QtGui/QGuiApplication> #include <QtGui/QWindow> #include <qpa/qwindowsysteminterface.h> +#include <qgenericplugin.h> #include <QDebug> @@ -61,6 +62,7 @@ private slots: void keyboardModifiers(); void modalWindow(); void quitOnLastWindowClosed(); + void genericPluginsAndWindowSystemEvents(); }; void tst_QGuiApplication::displayName() @@ -568,6 +570,74 @@ void tst_QGuiApplication::quitOnLastWindowClosed() } } +static Qt::ScreenOrientation testOrientationToSend = Qt::PrimaryOrientation; + +class TestPlugin : public QObject +{ + Q_OBJECT +public: + TestPlugin() + { + QScreen* screen = QGuiApplication::primaryScreen(); + // Make sure the orientation we want to send doesn't get filtered out. + screen->setOrientationUpdateMask(screen->orientationUpdateMask() | testOrientationToSend); + QWindowSystemInterface::handleScreenOrientationChange(screen, testOrientationToSend); + } +}; + +class TestPluginFactory : public QGenericPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QGenericPluginFactoryInterface" FILE "testplugin.json") +public: + QObject* create(const QString &key, const QString &) + { + if (key == "testplugin") + return new TestPlugin; + return 0; + } +}; + +class TestEventReceiver : public QObject +{ + Q_OBJECT +public: + int customEvents; + + TestEventReceiver() + : customEvents(0) + {} + + virtual void customEvent(QEvent *) + { + customEvents++; + } +}; -QTEST_APPLESS_MAIN(tst_QGuiApplication) #include "tst_qguiapplication.moc" + +void tst_QGuiApplication::genericPluginsAndWindowSystemEvents() +{ + testOrientationToSend = Qt::InvertedLandscapeOrientation; + + TestEventReceiver testReceiver; + QCoreApplication::postEvent(&testReceiver, new QEvent(QEvent::User)); + QCOMPARE(testReceiver.customEvents, 0); + + QStaticPlugin testPluginInfo; + testPluginInfo.instance = qt_plugin_instance; + testPluginInfo.metaData = qt_plugin_query_metadata; + qRegisterStaticPluginFunction(testPluginInfo); + int argc = 3; + char *argv[] = { const_cast<char*>("tst_qguiapplication"), const_cast<char*>("-plugin"), const_cast<char*>("testplugin") }; + QGuiApplication app(argc, argv); + + QVERIFY(QGuiApplication::primaryScreen()); + QVERIFY(QGuiApplication::primaryScreen()->orientation() == testOrientationToSend); + + QCOMPARE(testReceiver.customEvents, 0); + QCoreApplication::sendPostedEvents(&testReceiver); + QCOMPARE(testReceiver.customEvents, 1); +} + +QTEST_APPLESS_MAIN(tst_QGuiApplication) |