diff options
| author | Peter Penz <[email protected]> | 2011-10-29 19:50:15 +0200 |
|---|---|---|
| committer | Peter Penz <[email protected]> | 2011-10-29 19:52:05 +0200 |
| commit | d062256db2c0590b7628ad7dcb9e720a5ef4f4a9 (patch) | |
| tree | 1920189854157b987253179064739480a44e68ec /src/kitemviews/kitemlistview.cpp | |
| parent | 74bc3cac2530031c0ec78fc5039342ac0f077eb7 (diff) | |
Fix grouping-issue with not visible sorting roles
It must be assured that the data for a sorting role always is
determined even it is not shown as "additional info" in the view.
Diffstat (limited to 'src/kitemviews/kitemlistview.cpp')
| -rw-r--r-- | src/kitemviews/kitemlistview.cpp | 53 |
1 files changed, 45 insertions, 8 deletions
diff --git a/src/kitemviews/kitemlistview.cpp b/src/kitemviews/kitemlistview.cpp index eff48cf09..24fb62aef 100644 --- a/src/kitemviews/kitemlistview.cpp +++ b/src/kitemviews/kitemlistview.cpp @@ -856,19 +856,17 @@ void KItemListView::slotItemsChanged(const KItemRangeList& itemRanges, void KItemListView::slotGroupedSortingChanged(bool current) { m_grouped = current; + if (m_grouped) { // Apply the height of the header to the layouter const qreal groupHeaderHeight = m_styleOption.fontMetrics.height() + m_styleOption.margin * 2; m_layouter->setGroupHeaderHeight(groupHeaderHeight); - // Assure that headers from already visible items get created - QHashIterator<int, KItemListWidget*> it(m_visibleItems); - while (it.hasNext()) { - it.next(); - updateGroupHeaderForWidget(it.value()); - } + updateVisibleGroupHeaders(); // Triggers updateLayout() } else { + m_layouter->markAsDirty(); + // Clear all visible headers QMutableHashIterator<KItemListWidget*, KItemListGroupHeader*> it (m_visibleGroups); while (it.hasNext()) { @@ -876,10 +874,27 @@ void KItemListView::slotGroupedSortingChanged(bool current) recycleGroupHeaderForWidget(it.key()); } Q_ASSERT(m_visibleGroups.isEmpty()); + + updateLayout(); } +} - m_layouter->markAsDirty(); - updateLayout(); +void KItemListView::slotSortOrderChanged(Qt::SortOrder current, Qt::SortOrder previous) +{ + Q_UNUSED(current); + Q_UNUSED(previous); + if (m_grouped) { + updateVisibleGroupHeaders(); + } +} + +void KItemListView::slotSortRoleChanged(const QByteArray& current, const QByteArray& previous) +{ + Q_UNUSED(current); + Q_UNUSED(previous); + if (m_grouped) { + updateVisibleGroupHeaders(); + } } void KItemListView::slotCurrentChanged(int current, int previous) @@ -1136,6 +1151,10 @@ void KItemListView::setModel(KItemModelBase* model) this, SLOT(slotItemsMoved(KItemRange,QList<int>))); disconnect(m_model, SIGNAL(groupedSortingChanged(bool)), this, SLOT(slotGroupedSortingChanged(bool))); + disconnect(m_model, SIGNAL(sortOrderChanged(Qt::SortOrder,Qt::SortOrder)), + this, SLOT(slotSortOrderChanged(Qt::SortOrder,Qt::SortOrder))); + disconnect(m_model, SIGNAL(sortRoleChanged(QByteArray,QByteArray)), + this, SLOT(slotSortRoleChanged(QByteArray,QByteArray))); } m_model = model; @@ -1153,6 +1172,10 @@ void KItemListView::setModel(KItemModelBase* model) this, SLOT(slotItemsMoved(KItemRange,QList<int>))); connect(m_model, SIGNAL(groupedSortingChanged(bool)), this, SLOT(slotGroupedSortingChanged(bool))); + connect(m_model, SIGNAL(sortOrderChanged(Qt::SortOrder,Qt::SortOrder)), + this, SLOT(slotSortOrderChanged(Qt::SortOrder,Qt::SortOrder))); + connect(m_model, SIGNAL(sortRoleChanged(QByteArray,QByteArray)), + this, SLOT(slotSortRoleChanged(QByteArray,QByteArray))); } onModelChanged(model, previous); @@ -1528,6 +1551,20 @@ void KItemListView::recycleGroupHeaderForWidget(KItemListWidget* widget) } } +void KItemListView::updateVisibleGroupHeaders() +{ + Q_ASSERT(m_grouped); + m_layouter->markAsDirty(); + + QHashIterator<int, KItemListWidget*> it(m_visibleItems); + while (it.hasNext()) { + it.next(); + updateGroupHeaderForWidget(it.value()); + } + + updateLayout(); +} + QHash<QByteArray, qreal> KItemListView::headerRolesWidths() const { QHash<QByteArray, qreal> rolesWidths; |
