diff options
| author | Ramil Nurmanov <[email protected]> | 2026-06-05 00:06:12 +0400 |
|---|---|---|
| committer | Ramil Nurmanov <[email protected]> | 2026-06-11 14:30:18 +0400 |
| commit | 989c0f4f0319f7d8e573c8a88fe8011bd3315466 (patch) | |
| tree | 2cecdf3bed6375269e4d9b6948ebc4c34918988d /src/kitemviews/kitemlistview.cpp | |
| parent | 6eed05fd769b01c37530b8b62cdcd65933ea8d14 (diff) | |
Allow grouping by a separate criterion
Add an explicit group role to Dolphin views so items can be grouped independently from the active sort role.
Previously, Dolphin's grouped view always used the current sort role as the grouping criterion. This meant that grouping and sorting were tied together, for example grouping by type also required sorting by type.
This change adds a separate Group By menu. It replaces the previous Show in Groups toggle and allows the user to disable grouping, keep the old Same as Sort behavior, or explicitly group by a selected criterion.
When an explicit group role is set, the model keeps groups stable and uses the normal sort role as a secondary key inside each group. The roles
updater also receives the active group role, so roles used only for grouping are still updated correctly.
BUG: 416134
CCBUG: 510670
CCBUG: 513235
CCBUG: 46393
Diffstat (limited to 'src/kitemviews/kitemlistview.cpp')
| -rw-r--r-- | src/kitemviews/kitemlistview.cpp | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/kitemviews/kitemlistview.cpp b/src/kitemviews/kitemlistview.cpp index b87216d4b..d24c2426d 100644 --- a/src/kitemviews/kitemlistview.cpp +++ b/src/kitemviews/kitemlistview.cpp @@ -1477,8 +1477,8 @@ void KItemListView::slotItemsChanged(const KItemRangeList &itemRanges, const QSe } } - if (m_grouped && roles.contains(m_model->sortRole())) { - // The sort-role has been changed which might result + if (m_grouped && roles.contains(m_model->groupRole())) { + // The group-role data has been changed which might result // in modified group headers updateVisibleGroupHeaders(); doLayout(NoAnimation); @@ -1543,6 +1543,16 @@ void KItemListView::slotSortRoleChanged(const QByteArray ¤t, const QByteAr } } +void KItemListView::slotGroupRoleChanged(const QByteArray ¤t, const QByteArray &previous) +{ + Q_UNUSED(current) + Q_UNUSED(previous) + if (m_grouped) { + updateVisibleGroupHeaders(); + doLayout(NoAnimation); + } +} + void KItemListView::slotCurrentChanged(int current, int previous) { // In SingleSelection mode (e.g., in the Places Panel), the current item is @@ -1826,6 +1836,7 @@ void KItemListView::setModel(KItemModelBase *model) disconnect(m_model, &KItemModelBase::groupedSortingChanged, this, &KItemListView::slotGroupedSortingChanged); disconnect(m_model, &KItemModelBase::sortOrderChanged, this, &KItemListView::slotSortOrderChanged); disconnect(m_model, &KItemModelBase::sortRoleChanged, this, &KItemListView::slotSortRoleChanged); + disconnect(m_model, &KItemModelBase::groupRoleChanged, this, &KItemListView::slotGroupRoleChanged); m_sizeHintResolver->itemsRemoved(KItemRangeList() << KItemRange(0, m_model->count())); } @@ -1843,6 +1854,7 @@ void KItemListView::setModel(KItemModelBase *model) connect(m_model, &KItemModelBase::groupedSortingChanged, this, &KItemListView::slotGroupedSortingChanged); connect(m_model, &KItemModelBase::sortOrderChanged, this, &KItemListView::slotSortOrderChanged); connect(m_model, &KItemModelBase::sortRoleChanged, this, &KItemListView::slotSortRoleChanged); + connect(m_model, &KItemModelBase::groupRoleChanged, this, &KItemListView::slotGroupRoleChanged); const int itemCount = m_model->count(); if (itemCount > 0) { @@ -2251,7 +2263,7 @@ void KItemListView::updateGroupHeaderForWidget(KItemListWidget *widget) const int groupIndex = groupIndexForItem(index); Q_ASSERT(groupIndex >= 0); groupHeader->setData(groups.at(groupIndex).second); - groupHeader->setRole(model()->sortRole()); + groupHeader->setRole(model()->groupRole()); groupHeader->setStyleOption(m_styleOption); groupHeader->setScrollOrientation(scrollOrientation()); groupHeader->setItemIndex(index); |
