diff options
author | Simon Hausmann <simon.hausmann@theqtcompany.com> | 2014-10-29 09:58:03 +0100 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@digia.com> | 2015-01-12 21:22:35 +0100 |
commit | 6b808b1eee4956286995ad9b1c2e81ae4b1a5884 (patch) | |
tree | 1d8af49173d374ba65e5c7f518b1d6cc8a33c754 /tests | |
parent | c5b575bdc26b54e4807760c9731e9b9752f56f21 (diff) |
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 <shawn.rutledge@digia.com>
Reviewed-by: J-P Nurmi <jpnurmi@theqtcompany.com>
Reviewed-by: Gunnar Sletta <gunnar@sletta.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/quick/qquickscreen/tst_qquickscreen.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
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 <qtest.h> #include <QDebug> +#include <QQmlEngine> #include <QtQuick/QQuickItem> #include <QtQuick/QQuickView> #include <QtGui/QScreen> @@ -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<QQuickItem> root(qobject_cast<QQuickItem*>(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" |