From 10bb998da35809d90ee9d0e9bc677fc710355031 Mon Sep 17 00:00:00 2001 From: Robin Burchell Date: Mon, 19 Oct 2015 23:40:14 +0200 Subject: [PATCH] DEBUG Change-Id: Ic8bfc948f8844661b44177ca6fb6bbf80a0332d6 --- src/quick/items/qquickitemview.cpp | 24 ++++++++++++++++++++++-- src/quick/items/qquicklistview.cpp | 27 +++++++++++++++++++++++++-- 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/src/quick/items/qquickitemview.cpp b/src/quick/items/qquickitemview.cpp index b618daf..370b5bb 100644 --- a/src/quick/items/qquickitemview.cpp +++ b/src/quick/items/qquickitemview.cpp @@ -1153,14 +1153,26 @@ qreal QQuickItemViewPrivate::calculatedMaxExtent() const // for debugging only void QQuickItemViewPrivate::checkVisible() const { + qDebug() << "CHECKING VISIBLE:"; + + showVisibleItems(); + + QHash uniqueItems; int skip = 0; for (int i = 0; i < visibleItems.count(); ++i) { FxViewItem *item = visibleItems.at(i); if (item->index == -1) { ++skip; } else if (item->index != visibleIndex + i - skip) { - qFatal("index %d %d %d", visibleIndex, i, item->index); + qFatal("first visible: %d at: %d was: %d expected: %d (skip %d)", visibleIndex, i, item->index, visibleIndex + i - skip, skip); + } + + if (uniqueItems.contains(item->item)) { + qWarning() << "item " << item->item << " found at " << uniqueItems.find(item->item).value() << " and " << i; + qFatal("boom"); } + + uniqueItems.insert(item->item, i); } } @@ -1170,7 +1182,7 @@ void QQuickItemViewPrivate::showVisibleItems() const qDebug() << "Visible items:"; for (int i = 0; i < visibleItems.count(); ++i) { qDebug() << "\t" << visibleItems[i]->index - << visibleItems[i]->item->objectName() + << visibleItems[i]->item << visibleItems[i]->position(); } } @@ -2016,6 +2028,8 @@ bool QQuickItemViewPrivate::applyModelChanges(ChangeResult *totalInsertionResult QList newItems; QList movingIntoView; + qDebug() << "Before insertions"; + showVisibleItems(); for (int i=0; iattached) newItems.at(i)->attached->emitAdd(); @@ -2087,6 +2104,9 @@ bool QQuickItemViewPrivate::applyModelChanges(ChangeResult *totalInsertionResult if (!visibleAffected && viewportChanged) updateViewport(); + qDebug() << "applyModelChanges done"; + checkVisible(); + return visibleAffected; } diff --git a/src/quick/items/qquicklistview.cpp b/src/quick/items/qquicklistview.cpp index 6a2de58..7155448 100644 --- a/src/quick/items/qquicklistview.cpp +++ b/src/quick/items/qquicklistview.cpp @@ -634,6 +634,8 @@ bool QQuickListViewPrivate::releaseItem(FxViewItem *item) bool QQuickListViewPrivate::addVisibleItems(qreal fillFrom, qreal fillTo, qreal bufferFrom, qreal bufferTo, bool doBuffer) { + qDebug() << "addVisibleItems start " << fillFrom << fillTo; + checkVisible(); qreal itemEnd = visiblePos; if (visibleItems.count()) { visiblePos = (*visibleItems.constBegin())->position(); @@ -668,7 +670,7 @@ bool QQuickListViewPrivate::addVisibleItems(qreal fillFrom, qreal fillTo, qreal while (modelIndex < model->count() && pos <= fillTo) { if (!(item = static_cast(createItem(modelIndex, doBuffer)))) break; - qCDebug(lcItemViewDelegateLifecycle) << "refill: append item" << modelIndex << "pos" << pos << "buffer" << doBuffer << "item" << (QObject *)(item->item); + qCDebug(lcItemViewDelegateLifecycle) << "refill: append item" << modelIndex << "pos" << pos << "buffer" << doBuffer << "item" << item->item << "itemidx" << item->index; if (!transitioner || !transitioner->canTransition(QQuickItemViewTransitioner::PopulateTransition, true)) // pos will be set by layoutVisibleItems() item->setPosition(pos, true); if (item->item) @@ -685,7 +687,7 @@ bool QQuickListViewPrivate::addVisibleItems(qreal fillFrom, qreal fillTo, qreal while (visibleIndex > 0 && visibleIndex <= model->count() && visiblePos > fillFrom) { if (!(item = static_cast(createItem(visibleIndex-1, doBuffer)))) break; - qCDebug(lcItemViewDelegateLifecycle) << "refill: prepend item" << visibleIndex-1 << "current top pos" << visiblePos << "buffer" << doBuffer << "item" << (QObject *)(item->item); + qCDebug(lcItemViewDelegateLifecycle) << "refill: prepend item" << visibleIndex-1 << "current top pos" << visiblePos << "buffer" << doBuffer << "item" << item->item << "itemidx" << item->index; --visibleIndex; visiblePos -= item->size() + spacing; if (!transitioner || !transitioner->canTransition(QQuickItemViewTransitioner::PopulateTransition, true)) // pos will be set by layoutVisibleItems() @@ -696,11 +698,15 @@ bool QQuickListViewPrivate::addVisibleItems(qreal fillFrom, qreal fillTo, qreal changed = true; } + qDebug() << "addVisibleItems end"; + checkVisible(); return changed; } bool QQuickListViewPrivate::removeNonVisibleItems(qreal bufferFrom, qreal bufferTo) { + qDebug() << "removeNonVisibleItems start"; + checkVisible(); FxViewItem *item = 0; bool changed = false; @@ -726,6 +732,7 @@ bool QQuickListViewPrivate::removeNonVisibleItems(qreal bufferFrom, qreal buffer item->releaseAfterTransition = true; releasePendingTransition.append(item); } else { + qCDebug(lcItemViewDelegateLifecycle) << "\treleasing stationary item" << item->index << (QObject *)(item->item); releaseItem(item); } if (index == 0) @@ -748,11 +755,14 @@ bool QQuickListViewPrivate::removeNonVisibleItems(qreal bufferFrom, qreal buffer item->releaseAfterTransition = true; releasePendingTransition.append(item); } else { + qCDebug(lcItemViewDelegateLifecycle) << "\treleasing stationary item" << item->index << (QObject *)(item->item); releaseItem(item); } changed = true; } + qDebug() << "removeNonVisibleItems end"; + checkVisible(); return changed; } @@ -3068,10 +3078,16 @@ void QQuickListViewPrivate::updateSectionCriteria() bool QQuickListViewPrivate::applyInsertionChange(const QQmlChangeSet::Change &change, ChangeResult *insertResult, QList *addedItems, QList *movingIntoView) { + qDebug() << "applyInsertionChange start"; + checkVisible(); int modelIndex = change.index; int count = change.count; qreal tempPos = isContentFlowReversed() ? -position()-size() : position(); + + // modelIndex is the source row + // index is the index of modelIndex in the visibleItems vector + int index = visibleItems.count() ? mapFromModel(modelIndex) : 0; if (index < 0) { @@ -3121,6 +3137,7 @@ bool QQuickListViewPrivate::applyInsertionChange(const QQmlChangeSet::Change &ch int prevVisibleCount = visibleItems.count(); if (insertResult->visiblePos.isValid() && pos < insertResult->visiblePos) { // Insert items before the visible item. + qDebug() << "Insert BEFORE visible"; int insertionIdx = index; int i = 0; qreal from = tempPos - displayMarginBeginning - buffer; @@ -3128,6 +3145,7 @@ bool QQuickListViewPrivate::applyInsertionChange(const QQmlChangeSet::Change &ch for (i = count-1; i >= 0; --i) { if (pos > from && insertionIdx < visibleIndex) { // item won't be visible, just note the size for repositioning + qDebug() << "Item " << i << " NOT VISIBLE"; insertResult->sizeChangesBeforeVisiblePos += averageSize + spacing; pos -= averageSize + spacing; } else { @@ -3140,6 +3158,7 @@ bool QQuickListViewPrivate::applyInsertionChange(const QQmlChangeSet::Change &ch if (!item) return false; + qCDebug(lcItemViewDelegateLifecycle) << "refill: insert item before visible " << modelIndex + i << "pos" << pos << "item" << item->item; visibleItems.insert(insertionIdx, item); if (insertionIdx == 0) insertResult->changedFirstItem = true; @@ -3165,7 +3184,9 @@ bool QQuickListViewPrivate::applyInsertionChange(const QQmlChangeSet::Change &ch if (!item) return false; + qCDebug(lcItemViewDelegateLifecycle) << "refill: insert item (2) " << modelIndex + i << "pos" << pos << "item" << item->item; visibleItems.insert(index, item); + if (index == 0) insertResult->changedFirstItem = true; if (change.isMove()) { @@ -3184,6 +3205,8 @@ bool QQuickListViewPrivate::applyInsertionChange(const QQmlChangeSet::Change &ch } updateVisibleIndex(); + qDebug() << "applyInsertionChange end"; + checkVisible(); return visibleItems.count() > prevVisibleCount; } -- 2.6.0