mirror of
https://invent.kde.org/system/dolphin
synced 2024-11-05 18:47:12 +00:00
Update filtered items when the "refreshItems" signal is received
This fixes the problem that the new file name is not shown in the view if an item is renamed while it is filtered. BUG: 329118 FIXED-IN: 4.12.1 REVIEW: 114459
This commit is contained in:
parent
2260d70e21
commit
c0a851893e
2 changed files with 44 additions and 0 deletions
|
@ -967,6 +967,20 @@ void KFileItemModel::slotRefreshItems(const QList<QPair<KFileItem, KFileItem> >&
|
|||
m_items.remove(oldItem.url());
|
||||
m_items.insert(newItem.url(), index);
|
||||
indexes.append(index);
|
||||
} else {
|
||||
// Check if 'oldItem' is one of the filtered items.
|
||||
QHash<KFileItem, ItemData*>::iterator it = m_filteredItems.find(oldItem);
|
||||
if (it != m_filteredItems.end()) {
|
||||
ItemData* itemData = it.value();
|
||||
itemData->item = newItem;
|
||||
|
||||
// The data stored in 'values' might have changed. Therefore, we clear
|
||||
// 'values' and re-populate it the next time it is requested via data(int).
|
||||
itemData->values.clear();
|
||||
|
||||
m_filteredItems.erase(it);
|
||||
m_filteredItems.insert(newItem, itemData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -92,6 +92,7 @@ private slots:
|
|||
void testInconsistentModel();
|
||||
void testChangeRolesForFilteredItems();
|
||||
void testChangeSortRoleWhileFiltering();
|
||||
void testRefreshFilteredItems();
|
||||
|
||||
private:
|
||||
QStringList itemsInModel() const;
|
||||
|
@ -1561,6 +1562,35 @@ void KFileItemModelTest::testChangeSortRoleWhileFiltering()
|
|||
QCOMPARE(itemsInModel(), QStringList() << "c.txt" << "a.txt" << "b.txt");
|
||||
}
|
||||
|
||||
void KFileItemModelTest::testRefreshFilteredItems()
|
||||
{
|
||||
QStringList files;
|
||||
files << "a.txt" << "b.txt" << "c.jpg" << "d.jpg";
|
||||
m_testDir->createFiles(files);
|
||||
|
||||
m_model->loadDirectory(m_testDir->url());
|
||||
QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout));
|
||||
QCOMPARE(itemsInModel(), QStringList() << "a.txt" << "b.txt" << "c.jpg" << "d.jpg");
|
||||
|
||||
const KFileItem fileItemC = m_model->fileItem(2);
|
||||
|
||||
// Show only the .txt files.
|
||||
m_model->setNameFilter(".txt");
|
||||
QCOMPARE(itemsInModel(), QStringList() << "a.txt" << "b.txt");
|
||||
|
||||
// Rename one of the .jpg files.
|
||||
KFileItem fileItemE = fileItemC;
|
||||
KUrl urlE = fileItemE.url();
|
||||
urlE.setFileName("e.jpg");
|
||||
fileItemE.setUrl(urlE);
|
||||
|
||||
m_model->slotRefreshItems(QList<QPair<KFileItem, KFileItem> >() << qMakePair(fileItemC, fileItemE));
|
||||
|
||||
// Show all files again, and verify that the model has updated the file name.
|
||||
m_model->setNameFilter(QString());
|
||||
QCOMPARE(itemsInModel(), QStringList() << "a.txt" << "b.txt" << "d.jpg" << "e.jpg");
|
||||
}
|
||||
|
||||
QStringList KFileItemModelTest::itemsInModel() const
|
||||
{
|
||||
QStringList items;
|
||||
|
|
Loading…
Reference in a new issue