Fix QScreen::orientation() not always being updated after changing the update orientation mask

The back-end might report screen orientation changes at any point and we
record it in screen.d->orientation. However QScreen::orientation()
returns the orientation filtered according to the mask.

Changing the mask sends a notification to the back-end, which might send
another update as a result of a possible subscription to system services
(accelerometer). However on platforms where no subscription is required, where
the platform plugin ignores the mask and always sends the latest orientation,
we should "simulate" the update by updating the filtered orientation according
to the new mask. The function is cheap to call as it won't emit any signals
unless the orientation actually changes.

This patch also adds missing flush() calls after handleScreenOrientationChange
calls in the tests to ensure that the (synthetic) window system events are
actually delivered to QScreen/QGuiApplication.

Change-Id: Iebdd050f947e658ff5bc388629aa4cb31ab497fe
Reviewed-by: Samuel Rødal <samuel.rodal@digia.com>
Reviewed-by: Laszlo Papp <lpapp@kde.org>
This commit is contained in:
Simon Hausmann 2012-09-26 15:14:48 +02:00 committed by The Qt Project
parent 9362474805
commit ce1f994e9b
2 changed files with 17 additions and 0 deletions

View File

@ -42,6 +42,7 @@
#include "qscreen.h"
#include "qscreen_p.h"
#include "qpixmap.h"
#include "qguiapplication_p.h"
#include <qpa/qplatformscreen.h>
#include <QtCore/private/qobject_p.h>
@ -367,6 +368,7 @@ void QScreen::setOrientationUpdateMask(Qt::ScreenOrientations mask)
Q_D(QScreen);
d->orientationUpdateMask = mask;
d->platformScreen->setOrientationUpdateMask(mask);
QGuiApplicationPrivate::updateFilteredScreenOrientation(this);
}
/*!

View File

@ -185,19 +185,34 @@ void tst_QScreen::orientationChange()
screen->setOrientationUpdateMask(Qt::LandscapeOrientation | Qt::PortraitOrientation);
QWindowSystemInterface::handleScreenOrientationChange(screen, Qt::LandscapeOrientation);
QWindowSystemInterface::flushWindowSystemEvents();
QTRY_COMPARE(screen->orientation(), Qt::LandscapeOrientation);
QWindowSystemInterface::handleScreenOrientationChange(screen, Qt::PortraitOrientation);
QWindowSystemInterface::flushWindowSystemEvents();
QTRY_COMPARE(screen->orientation(), Qt::PortraitOrientation);
QSignalSpy spy(screen, SIGNAL(orientationChanged(Qt::ScreenOrientation)));
QWindowSystemInterface::handleScreenOrientationChange(screen, Qt::InvertedLandscapeOrientation);
QWindowSystemInterface::flushWindowSystemEvents();
QWindowSystemInterface::handleScreenOrientationChange(screen, Qt::InvertedPortraitOrientation);
QWindowSystemInterface::flushWindowSystemEvents();
QWindowSystemInterface::handleScreenOrientationChange(screen, Qt::LandscapeOrientation);
QWindowSystemInterface::flushWindowSystemEvents();
QTRY_COMPARE(screen->orientation(), Qt::LandscapeOrientation);
QCOMPARE(spy.count(), 1);
spy.clear();
QWindowSystemInterface::handleScreenOrientationChange(screen, Qt::InvertedLandscapeOrientation);
QWindowSystemInterface::flushWindowSystemEvents();
QTRY_COMPARE(screen->orientation(), Qt::LandscapeOrientation);
QCOMPARE(spy.count(), 0);
screen->setOrientationUpdateMask(screen->orientationUpdateMask() | Qt::InvertedLandscapeOrientation);
QTRY_COMPARE(screen->orientation(), Qt::InvertedLandscapeOrientation);
QCOMPARE(spy.count(), 1);
}
#include <tst_qscreen.moc>