Avoid anchor/positioning loops
authorAlan Alpert <alan.alpert@nokia.com>
Fri, 20 Jan 2012 04:35:27 +0000 (14:35 +1000)
committerQt by Nokia <qt-info@nokia.com>
Mon, 23 Jan 2012 02:43:09 +0000 (03:43 +0100)
Task-number: QTBUG-23740

Change-Id: I84922ac2dc6e499fc22b923298ca31eda382c622
Reviewed-by: Alan Alpert <alan.alpert@nokia.com>
src/quick/items/qquickpositioners.cpp
tests/auto/qtquick2/qquickanchors/tst_qquickanchors.cpp
tests/auto/qtquick2/qquickpositioners/tst_qquickpositioners.cpp

index 321ff7f..b50c73d 100644 (file)
@@ -172,7 +172,6 @@ void QQuickBasePositioner::componentComplete()
     QQuickItem::componentComplete();
     positionedItems.reserve(childItems().count());
     prePositioning();
-    reportConflictingAnchors();
 }
 
 void QQuickBasePositioner::itemChange(ItemChange change, const ItemChangeData &value)
@@ -239,8 +238,11 @@ void QQuickBasePositioner::prePositioning()
         }
     }
     QSizeF contentSize(0,0);
-    doPositioning(&contentSize);
-    updateAttachedProperties();
+    reportConflictingAnchors();
+    if (!d->anchorConflict) {
+        doPositioning(&contentSize);
+        updateAttachedProperties();
+    }
     if (!d->addActions.isEmpty() || !d->moveActions.isEmpty())
         finishApplyTransitions();
     d->doingPositioning = false;
@@ -574,7 +576,8 @@ void QQuickColumn::reportConflictingAnchors()
         }
     }
     if (d->anchorConflict) {
-        qmlInfo(this) << "Cannot specify top, bottom, verticalCenter, fill or centerIn anchors for items inside Column";
+        qmlInfo(this) << "Cannot specify top, bottom, verticalCenter, fill or centerIn anchors for items inside Column."
+            << " Column will not function.";
     }
 }
 /*!
@@ -800,7 +803,8 @@ void QQuickRow::reportConflictingAnchors()
         }
     }
     if (d->anchorConflict)
-        qmlInfo(this) << "Cannot specify left, right, horizontalCenter, fill or centerIn anchors for items inside Row";
+        qmlInfo(this) << "Cannot specify left, right, horizontalCenter, fill or centerIn anchors for items inside Row."
+            << " Row will not function.";
 }
 
 /*!
@@ -1234,7 +1238,7 @@ void QQuickGrid::reportConflictingAnchors()
         }
     }
     if (d->anchorConflict)
-        qmlInfo(this) << "Cannot specify anchors for items inside Grid";
+        qmlInfo(this) << "Cannot specify anchors for items inside Grid." << " Grid will not function.";
 }
 
 /*!
@@ -1526,7 +1530,7 @@ void QQuickFlow::reportConflictingAnchors()
         }
     }
     if (d->anchorConflict)
-        qmlInfo(this) << "Cannot specify anchors for items inside Flow";
+        qmlInfo(this) << "Cannot specify anchors for items inside Flow." << " Flow will not function.";
 }
 
 QT_END_NAMESPACE
index 9725390..fd08345 100644 (file)
@@ -482,7 +482,7 @@ void tst_qquickanchors::crash1()
 {
     QUrl source(testFileUrl("crash1.qml"));
 
-    QString expect = source.toString() + ":3:1: QML Column: Cannot specify top, bottom, verticalCenter, fill or centerIn anchors for items inside Column";
+    QString expect = source.toString() + ":3:1: QML Column: Cannot specify top, bottom, verticalCenter, fill or centerIn anchors for items inside Column. Column will not function.";
 
     QTest::ignoreMessage(QtWarningMsg, expect.toLatin1());
 
index 441c343..08ae5e2 100644 (file)
@@ -1206,14 +1206,14 @@ void tst_qquickpositioners::test_conflictinganchors()
     component.setData("import QtQuick 2.0\nColumn { Item { anchors.top: parent.top } }", QUrl::fromLocalFile(""));
     item = qobject_cast<QQuickItem*>(component.create());
     QVERIFY(item);
-    QCOMPARE(warningMessage, QString("file::2:1: QML Column: Cannot specify top, bottom, verticalCenter, fill or centerIn anchors for items inside Column"));
+    QCOMPARE(warningMessage, QString("file::2:1: QML Column: Cannot specify top, bottom, verticalCenter, fill or centerIn anchors for items inside Column. Column will not function."));
     warningMessage.clear();
     delete item;
 
     component.setData("import QtQuick 2.0\nColumn { Item { anchors.centerIn: parent } }", QUrl::fromLocalFile(""));
     item = qobject_cast<QQuickItem*>(component.create());
     QVERIFY(item);
-    QCOMPARE(warningMessage, QString("file::2:1: QML Column: Cannot specify top, bottom, verticalCenter, fill or centerIn anchors for items inside Column"));
+    QCOMPARE(warningMessage, QString("file::2:1: QML Column: Cannot specify top, bottom, verticalCenter, fill or centerIn anchors for items inside Column. Column will not function."));
     warningMessage.clear();
     delete item;
 
@@ -1227,14 +1227,14 @@ void tst_qquickpositioners::test_conflictinganchors()
     component.setData("import QtQuick 2.0\nRow { Item { anchors.left: parent.left } }", QUrl::fromLocalFile(""));
     item = qobject_cast<QQuickItem*>(component.create());
     QVERIFY(item);
-    QCOMPARE(warningMessage, QString("file::2:1: QML Row: Cannot specify left, right, horizontalCenter, fill or centerIn anchors for items inside Row"));
+    QCOMPARE(warningMessage, QString("file::2:1: QML Row: Cannot specify left, right, horizontalCenter, fill or centerIn anchors for items inside Row. Row will not function."));
     warningMessage.clear();
     delete item;
 
     component.setData("import QtQuick 2.0\nRow { Item { anchors.fill: parent } }", QUrl::fromLocalFile(""));
     item = qobject_cast<QQuickItem*>(component.create());
     QVERIFY(item);
-    QCOMPARE(warningMessage, QString("file::2:1: QML Row: Cannot specify left, right, horizontalCenter, fill or centerIn anchors for items inside Row"));
+    QCOMPARE(warningMessage, QString("file::2:1: QML Row: Cannot specify left, right, horizontalCenter, fill or centerIn anchors for items inside Row. Row will not function."));
     warningMessage.clear();
     delete item;
 
@@ -1248,27 +1248,27 @@ void tst_qquickpositioners::test_conflictinganchors()
     component.setData("import QtQuick 2.0\nGrid { Item { anchors.horizontalCenter: parent.horizontalCenter } }", QUrl::fromLocalFile(""));
     item = qobject_cast<QQuickItem*>(component.create());
     QVERIFY(item);
-    QCOMPARE(warningMessage, QString("file::2:1: QML Grid: Cannot specify anchors for items inside Grid"));
+    QCOMPARE(warningMessage, QString("file::2:1: QML Grid: Cannot specify anchors for items inside Grid. Grid will not function."));
     warningMessage.clear();
     delete item;
 
     component.setData("import QtQuick 2.0\nGrid { Item { anchors.centerIn: parent } }", QUrl::fromLocalFile(""));
     item = qobject_cast<QQuickItem*>(component.create());
     QVERIFY(item);
-    QCOMPARE(warningMessage, QString("file::2:1: QML Grid: Cannot specify anchors for items inside Grid"));
+    QCOMPARE(warningMessage, QString("file::2:1: QML Grid: Cannot specify anchors for items inside Grid. Grid will not function."));
     warningMessage.clear();
     delete item;
 
     component.setData("import QtQuick 2.0\nFlow { Item { anchors.verticalCenter: parent.verticalCenter } }", QUrl::fromLocalFile(""));
     item = qobject_cast<QQuickItem*>(component.create());
     QVERIFY(item);
-    QCOMPARE(warningMessage, QString("file::2:1: QML Flow: Cannot specify anchors for items inside Flow"));
+    QCOMPARE(warningMessage, QString("file::2:1: QML Flow: Cannot specify anchors for items inside Flow. Flow will not function."));
     delete item;
 
     component.setData("import QtQuick 2.0\nFlow { Item { anchors.fill: parent } }", QUrl::fromLocalFile(""));
     item = qobject_cast<QQuickItem*>(component.create());
     QVERIFY(item);
-    QCOMPARE(warningMessage, QString("file::2:1: QML Flow: Cannot specify anchors for items inside Flow"));
+    QCOMPARE(warningMessage, QString("file::2:1: QML Flow: Cannot specify anchors for items inside Flow. Flow will not function."));
     qInstallMsgHandler(oldMsgHandler);
     delete item;
 }