diff options
author | Assam Boudjelthia <assam.boudjelthia@qt.io> | 2023-11-30 17:41:37 +0200 |
---|---|---|
committer | Assam Boudjelthia <assam.boudjelthia@qt.io> | 2023-12-05 16:28:12 +0000 |
commit | 7a9bc220c70745cd3689d51cd131efde86f078d7 (patch) | |
tree | 19b6455e415fa871a876f9e118711650120df7c5 /tests/auto/corelib/platform/android/tst_android.cpp | |
parent | a0bdd2195f24d8a7d880ba506afc16b41337218e (diff) |
Android: fix and simplify the orientation change logic
Move the orientation change handling to the display manager
and call it from the relevant places to repeated and scattered
code for the same functionality.
Bring back part of 072387edecb2269097821e35f1f232da6c657650
which checks discard a resize event that's not valid that
reports not up to date layout size.
If DisplayManager.DisplayListener.onDisplay() initiates the
orientation change, handle it immediately if we don't expect
the size to change, i.e. if the orientation is changing from
portrait to inverted portrait and vise versa for landscape.
Otherwise, expect the change to be initiated again shortly
after from QtLayout.onSizeChanged().
Also, add improve the unit test of the orientation change,
and test for the widget size after such changes to make
sure QTBUG-94459 is not reached again.
Fixes: QTBUG-119430
Task-number: QTBUG-115019
Task-number: QTBUG-94459
Change-Id: I5f060d91531af677ddf891f2af360d5f399e26e5
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
Diffstat (limited to 'tests/auto/corelib/platform/android/tst_android.cpp')
-rw-r--r-- | tests/auto/corelib/platform/android/tst_android.cpp | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/tests/auto/corelib/platform/android/tst_android.cpp b/tests/auto/corelib/platform/android/tst_android.cpp index 9a503fafc5..02204abcb5 100644 --- a/tests/auto/corelib/platform/android/tst_android.cpp +++ b/tests/auto/corelib/platform/android/tst_android.cpp @@ -12,6 +12,8 @@ #include <qpa/qplatformscreen.h> #include <qpa/qplatformnativeinterface.h> #include <QtCore/qdiriterator.h> +#include <QWidget> +#include <QSignalSpy> using namespace Qt::StringLiterals; @@ -305,19 +307,37 @@ void tst_Android::orientationChange_data() { QTest::addColumn<int>("nativeOrientation"); QTest::addColumn<Qt::ScreenOrientation>("expected"); + QTest::addColumn<QSize>("screenSize"); - QTest::newRow("Landscape") << 0 << Qt::LandscapeOrientation; - QTest::newRow("Portrait") << 1 << Qt::PortraitOrientation; + const QSize portraitSize = QGuiApplication::primaryScreen()->size(); + const QSize landscapeSize = QSize(portraitSize.height(), portraitSize.width()); + + QTest::newRow("InvertedLandscape") << 8 << Qt::InvertedLandscapeOrientation << landscapeSize; + QTest::newRow("InvertedPortrait") << 9 << Qt::InvertedPortraitOrientation << portraitSize; + QTest::newRow("Landscape") << 0 << Qt::LandscapeOrientation << landscapeSize; + // Leave Portrait till the end + QTest::newRow("Portrait") << 1 << Qt::PortraitOrientation << portraitSize; } void tst_Android::orientationChange() { QFETCH(int, nativeOrientation); QFETCH(Qt::ScreenOrientation, expected); + QFETCH(QSize, screenSize); + + // For QTBUG-94459 to check that the widget size are consistent after orientation changes + QWidget widget; + widget.show(); auto context = QNativeInterface::QAndroidApplication::context(); context.callMethod<void>("setRequestedOrientation", nativeOrientation); - QTRY_COMPARE(qGuiApp->primaryScreen()->orientation(), expected); + + QScreen *screen = QGuiApplication::primaryScreen(); + QSignalSpy orientationSpy(screen, SIGNAL(orientationChanged(Qt::ScreenOrientation))); + QTRY_COMPARE(screen->orientation(), expected); + QCOMPARE(orientationSpy.size(), 1); + QCOMPARE(screen->size(), screenSize); + QCOMPARE(widget.size(), screen->availableSize()); } QTEST_MAIN(tst_Android) |