From 21311d3a352adcdb8c2e9f9c5af637e54293b6a8 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Thu, 3 May 2012 13:42:13 +1000 Subject: [PATCH] Move check for whether a layout is already in progress Move it out of applyModelChanges() into layout() since that's where it should really be checked. Change-Id: I24093e91e2ffadd5377ba44128168939e5db54c9 Reviewed-by: Andrew den Exter --- src/quick/items/qquickitemview.cpp | 24 +++++++++++++----------- src/quick/items/qquickitemview_p_p.h | 2 +- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/quick/items/qquickitemview.cpp b/src/quick/items/qquickitemview.cpp index 2a26e85..1b48a32 100644 --- a/src/quick/items/qquickitemview.cpp +++ b/src/quick/items/qquickitemview.cpp @@ -1093,14 +1093,14 @@ void QQuickItemViewPrivate::itemGeometryChanged(QQuickItem *item, const QRectF & if (currentItem && currentItem->item == item) { // don't allow item movement transitions to trigger a re-layout and // start new transitions - bool prevDisableLayout = disableLayout; - if (!disableLayout) { + bool prevInLayout = inLayout; + if (!inLayout) { FxViewItem *actualItem = transitioner ? visibleItem(currentIndex) : 0; if (actualItem && actualItem->transitionRunning()) - disableLayout = true; + inLayout = true; } updateHighlight(); - disableLayout = prevDisableLayout; + inLayout = prevInLayout; } if (trackedItem && trackedItem->item == item) @@ -1154,7 +1154,7 @@ void QQuickItemView::modelUpdated(const QQuickChangeSet &changeSet, bool reset) polish(); } } else { - if (d->disableLayout) { + if (d->inLayout) { d->bufferedChanges.prepare(d->currentIndex, d->itemCount); d->bufferedChanges.applyChanges(changeSet); } else { @@ -1419,7 +1419,7 @@ QQuickItemViewPrivate::QQuickItemViewPrivate() , transitioner(0) , minExtent(0), maxExtent(0) , ownModel(false), wrap(false) - , disableLayout(false), inViewportMoved(false), forceLayout(false), currentIndexCleared(false) + , inLayout(false), inViewportMoved(false), forceLayout(false), currentIndexCleared(false) , haveHighlightRange(false), autoHighlight(true), highlightRangeStartValid(false), highlightRangeEndValid(false) , fillCacheBuffer(false), inRequest(false), requestedAsync(false) , runDelayedRemoveTransition(false) @@ -1721,14 +1721,17 @@ void QQuickItemViewPrivate::updateViewport() void QQuickItemViewPrivate::layout() { Q_Q(QQuickItemView); - if (disableLayout) + if (inLayout) return; + inLayout = true; + if (!isValid() && !visibleItems.count()) { clear(); setPosition(contentStartOffset()); if (transitioner) transitioner->setPopulateTransitionEnabled(false); + inLayout = false; return; } @@ -1747,6 +1750,7 @@ void QQuickItemViewPrivate::layout() fillCacheBuffer = false; refill(); } + inLayout = false; return; } forceLayout = false; @@ -1806,16 +1810,15 @@ void QQuickItemViewPrivate::layout() } runDelayedRemoveTransition = false; + inLayout = false; } bool QQuickItemViewPrivate::applyModelChanges(ChangeResult *totalInsertionResult, ChangeResult *totalRemovalResult) { Q_Q(QQuickItemView); - if (!q->isComponentComplete() || !hasPendingChanges() || disableLayout) + if (!q->isComponentComplete() || !hasPendingChanges()) return false; - disableLayout = true; - if (bufferedChanges.hasPendingChanges()) { currentChanges.applyBufferedChanges(bufferedChanges); bufferedChanges.reset(); @@ -1957,7 +1960,6 @@ bool QQuickItemViewPrivate::applyModelChanges(ChangeResult *totalInsertionResult if (!visibleAffected && viewportChanged) updateViewport(); - disableLayout = false; return visibleAffected; } diff --git a/src/quick/items/qquickitemview_p_p.h b/src/quick/items/qquickitemview_p_p.h index 8fc83a9..5f28ac7 100644 --- a/src/quick/items/qquickitemview_p_p.h +++ b/src/quick/items/qquickitemview_p_p.h @@ -293,7 +293,7 @@ public: bool ownModel : 1; bool wrap : 1; - bool disableLayout : 1; + bool inLayout : 1; bool inViewportMoved : 1; bool forceLayout : 1; bool currentIndexCleared : 1; -- 2.7.4