From 39b8bdab1788284c96efbf35bfadc07a1d76d85a Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Tue, 11 Apr 2023 19:17:55 +0200 Subject: [PATCH] BookmarkFilter: Use Acceptor for LocatorFilterEntry Change-Id: Idc3e0541b53277ab8e0cdc8626df7f9095f24ba9 Reviewed-by: Eike Ziller Reviewed-by: Reviewed-by: Qt CI Bot --- src/plugins/bookmarks/bookmarkfilter.cpp | 24 +++++++++++------------- src/plugins/bookmarks/bookmarkfilter.h | 3 --- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/plugins/bookmarks/bookmarkfilter.cpp b/src/plugins/bookmarks/bookmarkfilter.cpp index 28a03ce0074..f5af4c9b5fb 100644 --- a/src/plugins/bookmarks/bookmarkfilter.cpp +++ b/src/plugins/bookmarks/bookmarkfilter.cpp @@ -58,9 +58,17 @@ void BookmarkFilter::prepareSearch(const QString &entry) for (const QModelIndex &idx : matches) { const Bookmark *bookmark = m_manager->bookmarkForIndex(idx); const QString filename = bookmark->filePath().fileName(); - LocatorFilterEntry filterEntry(this, - QString("%1:%2").arg(filename).arg(bookmark->lineNumber())); - filterEntry.internalData = QVariant::fromValue(idx); + LocatorFilterEntry filterEntry; + filterEntry.displayName = QString("%1:%2").arg(filename).arg(bookmark->lineNumber()); + // TODO: according to QModelIndex docs, we shouldn't store model indexes: + // Model indexes should be used immediately and then discarded. + // You should not rely on indexes to remain valid after calling model functions that change + // the structure of the model or delete items. + filterEntry.acceptor = [manager = m_manager, idx] { + if (Bookmark *bookmark = manager->bookmarkForIndex(idx)) + manager->gotoBookmark(bookmark); + return AcceptResult(); + }; if (!bookmark->note().isEmpty()) filterEntry.extraInfo = bookmark->note(); else if (!bookmark->lineText().isEmpty()) @@ -104,14 +112,4 @@ QList BookmarkFilter::matchesFor(QFutureInterfacebookmarkForIndex(selection.internalData.toModelIndex())) - m_manager->gotoBookmark(bookmark); -} - } // Bookmarks::Internal diff --git a/src/plugins/bookmarks/bookmarkfilter.h b/src/plugins/bookmarks/bookmarkfilter.h index 0c69e2b6d45..5745669dc2b 100644 --- a/src/plugins/bookmarks/bookmarkfilter.h +++ b/src/plugins/bookmarks/bookmarkfilter.h @@ -16,9 +16,6 @@ public: void prepareSearch(const QString &entry) override; QList matchesFor(QFutureInterface &future, const QString &entry) override; - void accept(const Core::LocatorFilterEntry &selection, QString *newText, - int *selectionStart, int *selectionLength) const override; - private: BookmarkManager *m_manager = nullptr; // not owned QList m_results;