Make section header updates part of the layout process.
Task-number: QTBUG-23298
Change-Id: I4586bc58bc195fcc47f6db79346727eb6e3d3845
Reviewed-by: Bea Lam <bea.lam@nokia.com>
d->cellWidth = qMax(qreal(1), cellWidth);
d->updateViewport();
emit cellWidthChanged();
- d->forceLayout = true;
- polish();
+ d->forceLayoutPolish();
}
}
d->cellHeight = qMax(qreal(1), cellHeight);
d->updateViewport();
emit cellHeightChanged();
- d->forceLayout = true;
- polish();
+ d->forceLayoutPolish();
}
}
/*!
connect(d->model, SIGNAL(initItem(int,QQuickItem*)), this, SLOT(initItem(int,QQuickItem*)));
connect(d->model, SIGNAL(destroyingItem(QQuickItem*)), this, SLOT(destroyingItem(QQuickItem*)));
if (isComponentComplete()) {
- updateSections();
+ d->updateSectionCriteria();
d->refill();
if ((d->currentIndex >= d->model->count() || d->currentIndex < 0) && !d->currentIndexCleared) {
setCurrentIndex(0);
d->updateViewport();
if (d->transitioner && d->transitioner->populateTransition) {
- d->forceLayout = true;
d->transitioner->setPopulateTransitionEnabled(true);
- polish();
+ d->forceLayoutPolish();
}
}
connect(d->model, SIGNAL(modelUpdated(QQuickChangeSet,bool)),
d->visibleItems.clear();
d->releaseItem(d->currentItem);
d->currentItem = 0;
- updateSections();
+ d->updateSectionCriteria();
d->refill();
d->moveReason = QQuickItemViewPrivate::SetIndex;
d->updateCurrent(d->currentIndex);
}
// Correct the positioning of the items
- d->updateSections();
- d->forceLayout = true;
- polish();
+ d->forceLayoutPolish();
}
void QQuickItemView::modelUpdated(const QQuickChangeSet &changeSet, bool reset)
}
d->moveReason = QQuickItemViewPrivate::Other;
emit countChanged();
- if (d->transitioner && d->transitioner->populateTransition) {
- d->forceLayout = true;
- polish();
- }
+ if (d->transitioner && d->transitioner->populateTransition)
+ d->forceLayoutPolish();
} else {
if (d->inLayout) {
d->bufferedChanges.prepare(d->currentIndex, d->itemCount);
{
Q_D(QQuickItemView);
d->markExtentsDirty();
- if (isComponentComplete() && d->isValid()) {
- d->forceLayout = true;
- polish();
- }
+ if (isComponentComplete() && d->isValid())
+ d->forceLayoutPolish();
QQuickFlickable::geometryChanged(newGeometry, oldGeometry);
}
QQuickFlickable::componentComplete();
- updateSections();
+ d->updateSectionCriteria();
d->updateHeader();
d->updateFooter();
d->updateViewport();
visibleItems.at(i)->transitionNextReposition(transitioner, QQuickItemViewTransitioner::PopulateTransition, true);
}
}
+
+ updateSections();
layoutVisibleItems();
int lastIndexInView = findLastIndexInView();
virtual qreal maxXExtent() const;
protected slots:
- virtual void updateSections() {}
void destroyRemoved();
void createdItem(int index, QQuickItem *item);
virtual void initItem(int index, QQuickItem *item);
refill();
}
+ void forceLayoutPolish() {
+ Q_Q(QQuickItemView);
+ forceLayout = true;
+ q->polish();
+ }
+
QQmlGuard<QQuickVisualModel> model;
QVariant modelVariant;
int itemCount;
virtual void initializeViewItem(FxViewItem *) {}
virtual void initializeCurrentItem() {}
+ virtual void updateSectionCriteria() {}
virtual void updateSections() {}
virtual void itemGeometryChanged(QQuickItem *item, const QRectF &newGeometry, const QRectF &oldGeometry);
virtual bool applyInsertionChange(const QQuickChangeSet::Insert &insert, ChangeResult *changeResult, QList<FxViewItem *> *addedItems, QList<MovedItem> *movingIntoView);
virtual void translateAndTransitionItemsAfter(int afterIndex, const ChangeResult &insertionResult, const ChangeResult &removalResult);
+ virtual void updateSectionCriteria();
virtual void updateSections();
QQuickItem *getSectionItem(const QString §ion);
void releaseSectionItem(QQuickItem *item);
if (property != m_property) {
m_property = property;
emit propertyChanged();
- m_view->updateSections();
+ // notify view that the contents of the sections must be recalculated
+ m_view->updateSectionCriteria();
}
}
if (criteria != m_criteria) {
m_criteria = criteria;
emit criteriaChanged();
- m_view->updateSections();
+ // notify view that the contents of the sections must be recalculated
+ m_view->updateSectionCriteria();
}
}
m_view->releaseSectionItems();
m_delegate = delegate;
emit delegateChanged();
- m_view->updateSections();
+ m_view->forceLayoutPolish();
}
}
if (m_labelPositioning != l) {
m_labelPositioning = l;
emit labelPositioningChanged();
- m_view->updateSections();
+ m_view->forceLayoutPolish();
}
}
// move current item if it is not a visible item.
if (currentIndex >= 0 && currentItem && !fixedCurrent)
static_cast<FxListItemSG*>(currentItem)->setPosition(positionAt(currentIndex));
+
+ updateCurrentSection();
+ updateStickySections();
}
}
}
lastVisibleSection = QString();
- updateCurrentSection();
- updateStickySections();
- forceLayout = true;
- q->polish();
}
void QQuickListViewPrivate::updateCurrentSection()
listItem->setPosition(listItem->position() + diff, true);
}
}
- forceLayout = true;
- q->polish();
+ forceLayoutPolish();
}
}
}
Q_D(QQuickListView);
if (spacing != d->spacing) {
d->spacing = spacing;
- d->forceLayout = true;
- polish();
+ d->forceLayoutPolish();
emit spacingChanged();
}
}
QQuickViewSection *QQuickListView::sectionCriteria()
{
Q_D(QQuickListView);
- if (!d->sectionCriteria) {
+ if (!d->sectionCriteria)
d->sectionCriteria = new QQuickViewSection(this);
- connect(d->sectionCriteria, SIGNAL(propertyChanged()), this, SLOT(updateSections()));
- }
return d->sectionCriteria;
}
}
}
-void QQuickListView::updateSections()
+void QQuickListViewPrivate::updateSectionCriteria()
{
- Q_D(QQuickListView);
- if (isComponentComplete() && d->model) {
+ Q_Q(QQuickListView);
+ if (q->isComponentComplete() && model) {
QList<QByteArray> roles;
- if (d->sectionCriteria && !d->sectionCriteria->property().isEmpty())
- roles << d->sectionCriteria->property().toUtf8();
- d->model->setWatchedRoles(roles);
- d->updateSections();
- if (d->itemCount) {
- d->forceLayout = true;
- polish();
- }
+ if (sectionCriteria && !sectionCriteria->property().isEmpty())
+ roles << sectionCriteria->property().toUtf8();
+ model->setWatchedRoles(roles);
+ updateSections();
+ if (itemCount)
+ forceLayoutPolish();
}
}
void setLabelPositioning(int pos);
Q_SIGNALS:
+ void sectionsChanged();
void propertyChanged();
void criteriaChanged();
void delegateChanged();
virtual void keyPressEvent(QKeyEvent *);
virtual void geometryChanged(const QRectF &newGeometry,const QRectF &oldGeometry);
virtual void initItem(int index, QQuickItem *item);
-
-protected Q_SLOTS:
- void updateSections();
};
class QQuickListViewAttached : public QQuickItemViewAttached
QTRY_VERIFY(bottomItem = findVisibleChild(contentItem, "sect_new")); // section footer
QTRY_COMPARE(bottomItem->y(), 300.);
+ // delegate size increase should push section footer down
+ listview->setContentY(70);
+ QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false);
+ QTRY_VERIFY(bottomItem = findVisibleChild(contentItem, "sect_3")); // section footer
+ QTRY_COMPARE(bottomItem->y(), 370.);
+ QQuickItem *inlineSection = findVisibleChild(contentItem, "sect_new");
+ item = findItem<QQuickItem>(contentItem, "wrapper", 13);
+ QVERIFY(item);
+ item->setHeight(40.);
+ QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false);
+ QTRY_COMPARE(bottomItem->y(), 380.);
+ QCOMPARE(inlineSection->y(), 360.);
+ item->setHeight(20.);
+
// Turn sticky footer off
listview->setContentY(20);
- QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false);
canvas->rootObject()->setProperty("sectionPositioning", QVariant(int(QQuickViewSection::InlineLabels | QQuickViewSection::CurrentLabelAtStart)));
+ QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false);
QTRY_VERIFY(item = findVisibleChild(contentItem, "sect_new")); // inline label restored
QCOMPARE(item->y(), 340.);
// Turn sticky header off
listview->setContentY(30);
- QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false);
canvas->rootObject()->setProperty("sectionPositioning", QVariant(int(QQuickViewSection::InlineLabels)));
+ QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false);
QTRY_VERIFY(item = findVisibleChild(contentItem, "sect_aaa")); // inline label restored
QCOMPARE(item->y(), 0.);