aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quickwidgets
diff options
context:
space:
mode:
authorQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2020-03-26 01:00:11 +0100
committerFabian Kosmale <fabian.kosmale@qt.io>2020-04-09 10:08:41 +0200
commit2812184e1bb87cd94d2989162bc6ea954bb585c4 (patch)
tree25460548730e2ddc1f6f328d54e97d3fbfb49d21 /tests/auto/quickwidgets
parentcd4a99a7ba92968bf88da9af2624bb738d71e726 (diff)
parentbf205b45a29ba80d94df3b6bac5fec4c7cd79bf9 (diff)
Merge remote-tracking branch 'origin/5.15' into dev
Conflicts: src/qml/jsruntime/qv4executablecompilationunit.cpp src/qml/jsruntime/qv4executablecompilationunit_p.h src/qml/qml/qqmlobjectcreator.cpp src/qml/qml/qqmlpropertycachecreator_p.h src/qml/qml/qqmltypecompiler.cpp src/qml/qml/qqmltypedata.cpp tests/auto/qml/qmlformat/tst_qmlformat.cpp tools/qmllint/scopetree.cpp src/qml/qml/qqmlapplicationengine_p.h Adjusted tools/qmllint/findunqualified.cpp to use newer API Change-Id: Ibfb4678ca39d626d47527265e3c96e43313873d4
Diffstat (limited to 'tests/auto/quickwidgets')
-rw-r--r--tests/auto/quickwidgets/qquickwidget/data/resizeOverlay.qml15
-rw-r--r--tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp70
2 files changed, 85 insertions, 0 deletions
diff --git a/tests/auto/quickwidgets/qquickwidget/data/resizeOverlay.qml b/tests/auto/quickwidgets/qquickwidget/data/resizeOverlay.qml
new file mode 100644
index 0000000000..5547856941
--- /dev/null
+++ b/tests/auto/quickwidgets/qquickwidget/data/resizeOverlay.qml
@@ -0,0 +1,15 @@
+import QtQuick 2.15
+
+import Test 1.0
+
+Item {
+ id: root
+
+ property alias overlay: overlay
+
+ Overlay {
+ id: overlay
+ // Parent it to the contentItem of the underlying QQuickWindow.
+ parent: root.parent
+ }
+}
diff --git a/tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp b/tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp
index 691dfd1bc6..12c51caa75 100644
--- a/tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp
+++ b/tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp
@@ -33,6 +33,7 @@
#include <QtQml/qqmlcontext.h>
#include <QtQuick/qquickview.h>
#include <QtQuick/qquickitem.h>
+#include <QtQuick/private/qquickitem_p.h>
#include "../../shared/util.h"
#include <QtGui/QWindow>
#include <QtGui/QScreen>
@@ -142,6 +143,7 @@ private slots:
void synthMouseFromTouch_data();
void synthMouseFromTouch();
void tabKey();
+ void resizeOverlay();
private:
QTouchDevice *device = QTest::createTouchDevice();
@@ -662,6 +664,74 @@ void tst_qquickwidget::tabKey()
QVERIFY(middleItem->property("activeFocus").toBool());
}
+class Overlay : public QQuickItem, public QQuickItemChangeListener
+{
+ Q_OBJECT
+
+public:
+ Overlay() = default;
+
+ ~Overlay()
+ {
+ QQuickItemPrivate::get(parentItem())->removeItemChangeListener(this, QQuickItemPrivate::Geometry);
+ }
+
+ // componentCompleted() is too early to add the listener, as parentItem()
+ // is still null by that stage, so we use this function instead.
+ void startListening()
+ {
+ QQuickItemPrivate::get(parentItem())->addItemChangeListener(this, QQuickItemPrivate::Geometry);
+ }
+
+private:
+ virtual void itemGeometryChanged(QQuickItem *, QQuickGeometryChange, const QRectF &/*oldGeometry*/) override
+ {
+ auto window = QQuickItemPrivate::get(this)->window;
+ if (!window)
+ return;
+
+ setSize(window->size());
+ }
+};
+
+// Test that an item that resizes itself based on the window size can use a
+// Geometry item change listener to respond to changes in size. This is a
+// simplified test to mimic a use case involving Overlay from Qt Quick Controls 2.
+void tst_qquickwidget::resizeOverlay()
+{
+ QWidget widget;
+ auto contentVerticalLayout = new QVBoxLayout(&widget);
+ contentVerticalLayout->setMargin(0);
+
+ qmlRegisterType<Overlay>("Test", 1, 0, "Overlay");
+
+ auto quickWidget = new QQuickWidget(testFileUrl("resizeOverlay.qml"), &widget);
+ QCOMPARE(quickWidget->status(), QQuickWidget::Ready);
+ quickWidget->setResizeMode(QQuickWidget::SizeRootObjectToView);
+ contentVerticalLayout->addWidget(quickWidget);
+
+ auto rootItem = qobject_cast<QQuickItem*>(quickWidget->rootObject());
+ QVERIFY(rootItem);
+
+ auto overlay = rootItem->property("overlay").value<Overlay*>();
+ QVERIFY(overlay);
+ QVERIFY(overlay->parentItem());
+ overlay->startListening();
+
+ widget.resize(200, 200);
+ widget.show();
+ QCOMPARE(rootItem->width(), 200);
+ QCOMPARE(rootItem->height(), 200);
+ QCOMPARE(overlay->width(), rootItem->width());
+ QCOMPARE(overlay->height(), rootItem->height());
+
+ widget.resize(300, 300);
+ QCOMPARE(rootItem->width(), 300);
+ QCOMPARE(rootItem->height(), 300);
+ QCOMPARE(overlay->width(), rootItem->width());
+ QCOMPARE(overlay->height(), rootItem->height());
+}
+
QTEST_MAIN(tst_qquickwidget)
#include "tst_qquickwidget.moc"