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/views/dolphinview.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/views/dolphinview.cpp')
| -rw-r--r-- | src/views/dolphinview.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp index 6882df5d3..e14227198 100644 --- a/src/views/dolphinview.cpp +++ b/src/views/dolphinview.cpp @@ -549,6 +549,33 @@ QByteArray DolphinView::sortRole() const return model->sortRole(); } +void DolphinView::setGroupRole(const QByteArray &role) +{ + KItemModelBase *model = m_container->controller()->model(); + if (role == model->rawGroupRole()) { + return; + } + + ViewProperties props(viewPropertiesUrl()); + props.setGroupRole(role); + + model->setGroupRole(role); + + Q_EMIT groupRoleChanged(role); +} + +QByteArray DolphinView::groupRole() const +{ + const KItemModelBase *model = m_container->controller()->model(); + return model->groupRole(); +} + +QByteArray DolphinView::rawGroupRole() const +{ + const KItemModelBase *model = m_container->controller()->model(); + return model->rawGroupRole(); +} + void DolphinView::setSortOrder(Qt::SortOrder order) { if (sortOrder() != order) { @@ -2405,6 +2432,12 @@ void DolphinView::applyViewProperties(const ViewProperties &props) Q_EMIT sortRoleChanged(sortRole); } + const QByteArray groupRole = props.groupRole(); + if (groupRole != m_model->rawGroupRole()) { + m_model->setGroupRole(groupRole); + Q_EMIT groupRoleChanged(groupRole); + } + const Qt::SortOrder sortOrder = props.sortOrder(); if (sortOrder != m_model->sortOrder()) { m_model->setSortOrder(sortOrder); |
