From 5c1e49fa76d3d3b1668c7cf7b705454d3d64faba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20G=C3=A2teau?= Date: Wed, 13 Jun 2012 23:56:13 +0200 Subject: [PATCH] SortFilterModel: Do not sort by default It seems QML sets properties to their default value at startup and thus calls setSortRole(QString()), which causes SortFilterModel to sort by default. CCMAIL: mart@kde.org --- declarativeimports/core/datamodel.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/declarativeimports/core/datamodel.cpp b/declarativeimports/core/datamodel.cpp index 18e60b5b4..9400dbe5b 100644 --- a/declarativeimports/core/datamodel.cpp +++ b/declarativeimports/core/datamodel.cpp @@ -103,9 +103,16 @@ QString SortFilterModel::filterRole() const void SortFilterModel::setSortRole(const QString &role) { - QSortFilterProxyModel::setSortRole(roleNameToId(role)); + if (m_sortRole == role) { + return; + } m_sortRole = role; - sort(0, sortOrder()); + if (role.isEmpty()) { + sort(-1, Qt::AscendingOrder); + } else { + QSortFilterProxyModel::setSortRole(roleNameToId(role)); + sort(0, sortOrder()); + } } QString SortFilterModel::sortRole() const