From: Peter Penz Date: Sun, 30 Oct 2011 09:19:29 +0000 (+0100) Subject: Fix layout issue for groups X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/a803819afddfd16f63e82f66ac46d5b54f508bd4?ds=inline Fix layout issue for groups When enabling a group where the sort-role is retrieved asynchronously (e.g. group by "type") the group-headers have stayed invisible. --- diff --git a/src/kitemviews/kfileitemmodel.cpp b/src/kitemviews/kfileitemmodel.cpp index 60f1c72ce..523fb619d 100644 --- a/src/kitemviews/kfileitemmodel.cpp +++ b/src/kitemviews/kfileitemmodel.cpp @@ -119,6 +119,9 @@ bool KFileItemModel::setData(int index, const QHash& value } if (!changedRoles.isEmpty()) { + if (groupedSorting() && changedRoles.contains(sortRole())) { + m_groups.clear(); + } m_data[index] = currentValue; emit itemsChanged(KItemRangeList() << KItemRange(index, 1), changedRoles); } diff --git a/src/kitemviews/kitemlistview.cpp b/src/kitemviews/kitemlistview.cpp index 24fb62aef..b11fe905d 100644 --- a/src/kitemviews/kitemlistview.cpp +++ b/src/kitemviews/kitemlistview.cpp @@ -126,7 +126,7 @@ void KItemListView::setScrollOrientation(Qt::Orientation orientation) } } - updateLayout(); + doLayout(Animation, 0, 0); onScrollOrientationChanged(orientation, previousOrientation); emit scrollOrientationChanged(orientation, previousOrientation); @@ -158,7 +158,7 @@ void KItemListView::setItemSize(const QSizeF& itemSize) } m_sizeHintResolver->clearCache(); - updateLayout(); + doLayout(Animation, 0, 0); onItemSizeChanged(itemSize, previousSize); } @@ -182,7 +182,6 @@ void KItemListView::setScrollOffset(qreal offset) m_animation->setScrollOffset(offset); if (!m_layoutTimer->isActive()) { doLayout(NoAnimation, 0, 0); - update(); } onScrollOffsetChanged(offset, previousOffset); } @@ -205,7 +204,6 @@ void KItemListView::setItemOffset(qreal offset) } if (!m_layoutTimer->isActive()) { doLayout(NoAnimation, 0, 0); - update(); } } @@ -242,7 +240,7 @@ void KItemListView::setVisibleRoles(const QList& roles) } updateVisibleRolesSizes(); - updateLayout(); + doLayout(Animation, 0, 0); onVisibleRolesChanged(roles, previousRoles); } @@ -313,7 +311,7 @@ void KItemListView::setStyleOption(const KItemListStyleOption& option) } m_sizeHintResolver->clearCache(); - updateLayout(); + doLayout(Animation, 0, 0); onStyleOptionChanged(option, previousOption); } @@ -432,7 +430,7 @@ void KItemListView::endTransaction() if (m_activeTransactions == 0) { onTransactionEnd(); - updateLayout(); + doLayout(Animation, 0, 0); } } @@ -836,6 +834,7 @@ void KItemListView::slotItemsChanged(const KItemRangeList& itemRanges, if (updateSizeHints) { m_sizeHintResolver->itemsChanged(index, count, roles); m_layouter->markAsDirty(); + if (!m_layoutTimer->isActive()) { m_layoutTimer->start(); } @@ -850,12 +849,22 @@ void KItemListView::slotItemsChanged(const KItemRangeList& itemRanges, } } + if (m_grouped && roles.contains(m_model->sortRole())) { + // The sort-role has been changed which might result + // in modified group headers + updateVisibleGroupHeaders(); + doLayout(NoAnimation, 0, 0); + if (!m_layoutTimer->isActive()) { + m_layoutTimer->start(); + } + } } } void KItemListView::slotGroupedSortingChanged(bool current) { m_grouped = current; + m_layouter->markAsDirty(); if (m_grouped) { // Apply the height of the header to the layouter @@ -863,10 +872,8 @@ void KItemListView::slotGroupedSortingChanged(bool current) m_styleOption.margin * 2; m_layouter->setGroupHeaderHeight(groupHeaderHeight); - updateVisibleGroupHeaders(); // Triggers updateLayout() + updateVisibleGroupHeaders(); } else { - m_layouter->markAsDirty(); - // Clear all visible headers QMutableHashIterator it (m_visibleGroups); while (it.hasNext()) { @@ -874,9 +881,9 @@ void KItemListView::slotGroupedSortingChanged(bool current) recycleGroupHeaderForWidget(it.key()); } Q_ASSERT(m_visibleGroups.isEmpty()); - - updateLayout(); } + + doLayout(Animation, 0, 0); } void KItemListView::slotSortOrderChanged(Qt::SortOrder current, Qt::SortOrder previous) @@ -885,6 +892,7 @@ void KItemListView::slotSortOrderChanged(Qt::SortOrder current, Qt::SortOrder pr Q_UNUSED(previous); if (m_grouped) { updateVisibleGroupHeaders(); + doLayout(Animation, 0, 0); } } @@ -894,6 +902,7 @@ void KItemListView::slotSortRoleChanged(const QByteArray& current, const QByteAr Q_UNUSED(previous); if (m_grouped) { updateVisibleGroupHeaders(); + doLayout(Animation, 0, 0); } } @@ -1049,7 +1058,7 @@ void KItemListView::slotVisibleRoleWidthChanged(const QByteArray& role, widget->setVisibleRolesSizes(m_stretchedVisibleRolesSizes); } - updateLayout(); + doLayout(Animation, 0, 0); } } @@ -1186,12 +1195,6 @@ KItemListRubberBand* KItemListView::rubberBand() const return m_rubberBand; } -void KItemListView::updateLayout() -{ - doLayout(Animation, 0, 0); - update(); -} - void KItemListView::doLayout(LayoutAnimationHint hint, int changedIndex, int changedCount) { if (m_layoutTimer->isActive()) { @@ -1561,8 +1564,6 @@ void KItemListView::updateVisibleGroupHeaders() it.next(); updateGroupHeaderForWidget(it.value()); } - - updateLayout(); } QHash KItemListView::headerRolesWidths() const diff --git a/src/kitemviews/kitemlistview.h b/src/kitemviews/kitemlistview.h index 397ecedf5..ff908000a 100644 --- a/src/kitemviews/kitemlistview.h +++ b/src/kitemviews/kitemlistview.h @@ -301,7 +301,6 @@ private: KItemListRubberBand* rubberBand() const; - void updateLayout(); void doLayout(LayoutAnimationHint hint, int changedIndex, int changedCount); void doGroupHeadersLayout(LayoutAnimationHint hint, int changedIndex, int changedCount); void emitOffsetChanges();