mirror of
https://invent.kde.org/system/dolphin
synced 2024-10-05 16:19:10 +00:00
Fix place item edit after creation
Summary: Make sure that the place can be edited after the creation. Depends on D9333 BUG: 389147 Test Plan: Create an item in dolphin places panel, make sure that you can rename it Reviewers: #dolphin, ngraham Reviewed By: ngraham Subscribers: michaelh, elvisangelaccio, lbeltrame, ngraham, #dolphin Differential Revision: https://phabricator.kde.org/D9985
This commit is contained in:
parent
3bf68fd714
commit
a8a3fa51a0
|
@ -129,12 +129,15 @@ Solid::Device PlacesItem::device() const
|
||||||
|
|
||||||
void PlacesItem::setBookmark(const KBookmark& bookmark)
|
void PlacesItem::setBookmark(const KBookmark& bookmark)
|
||||||
{
|
{
|
||||||
if (bookmark == m_bookmark) {
|
const bool bookmarkDataChanged = !(bookmark == m_bookmark);
|
||||||
|
|
||||||
|
// bookmark object must be updated to keep in sync with source model
|
||||||
|
m_bookmark = bookmark;
|
||||||
|
|
||||||
|
if (!bookmarkDataChanged) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_bookmark = bookmark;
|
|
||||||
|
|
||||||
delete m_access;
|
delete m_access;
|
||||||
delete m_volume;
|
delete m_volume;
|
||||||
delete m_disc;
|
delete m_disc;
|
||||||
|
|
|
@ -410,7 +410,10 @@ void PlacesItemModel::addItemFromSourceModel(const QModelIndex &index)
|
||||||
|
|
||||||
const KBookmark bookmark = m_sourceModel->bookmarkForIndex(index);
|
const KBookmark bookmark = m_sourceModel->bookmarkForIndex(index);
|
||||||
Q_ASSERT(!bookmark.isNull());
|
Q_ASSERT(!bookmark.isNull());
|
||||||
PlacesItem *item = new PlacesItem(bookmark);
|
PlacesItem *item = itemFromBookmark(bookmark);
|
||||||
|
if (!item) {
|
||||||
|
item = new PlacesItem(bookmark);
|
||||||
|
}
|
||||||
updateItem(item, index);
|
updateItem(item, index);
|
||||||
insertSortedItem(item);
|
insertSortedItem(item);
|
||||||
|
|
||||||
|
@ -602,6 +605,8 @@ void PlacesItemModel::onSourceModelDataChanged(const QModelIndex &topLeft, const
|
||||||
placeItem->setUrl(m_sourceModel->url(sourceIndex));
|
placeItem->setUrl(m_sourceModel->url(sourceIndex));
|
||||||
placeItem->bookmark().setMetaDataItem(QStringLiteral("OnlyInApp"),
|
placeItem->bookmark().setMetaDataItem(QStringLiteral("OnlyInApp"),
|
||||||
bookmark.metaDataItem(QStringLiteral("OnlyInApp")));
|
bookmark.metaDataItem(QStringLiteral("OnlyInApp")));
|
||||||
|
// must update the bookmark object
|
||||||
|
placeItem->setBookmark(bookmark);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -641,7 +646,6 @@ void PlacesItemModel::loadBookmarks()
|
||||||
{
|
{
|
||||||
for(int r = 0, rMax = m_sourceModel->rowCount(); r < rMax; r++) {
|
for(int r = 0, rMax = m_sourceModel->rowCount(); r < rMax; r++) {
|
||||||
const QModelIndex sourceIndex = m_sourceModel->index(r, 0);
|
const QModelIndex sourceIndex = m_sourceModel->index(r, 0);
|
||||||
KBookmark bookmark = m_sourceModel->bookmarkForIndex(sourceIndex);
|
|
||||||
if (m_hiddenItemsShown || !m_sourceModel->isHidden(sourceIndex)) {
|
if (m_hiddenItemsShown || !m_sourceModel->isHidden(sourceIndex)) {
|
||||||
addItemFromSourceModel(sourceIndex);
|
addItemFromSourceModel(sourceIndex);
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,6 +84,7 @@ private slots:
|
||||||
void testDragAndDrop();
|
void testDragAndDrop();
|
||||||
void testHideDevices();
|
void testHideDevices();
|
||||||
void testDuplicatedEntries();
|
void testDuplicatedEntries();
|
||||||
|
void renameAfterCreation();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PlacesItemModel* m_model;
|
PlacesItemModel* m_model;
|
||||||
|
@ -808,6 +809,42 @@ void PlacesItemModelTest::testDuplicatedEntries()
|
||||||
delete newModel;
|
delete newModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PlacesItemModelTest::renameAfterCreation()
|
||||||
|
{
|
||||||
|
const QUrl tempUrl = QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::TempLocation));
|
||||||
|
QStringList urls = initialUrls();
|
||||||
|
PlacesItemModel *model = new PlacesItemModel();
|
||||||
|
|
||||||
|
CHECK_PLACES_URLS(urls);
|
||||||
|
QTRY_COMPARE(model->count(), m_model->count());
|
||||||
|
|
||||||
|
// create a new place
|
||||||
|
createPlaceItem(QStringLiteral("Temporary Dir"), tempUrl, QString());
|
||||||
|
urls.insert(3, tempUrl.toLocalFile());
|
||||||
|
|
||||||
|
// make sure that the new item will be removed later
|
||||||
|
removePlaceAfter(3);
|
||||||
|
|
||||||
|
CHECK_PLACES_URLS(urls);
|
||||||
|
QCOMPARE(model->count(), m_model->count());
|
||||||
|
|
||||||
|
|
||||||
|
// modify place text
|
||||||
|
QSignalSpy changedSpy(m_model, &PlacesItemModel::itemsChanged);
|
||||||
|
|
||||||
|
PlacesItem *item = m_model->placesItem(3);
|
||||||
|
item->setText(QStringLiteral("New Temporary Dir"));
|
||||||
|
item->setUrl(item->url());
|
||||||
|
item->setIcon(item->icon());
|
||||||
|
m_model->refresh();
|
||||||
|
|
||||||
|
QTRY_COMPARE(changedSpy.count(), 1);
|
||||||
|
|
||||||
|
// check if the place was modified in both models
|
||||||
|
QTRY_COMPARE(m_model->placesItem(3)->text(), QStringLiteral("New Temporary Dir"));
|
||||||
|
QTRY_COMPARE(model->placesItem(3)->text(), QStringLiteral("New Temporary Dir"));
|
||||||
|
}
|
||||||
|
|
||||||
QTEST_MAIN(PlacesItemModelTest)
|
QTEST_MAIN(PlacesItemModelTest)
|
||||||
|
|
||||||
#include "placesitemmodeltest.moc"
|
#include "placesitemmodeltest.moc"
|
||||||
|
|
Loading…
Reference in a new issue