else
d->bufferMode = d->hData.smoothVelocity < 0 ? QQuickItemViewPrivate::BufferBefore : QQuickItemViewPrivate::BufferAfter;
- d->refill();
+ d->refillOrLayout();
// Set visibility of items to eliminate cost of items outside the visible area.
qreal from = d->isContentFlowReversed() ? -d->position()-d->size() : d->position();
d->buffer = b;
if (isComponentComplete()) {
d->bufferMode = QQuickItemViewPrivate::BufferBefore | QQuickItemViewPrivate::BufferAfter;
- d->refill();
+ d->refillOrLayout();
}
emit cacheBufferChanged();
}
{
Q_D(QQuickItemView);
d->bufferMode = QQuickItemViewPrivate::BufferBefore | QQuickItemViewPrivate::BufferAfter;
- d->refill();
+ d->refillOrLayout();
if (d->haveHighlightRange && d->highlightRange == QQuickItemView::StrictlyEnforceRange)
d->updateHighlight();
}
bool QQuickItemViewPrivate::applyModelChanges(ChangeResult *totalInsertionResult, ChangeResult *totalRemovalResult)
{
Q_Q(QQuickItemView);
- if (!q->isComponentComplete() || (!currentChanges.hasPendingChanges() && !bufferedChanges.hasPendingChanges() && !runDelayedRemoveTransition) || disableLayout)
+ if (!q->isComponentComplete() || !hasPendingChanges() || disableLayout)
return false;
disableLayout = true;
hData.markExtentsDirty();
}
+ bool hasPendingChanges() const {
+ return currentChanges.hasPendingChanges()
+ || bufferedChanges.hasPendingChanges()
+ ||runDelayedRemoveTransition;
+ }
+
+ void refillOrLayout() {
+ if (hasPendingChanges())
+ layout();
+ else
+ refill();
+ }
+
QQmlGuard<QQuickVisualModel> model;
QVariant modelVariant;
int itemCount;
else
d->bufferMode = d->hData.smoothVelocity < 0 ? QQuickListViewPrivate::BufferBefore : QQuickListViewPrivate::BufferAfter;
- d->refill();
+ d->refillOrLayout();
// Set visibility of items to eliminate cost of items outside the visible area.
qreal from = d->isContentFlowReversed() ? -d->position()-d->size() : d->position();
void clear();
void moved();
void moved_data();
- void multipleChanges();
- void multipleChanges_data();
+ void multipleChanges_condensed() { multipleChanges(true); }
+ void multipleChanges_condensed_data() { multipleChanges_data(); }
+ void multipleChanges_uncondensed() { multipleChanges(false); }
+ void multipleChanges_uncondensed_data() { multipleChanges_data(); }
void swapWithFirstItem();
void changeFlow();
void currentIndex();
void matchItemsAndIndexes(const QVariantMap &items, const QaimModel &model, const QList<int> &expectedIndexes);
void matchItemLists(const QVariantList &itemLists, const QList<QQuickItem *> &expectedItems);
+ void multipleChanges(bool condensed);
+ void multipleChanges_data();
+
#ifdef SHARE_VIEWS
QQuickView *getView() {
if (m_view) {
<< -1.0; // 16,17,18 move to above item 0, all items move up by 1 row
}
-void tst_QQuickGridView::multipleChanges()
+void tst_QQuickGridView::multipleChanges(bool condensed)
{
QFETCH(int, startCount);
QFETCH(QList<ListChange>, changes);
}
case ListChange::Removed:
model.removeItems(changes[i].index, changes[i].count);
- QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
break;
case ListChange::Moved:
model.moveItems(changes[i].index, changes[i].to, changes[i].count);
- QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
break;
case ListChange::SetCurrent:
gridview->setCurrentIndex(changes[i].index);
- QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
break;
case ListChange::SetContentY:
gridview->setContentY(changes[i].pos);
- QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
break;
}
+ if (condensed) {
+ QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
+ }
}
+ QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
- QTRY_COMPARE(gridview->count(), newCount);
+ QCOMPARE(gridview->count(), newCount);
QCOMPARE(gridview->count(), model.count());
- QTRY_COMPARE(gridview->currentIndex(), newCurrentIndex);
+ QCOMPARE(gridview->currentIndex(), newCurrentIndex);
QQuickText *name;
QQuickText *number;
<< ListChange::remove(0, 5)
<< ListChange::insert(0, 5)
) << 5 << -1;
+
+ QTest::newRow("remove, scroll") << 30 << (QList<ListChange>()
+ << ListChange::remove(20, 5)
+ << ListChange::setContentY(20)
+ ) << 25 << 0;
+
+ QTest::newRow("insert, scroll") << 10 << (QList<ListChange>()
+ << ListChange::insert(9, 5)
+ << ListChange::setContentY(20)
+ ) << 15 << 0;
+
+ QTest::newRow("move, scroll") << 20 << (QList<ListChange>()
+ << ListChange::move(15, 8, 3)
+ << ListChange::setContentY(0)
+ ) << 20 << 0;
+
+ QTest::newRow("clear, insert, scroll") << 30 << (QList<ListChange>()
+ << ListChange::setContentY(20)
+ << ListChange::remove(0, 30)
+ << ListChange::insert(0, 2)
+ << ListChange::setContentY(0)
+ ) << 2 << 0;
}
void qAbstractItemModel_moved();
void qAbstractItemModel_moved_data();
- void multipleChanges();
- void multipleChanges_data();
+ void multipleChanges_condensed() { multipleChanges(true); }
+ void multipleChanges_condensed_data() { multipleChanges_data(); }
+ void multipleChanges_uncondensed() { multipleChanges(false); }
+ void multipleChanges_uncondensed_data() { multipleChanges_data(); }
void qListModelInterface_clear();
void qListModelInterface_package_clear();
template <class T> void clear(const QUrl &source);
template <class T> void sections(const QUrl &source);
+ void multipleChanges(bool condensed);
+ void multipleChanges_data();
+
QList<int> toIntList(const QVariantList &list);
void matchIndexLists(const QVariantList &indexLists, const QList<int> &expectedIndexes);
void matchItemsAndIndexes(const QVariantMap &items, const QaimModel &model, const QList<int> &expectedIndexes);
<< -20.0 * 3; // to minimize movement, 16,17,18 move to above item 0, and other items do not move
}
-void tst_QQuickListView::multipleChanges()
+void tst_QQuickListView::multipleChanges(bool condensed)
{
QFETCH(int, startCount);
QFETCH(QList<ListChange>, changes);
for (int j=changes[i].index; j<changes[i].index + changes[i].count; ++j)
items << qMakePair(QString("new item %1").arg(j), QString::number(j));
model.insertItems(changes[i].index, items);
- QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false);
break;
}
case ListChange::Removed:
model.removeItems(changes[i].index, changes[i].count);
- QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false);
break;
case ListChange::Moved:
model.moveItems(changes[i].index, changes[i].to, changes[i].count);
- QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false);
break;
case ListChange::SetCurrent:
listview->setCurrentIndex(changes[i].index);
- QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false);
break;
case ListChange::SetContentY:
listview->setContentY(changes[i].pos);
- QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false);
break;
+ default:
+ continue;
+ }
+ if (!condensed) {
+ QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false);
}
}
+ QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false);
- QTRY_COMPARE(listview->count(), newCount);
+ QCOMPARE(listview->count(), newCount);
QCOMPARE(listview->count(), model.count());
- QTRY_COMPARE(listview->currentIndex(), newCurrentIndex);
+ QCOMPARE(listview->currentIndex(), newCurrentIndex);
QQuickText *name;
QQuickText *number;
<< ListChange::insert(3, 5)
) << 15 << 8;
-
QTest::newRow("clear current") << 0 << (QList<ListChange>()
<< ListChange::insert(0, 5)
<< ListChange::setCurrent(-1)
<< ListChange::remove(0, 5)
<< ListChange::insert(0, 5)
) << 5 << -1;
+
+ QTest::newRow("remove, scroll") << 30 << (QList<ListChange>()
+ << ListChange::remove(20, 5)
+ << ListChange::setContentY(20)
+ ) << 25 << 0;
+
+ QTest::newRow("insert, scroll") << 10 << (QList<ListChange>()
+ << ListChange::insert(9, 5)
+ << ListChange::setContentY(20)
+ ) << 15 << 0;
+
+ QTest::newRow("move, scroll") << 20 << (QList<ListChange>()
+ << ListChange::move(15, 8, 3)
+ << ListChange::setContentY(0)
+ ) << 20 << 0;
+
+ QTest::newRow("clear, insert, scroll") << 30 << (QList<ListChange>()
+ << ListChange::setContentY(20)
+ << ListChange::remove(0, 30)
+ << ListChange::insert(0, 2)
+ << ListChange::setContentY(0)
+ ) << 2 << 0;
}
void tst_QQuickListView::swapWithFirstItem()