Commit a79c3a39 authored by Frank Reininghaus's avatar Frank Reininghaus

Do not reset the 'isExpanded' state when an expanded folder is refreshed

If an item is moved out of an expanded folder, the model receives the
dir lister's refreshItems signal for the folder. The method
retrieveData() then updates the folder's properties. This commit makes
sure that the 'isExpanded' state is not touched by retrieveData(). A
side-effect is that the 'isExpanded' role is not initialized to 'false',
but this does not matter because trying to read a non-existing role from
the QHash<QByteArray, QVariant> yields a default-constructed QVariant,
which evaluates to 'false'.

BUG: 299675
FIXED-IN: 4.10.4
REVIEW: 110401
parent 56cf52db
......@@ -1333,10 +1333,6 @@ QHash<QByteArray, QVariant> KFileItemModel::retrieveData(const KFileItem& item)
data.insert("path", path);
if (m_requestRole[IsExpandedRole]) {
data.insert("isExpanded", false);
if (m_requestRole[IsExpandableRole]) {
data.insert("isExpandable", item.isDir() && item.url() == item.targetUrl());
......@@ -75,6 +75,7 @@ private slots:
void testIndexForKeyboardSearch();
void testNameFilter();
void testEmptyPath();
void testRefreshExpandedItem();
void testRemoveHiddenItems();
void collapseParentOfHiddenItems();
void removeParentOfHiddenItems();
......@@ -801,6 +802,39 @@ void KFileItemModelTest::testEmptyPath()
* Verifies that the 'isExpanded' state of folders does not change when the
* 'refreshItems' signal is received, see
void KFileItemModelTest::testRefreshExpandedItem()
QSet<QByteArray> modelRoles = m_model->roles();
modelRoles << "isExpanded" << "isExpandable" << "expandedParentsCount";
QStringList files;
files << "a/1" << "a/2" << "3" << "4";
QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout));
QCOMPARE(m_model->count(), 3); // "a/", "3", "4"
m_model->setExpanded(0, true);
QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout));
QCOMPARE(m_model->count(), 5); // "a/", "a/1", "a/2", "3", "4"
QSignalSpy spyItemsChanged(m_model, SIGNAL(itemsChanged(KItemRangeList,QSet<QByteArray>)));
const KFileItem item = m_model->fileItem(0);
m_model->slotRefreshItems(QList<QPair<KFileItem, KFileItem> >() << qMakePair(item, item));
QCOMPARE(m_model->count(), 5); // "a/", "a/1", "a/2", "3", "4"
* Verify that removing hidden files and folders from the model does not
* result in a crash, see
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment