diff options
| author | Frank Reininghaus <[email protected]> | 2013-08-15 00:07:43 +0200 |
|---|---|---|
| committer | Frank Reininghaus <[email protected]> | 2013-08-15 00:07:43 +0200 |
| commit | 7c99a9c2ad4455c65a218c53dfa7f6376f389b66 (patch) | |
| tree | 0b2dcaf332ff5f507fc5ad94b41eb6c4e4764620 /src/kitemviews | |
| parent | 59723fca41a44e4d1ee753e93589027cbdf8d20d (diff) | |
Make sure that the sort order is correct after renaming
KFileItemModel::setData() should not only cause a resorting when the
sort role is changed. The name is always used as a fallback if the sort
role of multiple files is equal, therefore, renaming a file can change
the correct order of the files even if the files are not sorted by
"name".
Unit test included.
BUG: 323518
FIXED-IN: 4.11.1
REVIEW: 111721
Diffstat (limited to 'src/kitemviews')
| -rw-r--r-- | src/kitemviews/kfileitemmodel.cpp | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/src/kitemviews/kfileitemmodel.cpp b/src/kitemviews/kfileitemmodel.cpp index c0dedff39..70e8834a6 100644 --- a/src/kitemviews/kfileitemmodel.cpp +++ b/src/kitemviews/kfileitemmodel.cpp @@ -192,8 +192,30 @@ bool KFileItemModel::setData(int index, const QHash<QByteArray, QVariant>& value emit itemsChanged(KItemRangeList() << KItemRange(index, 1), changedRoles); - if (changedRoles.contains(sortRole())) { - m_resortAllItemsTimer->start(); + // Trigger a resorting if the item's correct position has changed. Note + // that this can happen even if the sort role has not changed at all + // because the file name can be used as a fallback. + if (changedRoles.contains(sortRole()) || changedRoles.contains(roleForType(NameRole))) { + // Compare the changed item with its neighbors to see + // if an expensive resorting is needed at all. + const ItemData* changedItem = m_itemData.at(index); + const ItemData* previousItem = (index == 0) ? 0 : m_itemData.at(index - 1); + const ItemData* nextItem = (index == m_itemData.count() - 1) ? 0 : m_itemData.at(index + 1); + + if ((previousItem && lessThan(changedItem, previousItem)) + || (nextItem && lessThan(nextItem, changedItem))) { + m_resortAllItemsTimer->start(); + } else if (groupedSorting() && changedRoles.contains(sortRole())) { + // The position is still correct, but the groups might have changed + // if the changed item is either the first or the last item in a + // group. + // In principle, we could try to find out if the item really is the + // first or last one in its group and then update the groups + // (possibly with a delayed timer to make sure that we don't + // re-calculate the groups very often if items are updated one by + // one), but starting m_resortAllItemsTimer is easier. + m_resortAllItemsTimer->start(); + } } return true; |
