Avoid a unnecessary resorting when items are changed, only resort the items when the sorting role value is changed.

BUG: 299565
FIXED-IN: 4.11
REVIEW: 111146
This commit is contained in:
Emmanuel Pescosta 2013-06-20 19:16:22 +02:00
parent 015957c5a2
commit 0c0c86f220

View file

@ -846,12 +846,12 @@ void KFileItemModel::slotRefreshItems(const QList<QPair<KFileItem, KFileItem> >&
kDebug() << "Refreshing" << items.count() << "items";
#endif
m_groups.clear();
// Get the indexes of all items that have been refreshed
QList<int> indexes;
indexes.reserve(items.count());
QSet<QByteArray> changedRoles;
QListIterator<QPair<KFileItem, KFileItem> > it(items);
while (it.hasNext()) {
const QPair<KFileItem, KFileItem>& itemPair = it.next();
@ -864,9 +864,14 @@ void KFileItemModel::slotRefreshItems(const QList<QPair<KFileItem, KFileItem> >&
// Keep old values as long as possible if they could not retrieved synchronously yet.
// The update of the values will be done asynchronously by KFileItemModelRolesUpdater.
QHashIterator<QByteArray, QVariant> it(retrieveData(newItem, m_itemData.at(index)->parent));
QHash<QByteArray, QVariant>& values = m_itemData[index]->values;
while (it.hasNext()) {
it.next();
m_itemData[index]->values.insert(it.key(), it.value());
const QByteArray& role = it.key();
if (values.value(role) != it.value()) {
values.insert(role, it.value());
changedRoles.insert(role);
}
}
m_items.remove(oldItem.url());
@ -907,9 +912,11 @@ void KFileItemModel::slotRefreshItems(const QList<QPair<KFileItem, KFileItem> >&
itemRangeList.append(KItemRange(rangeIndex, rangeCount));
}
emit itemsChanged(itemRangeList, m_roles);
emit itemsChanged(itemRangeList, changedRoles);
resortAllItems();
if (changedRoles.contains(sortRole())) {
resortAllItems();
}
}
void KFileItemModel::slotClear()