]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Do not sort twice when changing role and order at the same time
authorThomas Surrel <thomas.surrel@protonmail.com>
Thu, 22 Nov 2018 21:24:37 +0000 (22:24 +0100)
committerThomas Surrel <thomas.surrel@protonmail.com>
Sat, 1 Dec 2018 20:07:29 +0000 (21:07 +0100)
Summary:
When using the list header to change the role and order, if one
changes the order to descending and then changes role, dolphin
also changes the order back to ascending. This results in sorting
the list of files twice in a row. This patch removes the first
(useless) sort.

Reviewers: #dolphin, elvisangelaccio

Reviewed By: #dolphin, elvisangelaccio

Subscribers: elvisangelaccio, kfm-devel

Tags: #dolphin

Differential Revision: https://phabricator.kde.org/D17111

src/kitemviews/kfileitemmodel.cpp
src/kitemviews/kfileitemmodel.h
src/kitemviews/kitemmodelbase.cpp
src/kitemviews/kitemmodelbase.h
src/kitemviews/private/kitemlistheaderwidget.cpp

index e67255c0a48d7d504ff81a3a45862a90e3d10b72..7c7abe9a7221758df4b6de41b7ca29f45147ad12 100644 (file)
@@ -789,7 +789,7 @@ void KFileItemModel::onGroupedSortingChanged(bool current)
     m_groups.clear();
 }
 
-void KFileItemModel::onSortRoleChanged(const QByteArray& current, const QByteArray& previous)
+void KFileItemModel::onSortRoleChanged(const QByteArray& current, const QByteArray& previous, bool resortItems)
 {
     Q_UNUSED(previous);
     m_sortRole = typeForRole(current);
@@ -800,7 +800,9 @@ void KFileItemModel::onSortRoleChanged(const QByteArray& current, const QByteArr
         setRoles(newRoles);
     }
 
-    resortAllItems();
+    if (resortItems) {
+        resortAllItems();
+    }
 }
 
 void KFileItemModel::onSortOrderChanged(Qt::SortOrder current, Qt::SortOrder previous)
index a931a28cc35d5b07954f72931d7fb50e93e42767..3266a49f9246c92bf87201f7421654d715eb41a9 100644 (file)
@@ -260,7 +260,7 @@ signals:
 
 protected:
     void onGroupedSortingChanged(bool current) override;
-    void onSortRoleChanged(const QByteArray& current, const QByteArray& previous) override;
+    void onSortRoleChanged(const QByteArray& current, const QByteArray& previous, bool resortItems = true) override;
     void onSortOrderChanged(Qt::SortOrder current, Qt::SortOrder previous) override;
 
 private slots:
index 47db1f86d1d4286d719a09f0704c15666c311cbd..7f7877555d46a5a13d52bcacb666276f95b41bae 100644 (file)
@@ -63,12 +63,12 @@ bool KItemModelBase::groupedSorting() const
     return m_groupedSorting;
 }
 
-void KItemModelBase::setSortRole(const QByteArray& role)
+void KItemModelBase::setSortRole(const QByteArray& role, bool resortItems)
 {
     if (role != m_sortRole) {
         const QByteArray previous = m_sortRole;
         m_sortRole = role;
-        onSortRoleChanged(role, previous);
+        onSortRoleChanged(role, previous, resortItems);
         emit sortRoleChanged(role, previous);
     }
 }
@@ -152,10 +152,11 @@ void KItemModelBase::onGroupedSortingChanged(bool current)
     Q_UNUSED(current);
 }
 
-void KItemModelBase::onSortRoleChanged(const QByteArray& current, const QByteArray& previous)
+void KItemModelBase::onSortRoleChanged(const QByteArray& current, const QByteArray& previous, bool resortItems)
 {
     Q_UNUSED(current);
     Q_UNUSED(previous);
+    Q_UNUSED(resortItems);
 }
 
 void KItemModelBase::onSortOrderChanged(Qt::SortOrder current, Qt::SortOrder previous)
index 257872f9ca91f1058299030e9116f0c683ab9e45..f1945de06c1df6cf47ee5eee47be80e6d5a95cc2 100644 (file)
@@ -85,8 +85,9 @@ public:
      * Sets the sort-role to \a role. The method KItemModelBase::onSortRoleChanged() will be
      * called so that model-implementations can react on the sort-role change. Afterwards the
      * signal sortRoleChanged() will be emitted.
+     * The implementation should resort only if \a resortItems is true.
      */
-    void setSortRole(const QByteArray& role);
+    void setSortRole(const QByteArray& role, bool resortItems = true);
     QByteArray sortRole() const;
 
     /**
@@ -266,8 +267,9 @@ protected:
      * Usually the most efficient way is to emit a
      * itemsRemoved() signal for all items, reorder the items internally and to emit a
      * itemsInserted() signal afterwards.
+     * The implementation should resort only if \a resortItems is true.
      */
-    virtual void onSortRoleChanged(const QByteArray& current, const QByteArray& previous);
+    virtual void onSortRoleChanged(const QByteArray& current, const QByteArray& previous, bool resortItems = true);
 
     /**
      * Is invoked if the sort order has been changed by KItemModelBase::setSortOrder(). Allows
index a994f69c8358267885a897929b9bca7605e4466e..a3f3f521fa4063beb9504a5fbd06893889e72d69 100644 (file)
@@ -220,10 +220,11 @@ void KItemListHeaderWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent* event)
             // Change the sort role and reset to the ascending order
             const QByteArray previous = m_model->sortRole();
             const QByteArray current = m_columns[m_pressedRoleIndex];
-            m_model->setSortRole(current);
+            const bool resetSortOrder = m_model->sortOrder() == Qt::DescendingOrder;
+            m_model->setSortRole(current, !resetSortOrder);
             emit sortRoleChanged(current, previous);
 
-            if (m_model->sortOrder() == Qt::DescendingOrder) {
+            if (resetSortOrder) {
                 m_model->setSortOrder(Qt::AscendingOrder);
                 emit sortOrderChanged(Qt::AscendingOrder, Qt::DescendingOrder);
             }