diff --git a/autotests/kfileplacesmodeltest.cpp b/autotests/kfileplacesmodeltest.cpp --- a/autotests/kfileplacesmodeltest.cpp +++ b/autotests/kfileplacesmodeltest.cpp @@ -71,6 +71,7 @@ void testEnableBaloo(); void testRemoteUrls_data(); void testRemoteUrls(); + void testRefresh(); void testConvertedUrl_data(); void testConvertedUrl(); @@ -825,6 +826,24 @@ m_places->removePlace(index); } +void KFilePlacesModelTest::testRefresh() +{ + KBookmarkManager *bookmarkManager = KBookmarkManager::managerForFile(bookmarksFile(), QStringLiteral("kfilePlaces")); + KBookmarkGroup root = bookmarkManager->root(); + KBookmark homePlace = root.first(); + const QModelIndex homePlaceIndex = m_places->index(0, 0); + + QCOMPARE(m_places->text(homePlaceIndex), homePlace.fullText()); + + // modify bookmark + homePlace.setFullText("Test change the text"); + QVERIFY(m_places->text(homePlaceIndex) != homePlace.fullText()); + + // reload bookmark data + m_places->refresh(); + QCOMPARE(m_places->text(homePlaceIndex), homePlace.fullText()); +} + void KFilePlacesModelTest::testConvertedUrl_data() { QTest::addColumn("url"); diff --git a/src/filewidgets/kfileplacesmodel.h b/src/filewidgets/kfileplacesmodel.h --- a/src/filewidgets/kfileplacesmodel.h +++ b/src/filewidgets/kfileplacesmodel.h @@ -131,6 +131,12 @@ bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) Q_DECL_OVERRIDE; + /** + * @brief Reload bookmark information + * @since 5.41 + */ + void refresh() const; + /** * @brief Converts the URL, which contains "virtual" URLs for system-items like * "timeline:/lastmonth" into a Query-URL "timeline:/2017-10" diff --git a/src/filewidgets/kfileplacesmodel.cpp b/src/filewidgets/kfileplacesmodel.cpp --- a/src/filewidgets/kfileplacesmodel.cpp +++ b/src/filewidgets/kfileplacesmodel.cpp @@ -797,11 +797,16 @@ return false; } - d->reloadAndSignal(); + refresh(); return true; } +void KFilePlacesModel::refresh() const +{ + d->reloadAndSignal(); +} + QUrl KFilePlacesModel::convertedUrl(const QUrl &url) { QUrl newUrl = url; @@ -836,7 +841,7 @@ d->bookmarkManager->root().moveBookmark(bookmark, item->bookmark()); } - d->reloadAndSignal(); + refresh(); } void KFilePlacesModel::editPlace(const QModelIndex &index, const QString &text, const QUrl &url, @@ -863,7 +868,7 @@ bookmark.setIcon(iconName); bookmark.setMetaDataItem(QStringLiteral("OnlyInApp"), appName); - d->reloadAndSignal(); + refresh(); emit dataChanged(index, index); } @@ -886,7 +891,7 @@ } d->bookmarkManager->root().deleteBookmark(bookmark); - d->reloadAndSignal(); + refresh(); } void KFilePlacesModel::setPlaceHidden(const QModelIndex &index, bool hidden) @@ -905,7 +910,7 @@ bookmark.setMetaDataItem(QStringLiteral("IsHidden"), (hidden ? QStringLiteral("true") : QStringLiteral("false"))); - d->reloadAndSignal(); + refresh(); emit dataChanged(index, index); }