diff options
| author | Frank Reininghaus <[email protected]> | 2013-12-14 11:51:07 +0100 |
|---|---|---|
| committer | Frank Reininghaus <[email protected]> | 2013-12-14 11:51:07 +0100 |
| commit | 8210d5e472a2bff9f1a1f16b0740df25822b5362 (patch) | |
| tree | 30cb7478f6e88a36e03c70faadcb7e77d3f181db /src/kitemviews/kfileitemmodel.cpp | |
| parent | f3537f5b5fb0fd107a2e299aaeca3524cf1dd792 (diff) | |
Update the roles for filtered items if necessary
Since Dolphin 4.11, we store not only KFileItems, but also the
corresponding ItemData struct for filtered items. This is required for
keeping track of the parent-child relationships, and has the nice side
effect that the ItemData need not be re-determined when the items are
shown again.
However, this can become a problem if the visible roles or the sort role
change while some items are filtered.
This is fixed by is fixed by clearing the QHash "values" for the
filtered items if the visible roles change. The hash will be
re-populated with all requested data as soon as the items are shown
again and the data(int) method of the model is called.
Moreover, before the items are inserted into the model after filtering,
we have to make sure that the sort role "Permissions"/"User"/etc. is
present in the hash "values". This is achieved by factoring out the code
that currently does this job for new items in createItemDataList() into
a new function, and calling this in insertItems(), because the same
treatment is required for the previously filtered files.
BUG: 328791
FIXED-IN: 4.12.1
REVIEW: 114266
Diffstat (limited to 'src/kitemviews/kfileitemmodel.cpp')
| -rw-r--r-- | src/kitemviews/kfileitemmodel.cpp | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/src/kitemviews/kfileitemmodel.cpp b/src/kitemviews/kfileitemmodel.cpp index 4c8577543..739384bf9 100644 --- a/src/kitemviews/kfileitemmodel.cpp +++ b/src/kitemviews/kfileitemmodel.cpp @@ -413,6 +413,15 @@ void KFileItemModel::setRoles(const QSet<QByteArray>& roles) kWarning() << "TODO: Emitting itemsChanged() with no information what has changed!"; emit itemsChanged(KItemRangeList() << KItemRange(0, count()), QSet<QByteArray>()); } + + // Clear the 'values' of all filtered items. They will be re-populated with the + // correct roles the next time 'values' will be accessed via data(int). + QHash<KFileItem, ItemData*>::iterator filteredIt = m_filteredItems.begin(); + const QHash<KFileItem, ItemData*>::iterator filteredEnd = m_filteredItems.end(); + while (filteredIt != filteredEnd) { + (*filteredIt)->values.clear(); + ++filteredIt; + } } QSet<QByteArray> KFileItemModel::roles() const @@ -1033,6 +1042,7 @@ void KFileItemModel::insertItems(QList<ItemData*>& newItems) #endif m_groups.clear(); + prepareItemsForSorting(newItems); if (m_sortRole == NameRole && m_naturalSorting) { // Natural sorting of items can be very slow. However, it becomes much @@ -1196,6 +1206,11 @@ QList<KFileItemModel::ItemData*> KFileItemModel::createItemDataList(const KUrl& itemDataList.append(itemData); } + return itemDataList; +} + +void KFileItemModel::prepareItemsForSorting(QList<ItemData*>& itemDataList) +{ switch (m_sortRole) { case PermissionsRole: case OwnerRole: @@ -1205,16 +1220,20 @@ QList<KFileItemModel::ItemData*> KFileItemModel::createItemDataList(const KUrl& // These roles can be determined with retrieveData, and they have to be stored // in the QHash "values" for the sorting. foreach (ItemData* itemData, itemDataList) { - itemData->values = retrieveData(itemData->item, parentItem); + if (itemData->values.isEmpty()) { + itemData->values = retrieveData(itemData->item, itemData->parent); + } } break; case TypeRole: // At least store the data including the file type for items with known MIME type. foreach (ItemData* itemData, itemDataList) { - const KFileItem item = itemData->item; - if (item.isDir() || item.isMimeTypeKnown()) { - itemData->values = retrieveData(itemData->item, parentItem); + if (itemData->values.isEmpty()) { + const KFileItem item = itemData->item; + if (item.isDir() || item.isMimeTypeKnown()) { + itemData->values = retrieveData(itemData->item, itemData->parent); + } } } break; @@ -1223,12 +1242,10 @@ QList<KFileItemModel::ItemData*> KFileItemModel::createItemDataList(const KUrl& // The other roles are either resolved by KFileItemModelRolesUpdater // (this includes the SizeRole for directories), or they do not need // to be stored in the QHash "values" for sorting because the data can - // be retrieved directly from the KFileItem (NameRole, SiezRole for files, + // be retrieved directly from the KFileItem (NameRole, SizeRole for files, // DateRole). break; } - - return itemDataList; } int KFileItemModel::expandedParentsCount(const ItemData* data) |
