diff --git a/autotests/kfileplacesmodeltest.cpp b/autotests/kfileplacesmodeltest.cpp --- a/autotests/kfileplacesmodeltest.cpp +++ b/autotests/kfileplacesmodeltest.cpp @@ -75,6 +75,7 @@ void testConvertedUrl_data(); void testConvertedUrl(); void testBookmarkObject(); + void testDataChangedSignal(); private: QStringList placesUrls() const; @@ -900,6 +901,34 @@ } } +void KFilePlacesModelTest::testDataChangedSignal() +{ + QSignalSpy dataChangedSpy(m_places, &KFilePlacesModel::dataChanged); + + const QModelIndex index = m_places->index(1, 0); + const KBookmark bookmark = m_places->bookmarkForIndex(index); + + // call function with the same data + m_places->editPlace(index, bookmark.fullText(), bookmark.url(), bookmark.icon(), bookmark.metaDataItem(QStringLiteral("OnlyInApp"))); + QCOMPARE(dataChangedSpy.count(), 0); + + // call function with different data + const QString originalText = bookmark.fullText(); + m_places->editPlace(index, QStringLiteral("My text"), bookmark.url(), bookmark.icon(), bookmark.metaDataItem(QStringLiteral("OnlyInApp"))); + QCOMPARE(dataChangedSpy.count(), 1); + QList args = dataChangedSpy.takeFirst(); + QCOMPARE(args.at(0).toModelIndex().row(), 1); + QCOMPARE(args.at(0).toModelIndex().column(), 0); + QCOMPARE(args.at(1).toModelIndex().row(), 1); + QCOMPARE(args.at(1).toModelIndex().column(), 0); + QCOMPARE(m_places->text(index), QStringLiteral("My text")); + + // restore original value + dataChangedSpy.clear(); + m_places->editPlace(index, originalText, bookmark.url(), bookmark.icon(), bookmark.metaDataItem(QStringLiteral("OnlyInApp"))); + QCOMPARE(dataChangedSpy.count(), 1); +} + QTEST_MAIN(KFilePlacesModelTest) #include "kfileplacesmodeltest.moc" diff --git a/src/filewidgets/kfileplacesmodel.cpp b/src/filewidgets/kfileplacesmodel.cpp --- a/src/filewidgets/kfileplacesmodel.cpp +++ b/src/filewidgets/kfileplacesmodel.cpp @@ -858,13 +858,32 @@ return; } - bookmark.setFullText(text); - bookmark.setUrl(url); - bookmark.setIcon(iconName); - bookmark.setMetaDataItem(QStringLiteral("OnlyInApp"), appName); + bool changed = false; + if (text != bookmark.fullText()) { + bookmark.setFullText(text); + changed = true; + } - refresh(); - emit dataChanged(index, index); + if (url != bookmark.url()) { + bookmark.setUrl(url); + changed = true; + } + + if (iconName != bookmark.icon()) { + bookmark.setIcon(iconName); + changed = true; + } + + const QString onlyInApp = bookmark.metaDataItem(QStringLiteral("OnlyInApp")); + if (appName != onlyInApp) { + bookmark.setMetaDataItem(QStringLiteral("OnlyInApp"), appName); + changed = true; + } + + if (changed) { + refresh(); + emit dataChanged(index, index); + } } void KFilePlacesModel::removePlace(const QModelIndex &index) const