┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrank Reininghaus <[email protected]>2013-03-10 18:26:20 +0100
committerFrank Reininghaus <[email protected]>2013-03-10 18:26:37 +0100
commit9dd728cb98e0ea822248c641aef5d66f2476768e (patch)
tree896ee073f29037a61923b0473a561c244ad51da3
parent36510e16f790d71fe3cd70f902e86f742dd71639 (diff)
Remove filtered children if the parent folder is collapsed
This is analogous to commit e053ecdcd57cc39fdcbc314fc8dd22c8b9dbdd4f, which fixes the same problem for the case that the parent folder is deleted. BUG: 316335 FIXED-IN: 4.10.2 REVIEW: 109343
-rw-r--r--src/kitemviews/kfileitemmodel.cpp23
-rw-r--r--src/tests/kfileitemmodeltest.cpp50
2 files changed, 73 insertions, 0 deletions
diff --git a/src/kitemviews/kfileitemmodel.cpp b/src/kitemviews/kfileitemmodel.cpp
index d4c08a52e..792724502 100644
--- a/src/kitemviews/kfileitemmodel.cpp
+++ b/src/kitemviews/kfileitemmodel.cpp
@@ -438,6 +438,29 @@ bool KFileItemModel::setExpanded(int index, bool expanded)
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);
+ }
+
+ QSet<KFileItem>::iterator it = m_filteredItems.begin();
+ while (it != m_filteredItems.end()) {
+ const KUrl url = it->url();
+ KUrl parentUrl = url.upUrl();
+ parentUrl.adjustPath(KUrl::RemoveTrailingSlash);
+
+ if (urlsToRemove.contains(parentUrl)) {
+ it = m_filteredItems.erase(it);
+ } else {
+ ++it;
+ }
+ }
+
removeItems(itemsToRemove);
}
diff --git a/src/tests/kfileitemmodeltest.cpp b/src/tests/kfileitemmodeltest.cpp
index b76f4bee9..58e83ac68 100644
--- a/src/tests/kfileitemmodeltest.cpp
+++ b/src/tests/kfileitemmodeltest.cpp
@@ -76,6 +76,7 @@ private slots:
void testNameFilter();
void testEmptyPath();
void testRemoveHiddenItems();
+ void collapseParentOfHiddenItems();
void removeParentOfHiddenItems();
private:
@@ -851,6 +852,55 @@ void KFileItemModelTest::testRemoveHiddenItems()
}
/**
+ * Verify that filtered items are removed when their parent is collapsed.
+ */
+void KFileItemModelTest::collapseParentOfHiddenItems()
+{
+ QSet<QByteArray> modelRoles = m_model->roles();
+ modelRoles << "isExpanded" << "isExpandable" << "expandedParentsCount";
+ m_model->setRoles(modelRoles);
+
+ QStringList files;
+ files << "a/1" << "a/b/1" << "a/b/c/1" << "a/b/c/d/1";
+ m_testDir->createFiles(files);
+
+ m_model->loadDirectory(m_testDir->url());
+ QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout));
+ QCOMPARE(m_model->count(), 1); // Only "a/"
+
+ // Expand "a/".
+ m_model->setExpanded(0, true);
+ QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout));
+ QCOMPARE(m_model->count(), 3); // 3 items: "a/", "a/b/", "a/1"
+
+ // Expand "a/b/".
+ m_model->setExpanded(1, true);
+ QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout));
+ QCOMPARE(m_model->count(), 5); // 5 items: "a/", "a/b/", "a/b/c", "a/b/1", "a/1"
+
+ // Expand "a/b/c/".
+ m_model->setExpanded(2, true);
+ QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout));
+ QCOMPARE(m_model->count(), 7); // 7 items: "a/", "a/b/", "a/b/c", "a/b/c/d/", "a/b/c/1", "a/b/1", "a/1"
+
+ // Set a name filter that matches nothing -> only the expanded folders remain.
+ m_model->setNameFilter("xyz");
+ QCOMPARE(m_model->count(), 3);
+ QCOMPARE(itemsInModel(), QStringList() << "a" << "b" << "c");
+
+ // Collapse the folder "a/".
+ QSignalSpy spyItemsRemoved(m_model, SIGNAL(itemsRemoved(KItemRangeList)));
+ m_model->setExpanded(0, false);
+ QCOMPARE(spyItemsRemoved.count(), 1);
+ QCOMPARE(m_model->count(), 1);
+ QCOMPARE(itemsInModel(), QStringList() << "a");
+
+ // Remove the filter -> no files should appear (and we should not get a crash).
+ m_model->setNameFilter(QString());
+ QCOMPARE(m_model->count(), 1);
+}
+
+/**
* Verify that filtered items are removed when their parent is deleted.
*/
void KFileItemModelTest::removeParentOfHiddenItems()