From 6b808b1eee4956286995ad9b1c2e81ae4b1a5884 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Wed, 29 Oct 2014 09:58:03 +0100 Subject: Improve startup of bindings using QQuickScreen We can optimistically initialize the underlying QScreen to the primary screen and this way ensure that in the common case the evaluation of bindings using the screen's attached properties results in correct calculations on startup. This way we can avoid re-evaluating the bindings again later. Previously on startup all the returned values were zero and the bindings got evaluated again once a window was assigned. Change-Id: I98ba5905953f0b5054d924919239d178570250d3 Reviewed-by: Shawn Rutledge Reviewed-by: J-P Nurmi Reviewed-by: Gunnar Sletta --- tests/auto/quick/qquickscreen/tst_qquickscreen.cpp | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'tests') diff --git a/tests/auto/quick/qquickscreen/tst_qquickscreen.cpp b/tests/auto/quick/qquickscreen/tst_qquickscreen.cpp index 70ecff51eb..afcc9218bc 100644 --- a/tests/auto/quick/qquickscreen/tst_qquickscreen.cpp +++ b/tests/auto/quick/qquickscreen/tst_qquickscreen.cpp @@ -33,6 +33,7 @@ #include #include +#include #include #include #include @@ -43,6 +44,7 @@ class tst_qquickscreen : public QQmlDataTest Q_OBJECT private slots: void basicProperties(); + void screenOnStartup(); }; void tst_qquickscreen::basicProperties() @@ -67,6 +69,27 @@ void tst_qquickscreen::basicProperties() QVERIFY(screen->devicePixelRatio() >= 1.0); } +void tst_qquickscreen::screenOnStartup() +{ + // We expect QQuickScreen to fall back to the primary screen + QQmlEngine engine; + QQmlComponent component(&engine, testFileUrl("screen.qml")); + + QScopedPointer root(qobject_cast(component.create())); + QVERIFY(root); + + QScreen* screen = QGuiApplication::primaryScreen(); + QVERIFY(screen); + + QCOMPARE(screen->size().width(), root->property("w").toInt()); + QCOMPARE(screen->size().height(), root->property("h").toInt()); + QCOMPARE(int(screen->orientation()), root->property("curOrientation").toInt()); + QCOMPARE(int(screen->primaryOrientation()), root->property("priOrientation").toInt()); + QCOMPARE(int(screen->orientationUpdateMask()), root->property("updateMask").toInt()); + QCOMPARE(screen->devicePixelRatio(), root->property("devicePixelRatio").toReal()); + QVERIFY(screen->devicePixelRatio() >= 1.0); +} + QTEST_MAIN(tst_qquickscreen) #include "tst_qquickscreen.moc" -- cgit v1.2.3