on xenial help sign in
Do not assert if the item we are removing was not created yet (because e.g. it's not in the viewport).
a4d04adAlbert Astals
plugins/DashViews/verticaljournal.cpp+18−5
@@ -516,16 +516,29 @@ void VerticalJournal::onModelUpdated(const QQmlChangeSet &changeSet, bool reset)
516 for (int i = remove.count - 1; i >= 0; --i) {
516 for (int i = remove.count - 1; i >= 0; --i) {
517 const int indexToRemove = remove.index + i;
517 const int indexToRemove = remove.index + i;
518 // Since we only support removing from the end, indexToRemove
518 // Since we only support removing from the end, indexToRemove
519− // must refer to the last item of one of the columns.
519+ // must refer to the last item of one of the columns or
520+ // be bigger than them (because it's not in the viewport and
521+ // thus we have not created a delegate for it)
520 bool found = false;
522 bool found = false;
523+ int lastCreatedIndex = INT_MIN;
521 for (int i = 0; !found && i < m_columnVisibleItems.count(); ++i) {
524 for (int i = 0; !found && i < m_columnVisibleItems.count(); ++i) {
522 QList<ViewItem> &column = m_columnVisibleItems[i];
525 QList<ViewItem> &column = m_columnVisibleItems[i];
523− if (!column.isEmpty() && column.last().m_modelIndex == indexToRemove) {
526+ if (!column.isEmpty()) {
527+ const int lastColumnIndex = column.last().m_modelIndex;
528+ if (lastColumnIndex == indexToRemove) {
524− releaseItem(column.takeLast());
529+ releaseItem(column.takeLast());
530+ found = true;
531+ }
532+ lastCreatedIndex = qMax(lastCreatedIndex, lastColumnIndex);
533+ }
534+ }
525− found = true;
535+ if (!found) {
536+ if (indexToRemove < lastCreatedIndex) {
537+ qFatal("VerticalJournal only supports removal from the end of the model");
538+ } else {
539+ m_implicitHeightDirty = true;
526 }
540 }
527 }
541 }
528− Q_ASSERT(found);
529 }
542 }
530 }
543 }
531 }
544 }
tests/plugins/DashViews/verticaljournaltest.cpp+32
@@ -359,6 +359,38 @@ private Q_SLOTS:
359 verifyItem(vj->m_columnVisibleItems[1][1], 3, 160, 60, true);
359 verifyItem(vj->m_columnVisibleItems[1][1], 3, 160, 60, true);
360 }
360 }
361
361
362+ void testModelRemoveLastNonVisible()
363+ {
364+ model->removeLast();
365+
366+ // This is the same as checkInitialPositions but
367+ // with a different implicitHeight since there's an item less
368+ // in the model
369+ QTRY_COMPARE(vj->m_columnVisibleItems.count(), 3);
370+ QTRY_COMPARE(vj->m_columnVisibleItems[0].count(), 5);
371+ QTRY_COMPARE(vj->m_columnVisibleItems[1].count(), 7);
372+ QTRY_COMPARE(vj->m_columnVisibleItems[2].count(), 6);
373+ verifyItem(vj->m_columnVisibleItems[0][0], 0, 0, 0, true);
374+ verifyItem(vj->m_columnVisibleItems[1][0], 1, 160, 0, true);
375+ verifyItem(vj->m_columnVisibleItems[2][0], 2, 320, 0, true);
376+ verifyItem(vj->m_columnVisibleItems[1][1], 3, 160, 60, true);
377+ verifyItem(vj->m_columnVisibleItems[1][2], 4, 160, 80, true);
378+ verifyItem(vj->m_columnVisibleItems[0][1], 5, 0, 110, true);
379+ verifyItem(vj->m_columnVisibleItems[1][3], 6, 160, 130, true);
380+ verifyItem(vj->m_columnVisibleItems[2][1], 7, 320, 135, true);
381+ verifyItem(vj->m_columnVisibleItems[0][2], 8, 0, 190, true);
382+ verifyItem(vj->m_columnVisibleItems[2][2], 9, 320, 255, true);
383+ verifyItem(vj->m_columnVisibleItems[2][3], 10, 320, 285, true);
384+ verifyItem(vj->m_columnVisibleItems[2][4], 11, 320, 315, true);
385+ verifyItem(vj->m_columnVisibleItems[1][4], 12, 160, 340, true);
386+ verifyItem(vj->m_columnVisibleItems[0][3], 13, 0, 360, true);
387+ verifyItem(vj->m_columnVisibleItems[2][5], 14, 320, 390, true);
388+ verifyItem(vj->m_columnVisibleItems[1][5], 15, 160, 430, false);
389+ verifyItem(vj->m_columnVisibleItems[0][4], 16, 0, 570, false);
390+ verifyItem(vj->m_columnVisibleItems[1][6], 17, 160, 570, false);
391+ QTRY_COMPARE(vj->implicitHeight(), 970. + 1. * 970. / 18.);
392+ }
393+
362 void testModelAppendRemoveLast()
394 void testModelAppendRemoveLast()
363 {
395 {
364 QHeightModel *model2 = new QHeightModel();
396 QHeightModel *model2 = new QHeightModel();