Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit b714604a authored by Thomas Surrel's avatar Thomas Surrel

Do not sort twice when changing role and order at the same time

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
parent d0cfe1e6
......@@ -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)
......
......@@ -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:
......
......@@ -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)
......
......@@ -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
......
......@@ -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);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment