Merge remote-tracking branch 'origin/KDE/4.10'

Conflicts:
	dolphin/src/kitemviews/kfileitemmodel.cpp
This commit is contained in:
Frank Reininghaus 2013-03-10 18:31:23 +01:00
commit 0d3225e389
2 changed files with 74 additions and 0 deletions

View file

@ -437,6 +437,30 @@ 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);
}
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;
}
}
removeItems(itemsToRemove, DeleteItemData);
}

View file

@ -79,6 +79,7 @@ private slots:
void testNameFilter();
void testEmptyPath();
void testRemoveHiddenItems();
void collapseParentOfHiddenItems();
void removeParentOfHiddenItems();
private:
@ -904,6 +905,55 @@ void KFileItemModelTest::testRemoveHiddenItems()
m_model->setShowHiddenFiles(false);
}
/**
* 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.
*/