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
-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);
{
Q_UNUSED(previous);
m_sortRole = typeForRole(current);
+ if (resortItems) {
+ resortAllItems();
+ }
}
void KFileItemModel::onSortOrderChanged(Qt::SortOrder current, Qt::SortOrder previous)
}
void KFileItemModel::onSortOrderChanged(Qt::SortOrder current, Qt::SortOrder previous)
protected:
void onGroupedSortingChanged(bool current) override;
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:
void onSortOrderChanged(Qt::SortOrder current, Qt::SortOrder previous) override;
private slots:
return m_groupedSorting;
}
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;
{
if (role != m_sortRole) {
const QByteArray previous = m_sortRole;
m_sortRole = role;
- onSortRoleChanged(role, previous);
+ onSortRoleChanged(role, previous, resortItems);
emit sortRoleChanged(role, previous);
}
}
emit sortRoleChanged(role, previous);
}
}
-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(current);
Q_UNUSED(previous);
}
void KItemModelBase::onSortOrderChanged(Qt::SortOrder current, Qt::SortOrder previous)
}
void KItemModelBase::onSortOrderChanged(Qt::SortOrder current, Qt::SortOrder previous)
* 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.
* 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;
/**
QByteArray sortRole() const;
/**
* 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.
* 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
/**
* Is invoked if the sort order has been changed by KItemModelBase::setSortOrder(). Allows
// Change the sort role and reset to the ascending order
const QByteArray previous = m_model->sortRole();
const QByteArray current = m_columns[m_pressedRoleIndex];
// 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);
emit sortRoleChanged(current, previous);
- if (m_model->sortOrder() == Qt::DescendingOrder) {
m_model->setSortOrder(Qt::AscendingOrder);
emit sortOrderChanged(Qt::AscendingOrder, Qt::DescendingOrder);
}
m_model->setSortOrder(Qt::AscendingOrder);
emit sortOrderChanged(Qt::AscendingOrder, Qt::DescendingOrder);
}