Keep polishing until there is nothing left to polish.
authorGunnar Sletta <gunnar.sletta@nokia.com>
Thu, 3 May 2012 13:48:53 +0000 (15:48 +0200)
committerQt by Nokia <qt-info@nokia.com>
Thu, 3 May 2012 16:48:15 +0000 (18:48 +0200)
Some items will trigger changes in updatePolish() which
again trigger property changes which needs polish to
be executed again. If we do not polish until the set
is fully cleared, we will end up with some items being
in an unpolished state.

To avoid polishing from going on indefinitely, we have a
countdown that spits out a warning if polishing goes
on forever.

Change-Id: I4da6e884ca0d52b9b2701082ecf13e8c65508524
Reviewed-by: Aaron Kennedy <aaron.kennedy@nokia.com>
src/quick/items/qquickcanvas.cpp

index a6905b5..9a9a70b 100644 (file)
@@ -211,14 +211,22 @@ void QQuickCanvas::focusInEvent(QFocusEvent *)
 
 void QQuickCanvasPrivate::polishItems()
 {
-    QSet<QQuickItem *> itms = itemsToPolish;
-    itemsToPolish.clear();
+    int maxPolishCycles = 100000;
 
-    for (QSet<QQuickItem *>::iterator it = itms.begin(); it != itms.end(); ++it) {
-        QQuickItem *item = *it;
-        QQuickItemPrivate::get(item)->polishScheduled = false;
-        item->updatePolish();
+    while (!itemsToPolish.isEmpty() && --maxPolishCycles > 0) {
+        QSet<QQuickItem *> itms = itemsToPolish;
+        itemsToPolish.clear();
+
+        for (QSet<QQuickItem *>::iterator it = itms.begin(); it != itms.end(); ++it) {
+            QQuickItem *item = *it;
+            QQuickItemPrivate::get(item)->polishScheduled = false;
+            item->updatePolish();
+        }
     }
+
+    if (maxPolishCycles == 0)
+        qWarning("QQuickCanvas: possible QQuickItem::polish() loop");
+
     updateFocusItemTransform();
 }