┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/kitemviews
diff options
context:
space:
mode:
authorFrank Reininghaus <[email protected]>2013-03-15 00:23:44 +0100
committerFrank Reininghaus <[email protected]>2013-03-15 00:23:57 +0100
commit90dd8977520bfce23ff6669809db1e9ecb5ec060 (patch)
tree1e5b8af2f3312ea4439a9832ef3ac57d7ba38680 /src/kitemviews
parent2fc248faedf9eb8c593ac29de94ab0cb60bbc753 (diff)
Improve handling of filtered items when folders are deleted/collapsed
If an expanded folder with filtered children is collapsed or removed, and the parent-child relationship cannot be determined by parsing the URLs, this patch makes sure that the filtered children do not reappear when the filter bar is cleared. REVIEW: 109455
Diffstat (limited to 'src/kitemviews')
-rw-r--r--src/kitemviews/kfileitemmodel.cpp130
-rw-r--r--src/kitemviews/kfileitemmodel.h6
2 files changed, 56 insertions, 80 deletions
diff --git a/src/kitemviews/kfileitemmodel.cpp b/src/kitemviews/kfileitemmodel.cpp
index 40cd75094..5d1a1968a 100644
--- a/src/kitemviews/kfileitemmodel.cpp
+++ b/src/kitemviews/kfileitemmodel.cpp
@@ -1,22 +1,23 @@
-/***************************************************************************
- * Copyright (C) 2011 by Peter Penz <[email protected]> *
- * Copyright (C) 2013 by Frank Reininghaus <[email protected]> *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the *
- * Free Software Foundation, Inc., *
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
- ***************************************************************************/
+/*****************************************************************************
+ * Copyright (C) 2011 by Peter Penz <[email protected]> *
+ * Copyright (C) 2013 by Frank Reininghaus <[email protected]> *
+ * Copyright (C) 2013 by Emmanuel Pescosta <[email protected]> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
+ *****************************************************************************/
#include "kfileitemmodel.h"
@@ -421,7 +422,8 @@ bool KFileItemModel::setExpanded(int index, bool expanded)
return false;
}
- const KUrl url = m_itemData.at(index)->item.url();
+ const KFileItem item = m_itemData.at(index)->item;
+ const KUrl url = item.url();
if (expanded) {
m_expandedDirs.insert(url);
m_dirLister->openUrl(url, KDirLister::Keep);
@@ -429,38 +431,10 @@ bool KFileItemModel::setExpanded(int index, bool expanded)
m_expandedDirs.remove(url);
m_dirLister->stop(url);
+ removeFilteredChildren(KFileItemList() << item);
- KFileItemList itemsToRemove;
- const int expandedParentsCount = data(index)["expandedParentsCount"].toInt();
- ++index;
- while (index < count() && data(index)["expandedParentsCount"].toInt() > expandedParentsCount) {
- itemsToRemove.append(m_itemData.at(index)->item);
- ++index;
- }
-
- QSet<KUrl> urlsToRemove;
- urlsToRemove.reserve(itemsToRemove.count() + 1);
- urlsToRemove.insert(url);
- foreach (const KFileItem& item, itemsToRemove) {
- KUrl url = item.url();
- url.adjustPath(KUrl::RemoveTrailingSlash);
- urlsToRemove.insert(url);
- }
-
- QHash<KFileItem, ItemData*>::iterator it = m_filteredItems.begin();
- while (it != m_filteredItems.end()) {
- const KUrl url = it.key().url();
- KUrl parentUrl = url.upUrl();
- parentUrl.adjustPath(KUrl::RemoveTrailingSlash);
-
- if (urlsToRemove.contains(parentUrl)) {
- delete it.value();
- it = m_filteredItems.erase(it);
- } else {
- ++it;
- }
- }
-
+ const KFileItemList itemsToRemove = childItems(item);
+ removeFilteredChildren(itemsToRemove);
removeItems(itemsToRemove, DeleteItemData);
}
@@ -598,6 +572,30 @@ void KFileItemModel::applyFilters()
insertItems(newVisibleItems);
}
+void KFileItemModel::removeFilteredChildren(const KFileItemList& parentsList)
+{
+ if (m_filteredItems.isEmpty()) {
+ return;
+ }
+
+ // First, we put the parent items into a set to provide fast lookup
+ // while iterating over m_filteredItems and prevent quadratic
+ // complexity if there are N parents and N filtered items.
+ const QSet<KFileItem> parents = parentsList.toSet();
+
+ QHash<KFileItem, ItemData*>::iterator it = m_filteredItems.begin();
+ while (it != m_filteredItems.end()) {
+ const ItemData* parent = it.value()->parent;
+
+ if (parent && parents.contains(parent->item)) {
+ delete it.value();
+ it = m_filteredItems.erase(it);
+ } else {
+ ++it;
+ }
+ }
+}
+
QList<KFileItemModel::RoleInfo> KFileItemModel::rolesInformation()
{
static QList<RoleInfo> rolesInfo;
@@ -826,35 +824,7 @@ void KFileItemModel::slotItemsDeleted(const KFileItemList& items)
}
if (m_requestRole[ExpandedParentsCountRole]) {
- // Remove all filtered children of deleted items. First, we put the
- // deleted URLs into a set to provide fast lookup while iterating
- // over m_filteredItems and prevent quadratic complexity if there
- // are N removed items and N filtered items.
- //
- // TODO: This does currently *not* work if the parent-child
- // relationships can not be determined just by using KUrl::upUrl().
- // This is the case, e.g., when browsing smb:/.
- QSet<KUrl> urlsToRemove;
- urlsToRemove.reserve(itemsToRemove.count());
- foreach (const KFileItem& item, itemsToRemove) {
- KUrl url = item.url();
- url.adjustPath(KUrl::RemoveTrailingSlash);
- urlsToRemove.insert(url);
- }
-
- QHash<KFileItem, ItemData*>::iterator it = m_filteredItems.begin();
- while (it != m_filteredItems.end()) {
- const KUrl url = it.key().url();
- KUrl parentUrl = url.upUrl();
- parentUrl.adjustPath(KUrl::RemoveTrailingSlash);
-
- if (urlsToRemove.contains(parentUrl)) {
- delete it.value();
- it = m_filteredItems.erase(it);
- } else {
- ++it;
- }
- }
+ removeFilteredChildren(itemsToRemove);
}
}
diff --git a/src/kitemviews/kfileitemmodel.h b/src/kitemviews/kfileitemmodel.h
index 85a8d0c0d..1d837cb2a 100644
--- a/src/kitemviews/kfileitemmodel.h
+++ b/src/kitemviews/kfileitemmodel.h
@@ -397,6 +397,12 @@ private:
void applyFilters();
/**
+ * Removes filtered items whose expanded parents have been deleted
+ * or collapsed via setExpanded(parentIndex, false).
+ */
+ void removeFilteredChildren(const KFileItemList& parentsList);
+
+ /**
* Maps the QByteArray-roles to RoleTypes and provides translation- and
* group-contexts.
*/