From ad6ccf2b86b3e97138d13518bd6ea8fd670d3530 Mon Sep 17 00:00:00 2001 From: Nathan Williams Date: Thu, 11 Sep 2025 02:28:16 +0000 Subject: dolphinview: add preferred sort order for roles BUG: 425457 This commit ensures that both the menu and column headers in table view will have the same default sorting (ascending/descending) for each role. It also saves the user's preferences for each role throughout the session. Previously, sorting by "Modified" would always sort by "Oldest First." If the user then changed to "Newest First" and sorted again by "Name," files would be sorted in reverse alphabetical order (Z-A). Now, sorting by "Modified" defaults to "Newest First." If a user switches between multiple roles, the default for each role will be used unless the user changes to a non-default sort order. In that case, the user's preference will be applied. Defaults: **Descending Order:** Time-based roles - modificationtime - creationtime - accesstime - deletiontime - imageDateTime - releaseYear Size/dimension roles - size - width - height - pageCount - wordCount - lineCount Quality/Quantity roles - rating - duration - bitrate - frameRate **Ascending order:** - Text based roles (A-Z) - All other roles --- src/views/dolphinviewactionhandler.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/views/dolphinviewactionhandler.cpp') diff --git a/src/views/dolphinviewactionhandler.cpp b/src/views/dolphinviewactionhandler.cpp index e504fd831..de3facd14 100644 --- a/src/views/dolphinviewactionhandler.cpp +++ b/src/views/dolphinviewactionhandler.cpp @@ -594,6 +594,8 @@ void DolphinViewActionHandler::slotSortOrderChanged(Qt::SortOrder order) const bool sortDescending = (order == Qt::DescendingOrder); descending->setChecked(sortDescending); ascending->setChecked(!sortDescending); + const QByteArray currentRole = m_currentView->sortRole(); + m_currentView->setPreferredSortOrder(currentRole, order); } void DolphinViewActionHandler::slotSortFoldersFirstChanged(bool foldersFirst) @@ -723,13 +725,13 @@ void DolphinViewActionHandler::slotSortRoleChanged(const QByteArray &role) if (role == "text" || role == "type" || role == "extension" || role == "tags" || role == "comment") { descending->setText(i18nc("Sort descending", "Z-A")); ascending->setText(i18nc("Sort ascending", "A-Z")); - } else if (role == "size") { + } else if (role == "size" || role == "width" || role == "height" || role == "pageCount" || role == "wordCount" || role == "lineCount") { descending->setText(i18nc("Sort descending", "Largest First")); ascending->setText(i18nc("Sort ascending", "Smallest First")); - } else if (role == "modificationtime" || role == "creationtime" || role == "accesstime") { + } else if (role == "modificationtime" || role == "creationtime" || role == "accesstime" || role == "imageDateTime" || role == "releaseYear") { descending->setText(i18nc("Sort descending", "Newest First")); ascending->setText(i18nc("Sort ascending", "Oldest First")); - } else if (role == "rating") { + } else if (role == "rating" || role == "bitrate" || role == "frameRate") { descending->setText(i18nc("Sort descending", "Highest First")); ascending->setText(i18nc("Sort ascending", "Lowest First")); } else { -- cgit v1.3