forked from qt-creator/qt-creator
BookmarkFilter: Use Acceptor for LocatorFilterEntry
Change-Id: Idc3e0541b53277ab8e0cdc8626df7f9095f24ba9 Reviewed-by: Eike Ziller <eike.ziller@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
@@ -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<LocatorFilterEntry> BookmarkFilter::matchesFor(QFutureInterface<LocatorFil
|
||||
return m_results;
|
||||
}
|
||||
|
||||
void BookmarkFilter::accept(const LocatorFilterEntry &selection, QString *newText,
|
||||
int *selectionStart, int *selectionLength) const
|
||||
{
|
||||
Q_UNUSED(newText)
|
||||
Q_UNUSED(selectionStart)
|
||||
Q_UNUSED(selectionLength)
|
||||
if (Bookmark *bookmark = m_manager->bookmarkForIndex(selection.internalData.toModelIndex()))
|
||||
m_manager->gotoBookmark(bookmark);
|
||||
}
|
||||
|
||||
} // Bookmarks::Internal
|
||||
|
@@ -16,9 +16,6 @@ public:
|
||||
void prepareSearch(const QString &entry) override;
|
||||
QList<Core::LocatorFilterEntry> matchesFor(QFutureInterface<Core::LocatorFilterEntry> &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<Core::LocatorFilterEntry> m_results;
|
||||
|
Reference in New Issue
Block a user