Skip to content

Commit

Permalink
Ensure section header/footer are cleaned up.
Browse files Browse the repository at this point in the history
If the model is cleared or replaced with an empty one,
the section headers should be released.

Change-Id: Ia2f070c312593743b2c5332a6c69facaf222ee6d
Reviewed-by: Bea Lam <bea.lam@nokia.com>
  • Loading branch information
Martin Jones authored and Qt by Nokia committed Mar 19, 2012
1 parent cbe346a commit f079f78
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/quick/items/qquicklistview.cpp
Expand Up @@ -524,7 +524,9 @@ void QQuickListViewPrivate::clear()
sectionCache[i] = 0;
}
visiblePos = 0;
releaseSectionItem(currentSectionItem);
currentSectionItem = 0;
releaseSectionItem(nextSectionItem);
nextSectionItem = 0;
lastVisibleSection = QString();
QQuickItemViewPrivate::clear();
Expand Down Expand Up @@ -933,6 +935,8 @@ QQuickItem * QQuickListViewPrivate::getSectionItem(const QString &section)

void QQuickListViewPrivate::releaseSectionItem(QQuickItem *item)
{
if (!item)
return;
int i = 0;
do {
if (!sectionCache[i]) {
Expand Down Expand Up @@ -970,7 +974,7 @@ void QQuickListViewPrivate::updateInlineSection(FxListItemSG *listItem)

void QQuickListViewPrivate::updateStickySections()
{
if (!sectionCriteria || visibleItems.isEmpty()
if (!sectionCriteria
|| (!sectionCriteria->labelPositioning() && !currentSectionItem && !nextSectionItem))
return;

Expand Down Expand Up @@ -1006,7 +1010,7 @@ void QQuickListViewPrivate::updateStickySections()
}

// Current section header
if (sectionCriteria->labelPositioning() & QQuickViewSection::CurrentLabelAtStart) {
if (sectionCriteria->labelPositioning() & QQuickViewSection::CurrentLabelAtStart && isValid() && visibleItems.count()) {
if (!currentSectionItem) {
currentSectionItem = getSectionItem(currentSection);
} else if (currentStickySection != currentSection) {
Expand Down Expand Up @@ -1039,7 +1043,7 @@ void QQuickListViewPrivate::updateStickySections()
}

// Next section footer
if (sectionCriteria->labelPositioning() & QQuickViewSection::NextLabelAtEnd) {
if (sectionCriteria->labelPositioning() & QQuickViewSection::NextLabelAtEnd && isValid() && visibleItems.count()) {
if (!nextSectionItem) {
nextSectionItem = getSectionItem(nextSection);
} else if (nextStickySection != nextSection) {
Expand Down Expand Up @@ -1077,7 +1081,7 @@ void QQuickListViewPrivate::updateSections()

QQuickItemViewPrivate::updateSections();

if (sectionCriteria && !visibleItems.isEmpty()) {
if (sectionCriteria && !visibleItems.isEmpty() && isValid()) {
QString prevSection;
if (visibleIndex > 0)
prevSection = sectionAt(visibleIndex-1);
Expand Down
17 changes: 17 additions & 0 deletions tests/auto/quick/qquicklistview/tst_qquicklistview.cpp
Expand Up @@ -2182,6 +2182,23 @@ void tst_QQuickListView::sectionsPositioning()
QTRY_VERIFY(item = findVisibleChild(contentItem, "sect_aaa")); // inline label restored
QCOMPARE(item->y(), 0.);

// if an empty model is set the header/footer should be cleaned up
canvas->rootObject()->setProperty("sectionPositioning", QVariant(int(QQuickViewSection::InlineLabels | QQuickViewSection::CurrentLabelAtStart | QQuickViewSection::NextLabelAtEnd)));
QTRY_VERIFY(findVisibleChild(contentItem, "sect_aaa")); // section header
QTRY_VERIFY(findVisibleChild(contentItem, "sect_new")); // section footer
QmlListModel model1;
ctxt->setContextProperty("testModel", &model1);
QTRY_VERIFY(!findVisibleChild(contentItem, "sect_aaa")); // section header
QTRY_VERIFY(!findVisibleChild(contentItem, "sect_new")); // section footer

// clear model - header/footer should be cleaned up
ctxt->setContextProperty("testModel", &model);
QTRY_VERIFY(findVisibleChild(contentItem, "sect_aaa")); // section header
QTRY_VERIFY(findVisibleChild(contentItem, "sect_new")); // section footer
model.clear();
QTRY_VERIFY(!findVisibleChild(contentItem, "sect_aaa")); // section header
QTRY_VERIFY(!findVisibleChild(contentItem, "sect_new")); // section footer

delete canvas;
}

Expand Down

0 comments on commit f079f78

Please sign in to comment.