QQuickLoader: fix the recursion guard for size updates
authorJ-P Nurmi <jpnurmi@digia.com>
Wed, 13 Mar 2013 17:31:57 +0000 (18:31 +0100)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Sun, 17 Mar 2013 13:59:49 +0000 (14:59 +0100)
Task-number: QTBUG-30183
Change-Id: Ic8720e1e35bf2f349d74d2021dd202849da67852
Reviewed-by: Jan Arve Sæther <jan-arve.saether@digia.com>
Reviewed-by: Caroline Chao <caroline.chao@digia.com>
Reviewed-by: Jens Bache-Wiig <jens.bache-wiig@digia.com>
src/quick/items/qquickloader.cpp
tests/auto/quick/qquickloader/data/QTBUG_30183.qml [new file with mode: 0644]
tests/auto/quick/qquickloader/tst_qquickloader.cpp

index 0434c2a..0d14f3e 100644 (file)
@@ -887,16 +887,19 @@ void QQuickLoader::setAsynchronous(bool a)
 void QQuickLoaderPrivate::_q_updateSize(bool loaderGeometryChanged)
 {
     Q_Q(QQuickLoader);
-    if (!item || updatingSize)
+    if (!item)
         return;
 
-    updatingSize = true;
-
     if (loaderGeometryChanged && q->widthValid())
         item->setWidth(q->width());
     if (loaderGeometryChanged && q->heightValid())
         item->setHeight(q->height());
 
+    if (updatingSize)
+        return;
+
+    updatingSize = true;
+
     q->setImplicitSize(getImplicitWidth(), getImplicitHeight());
 
     updatingSize = false;
diff --git a/tests/auto/quick/qquickloader/data/QTBUG_30183.qml b/tests/auto/quick/qquickloader/data/QTBUG_30183.qml
new file mode 100644 (file)
index 0000000..1f626d9
--- /dev/null
@@ -0,0 +1,12 @@
+import QtQuick 2.0
+
+Loader {
+    width: implicitWidth
+    height: implicitHeight
+
+    sourceComponent: Rectangle {
+        color: "green"
+        implicitWidth: 240
+        implicitHeight: 120
+    }
+}
index d01e8aa..50ded4d 100644 (file)
@@ -126,6 +126,7 @@ private slots:
 
     void parented();
     void sizeBound();
+    void QTBUG_30183();
 
 private:
     QQmlEngine engine;
@@ -1126,6 +1127,22 @@ void tst_QQuickLoader::sizeBound()
     delete root;
 }
 
+void tst_QQuickLoader::QTBUG_30183()
+{
+    QQmlComponent component(&engine, testFileUrl("/QTBUG_30183.qml"));
+    QQuickLoader *loader = qobject_cast<QQuickLoader*>(component.create());
+    QVERIFY(loader != 0);
+    QCOMPARE(loader->width(), 240.0);
+    QCOMPARE(loader->height(), 120.0);
+
+    // the loaded item must follow the size
+    QQuickItem *rect = qobject_cast<QQuickItem*>(loader->item());
+    QVERIFY(rect);
+    QCOMPARE(rect->width(), 240.0);
+    QCOMPARE(rect->height(), 120.0);
+
+    delete loader;
+}
 
 QTEST_MAIN(tst_QQuickLoader)