mirror of
https://invent.kde.org/system/dolphin
synced 2024-09-12 12:54:29 +00:00
Make KFileItemModel::createMimeData() faster
Moreover, this commit ensures that the order of the URLs in the
QMimeData object is the same as the order of the items in the view.
Selecting many items and copying them to the clipboard could take quite
a bit of time. This is because we used
KDirModel::simplifiedUrlList(urls) to remove child items from the list
of URLs, and this function sorts the URLs internally to make it easier
to find out which of them are child URLs.
However, since commit 5c5d87fec4
, the
selected indices are already stored in ascending order, and this makes
it easy to detect if an item is a child of the last item that has been
added to the QMimeData.
BUG: 283409
REVIEW: 113515
FIXED-IN: 4.13.0
This commit is contained in:
parent
92cb6b3a18
commit
6e36733058
|
@ -21,7 +21,6 @@
|
|||
|
||||
#include "kfileitemmodel.h"
|
||||
|
||||
#include <KDirModel>
|
||||
#include <KGlobalSettings>
|
||||
#include <KLocale>
|
||||
#include <KStringHandler>
|
||||
|
@ -247,9 +246,23 @@ QMimeData* KFileItemModel::createMimeData(const KItemSet& indexes) const
|
|||
KUrl::List urls;
|
||||
KUrl::List mostLocalUrls;
|
||||
bool canUseMostLocalUrls = true;
|
||||
const ItemData* lastAddedItem = 0;
|
||||
|
||||
foreach (int index, indexes) {
|
||||
const KFileItem item = fileItem(index);
|
||||
const ItemData* itemData = m_itemData.at(index);
|
||||
const ItemData* parent = itemData->parent;
|
||||
|
||||
while (parent && parent != lastAddedItem) {
|
||||
itemData = itemData->parent;
|
||||
}
|
||||
|
||||
if (parent && parent == lastAddedItem) {
|
||||
// A parent of 'itemData' has been added already.
|
||||
continue;
|
||||
}
|
||||
|
||||
lastAddedItem = itemData;
|
||||
const KFileItem& item = itemData->item;
|
||||
if (!item.isNull()) {
|
||||
urls << item.targetUrl();
|
||||
|
||||
|
@ -262,9 +275,7 @@ QMimeData* KFileItemModel::createMimeData(const KItemSet& indexes) const
|
|||
}
|
||||
|
||||
const bool different = canUseMostLocalUrls && mostLocalUrls != urls;
|
||||
urls = KDirModel::simplifiedUrlList(urls); // TODO: Check if we still need KDirModel for this in KDE 5.0
|
||||
if (different) {
|
||||
mostLocalUrls = KDirModel::simplifiedUrlList(mostLocalUrls);
|
||||
urls.populateMimeData(mostLocalUrls, data);
|
||||
} else {
|
||||
urls.populateMimeData(data);
|
||||
|
|
Loading…
Reference in a new issue