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).

Approved by PS Jenkins bot, Daniel d'Andrada.

commita4d04ad1d5717fe3a37d311c0200840bb2ac8953 authorAlbert Astals <albert.astals@canonical.com> dateSun 22 Dec 2013, 22:59 (13 years ago) parent0def2e865194a3
2 files changed+50−5
plugins/DashViews/verticaljournal.cpp+18−5 tests/plugins/DashViews/verticaljournaltest.cpp+32
plugins/DashViews/verticaljournal.cpp+18−5
@@ -516,16 +516,29 @@ void VerticalJournal::onModelUpdated(const QQmlChangeSet &changeSet, bool reset)
516516 for (int i = remove.count - 1; i >= 0; --i) {
517517 const int indexToRemove = remove.index + i;
518518 // 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)
520522 bool found = false;
523+ int lastCreatedIndex = INT_MIN;
521524 for (int i = 0; !found && i < m_columnVisibleItems.count(); ++i) {
522525 QList<ViewItem> &column = m_columnVisibleItems[i];
523− if (!column.isEmpty() && column.last().m_modelIndex == indexToRemove) {
524− releaseItem(column.takeLast());
525− found = true;
526+ if (!column.isEmpty()) {
527+ const int lastColumnIndex = column.last().m_modelIndex;
528+ if (lastColumnIndex == indexToRemove) {
529+ releaseItem(column.takeLast());
530+ found = true;
531+ }
532+ lastCreatedIndex = qMax(lastCreatedIndex, lastColumnIndex);
533+ }
534+ }
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;
526540 }
527541 }
528− Q_ASSERT(found);
529542 }
530543 }
531544 }
tests/plugins/DashViews/verticaljournaltest.cpp+32
@@ -359,6 +359,38 @@ private Q_SLOTS:
359359 verifyItem(vj->m_columnVisibleItems[1][1], 3, 160, 60, true);
360360 }
361361
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+
362394 void testModelAppendRemoveLast()
363395 {
364396 QHeightModel *model2 = new QHeightModel();