From: Frank Reininghaus Date: Sat, 24 Aug 2013 18:27:30 +0000 (+0200) Subject: Merge remote-tracking branch 'origin/KDE/4.11' X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/ebfcb5e19b345a0fbb2425f537232f45d3b3d62a?hp=-c Merge remote-tracking branch 'origin/KDE/4.11' --- ebfcb5e19b345a0fbb2425f537232f45d3b3d62a diff --combined src/kitemviews/kfileitemmodel.cpp index eb7b16461,7bbc1d17f..37a30519a --- a/src/kitemviews/kfileitemmodel.cpp +++ b/src/kitemviews/kfileitemmodel.cpp @@@ -711,6 -711,7 +711,6 @@@ void KFileItemModel::resortAllItems( oldUrls.append(itemData->item.url()); } - m_groups.clear(); m_items.clear(); // Resort the items @@@ -719,45 -720,20 +719,45 @@@ m_items.insert(m_itemData.at(i)->item.url(), i); } - // Determine the indexes that have been moved - QList movedToIndexes; - movedToIndexes.reserve(itemCount); - for (int i = 0; i < itemCount; i++) { - const int newIndex = m_items.value(oldUrls.at(i)); - movedToIndexes.append(newIndex); + // Determine the first index that has been moved. + int firstMovedIndex = 0; + while (firstMovedIndex < itemCount + && firstMovedIndex == m_items.value(oldUrls.at(firstMovedIndex))) { + ++firstMovedIndex; } - // Don't check whether items have really been moved and always emit a - // itemsMoved() signal after resorting: In case of grouped items - // the groups might change even if the items themselves don't change their - // position. Let the receiver of the signal decide whether a check for moved - // items makes sense. - emit itemsMoved(KItemRange(0, itemCount), movedToIndexes); + const bool itemsHaveMoved = firstMovedIndex < itemCount; + if (itemsHaveMoved) { + m_groups.clear(); + + int lastMovedIndex = itemCount - 1; + while (lastMovedIndex > firstMovedIndex + && lastMovedIndex == m_items.value(oldUrls.at(lastMovedIndex))) { + --lastMovedIndex; + } + + Q_ASSERT(firstMovedIndex <= lastMovedIndex); + + // Create a list movedToIndexes, which has the property that + // movedToIndexes[i] is the new index of the item with the old index + // firstMovedIndex + i. + const int movedItemsCount = lastMovedIndex - firstMovedIndex + 1; + QList movedToIndexes; + movedToIndexes.reserve(movedItemsCount); + for (int i = firstMovedIndex; i <= lastMovedIndex; ++i) { + const int newIndex = m_items.value(oldUrls.at(i)); + movedToIndexes.append(newIndex); + } + + emit itemsMoved(KItemRange(firstMovedIndex, movedItemsCount), movedToIndexes); + } else if (groupedSorting()) { + // The groups might have changed even if the order of the items has not. + const QList > oldGroups = m_groups; + m_groups.clear(); + if (groups() != oldGroups) { + emit groupsChanged(); + } + } #ifdef KFILEITEMMODEL_DEBUG kDebug() << "[TIME] Resorting of" << itemCount << "items:" << timer.elapsed(); @@@ -972,7 -948,7 +972,7 @@@ void KFileItemModel::slotRefreshItems(c emit itemsChanged(itemRangeList, changedRoles); if (changedRoles.contains(sortRole())) { - resortAllItems(); + m_resortAllItemsTimer->start(); } } @@@ -1405,6 -1381,9 +1405,9 @@@ QHash KFileItemMo if (m_requestRole[TypeRole]) { data.insert(sharedValue("type"), item.mimeComment()); } + } else if (m_requestRole[TypeRole] && isDir) { + static const QString folderMimeType = item.mimeComment(); + data.insert(sharedValue("type"), folderMimeType); } return data; @@@ -2011,7 -1990,15 +2014,15 @@@ void KFileItemModel::determineMimeTypes QElapsedTimer timer; timer.start(); foreach (const KFileItem& item, items) { // krazy:exclude=foreach - item.determineMimeType(); + // Only determine mime types for files here. For directories, + // KFileItem::determineMimeType() reads the .directory file inside to + // load the icon, but this is not necessary at all if we just need the + // type. Some special code for setting the correct mime type for + // directories is in retrieveData(). + if (!item.isDir()) { + item.determineMimeType(); + } + if (timer.elapsed() > timeout) { // Don't block the user interface, let the remaining items // be resolved asynchronously.