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);
setRoles(newRoles);
}
- resortAllItems();
+ if (resortItems) {
+ resortAllItems();
+ }
}
void KFileItemModel::onSortOrderChanged(Qt::SortOrder current, Qt::SortOrder previous)
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:
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);
}
}
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)
* 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;
/**
* 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
// 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);
}