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) {
|
for (const QModelIndex &idx : matches) {
|
||||||
const Bookmark *bookmark = m_manager->bookmarkForIndex(idx);
|
const Bookmark *bookmark = m_manager->bookmarkForIndex(idx);
|
||||||
const QString filename = bookmark->filePath().fileName();
|
const QString filename = bookmark->filePath().fileName();
|
||||||
LocatorFilterEntry filterEntry(this,
|
LocatorFilterEntry filterEntry;
|
||||||
QString("%1:%2").arg(filename).arg(bookmark->lineNumber()));
|
filterEntry.displayName = QString("%1:%2").arg(filename).arg(bookmark->lineNumber());
|
||||||
filterEntry.internalData = QVariant::fromValue(idx);
|
// 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())
|
if (!bookmark->note().isEmpty())
|
||||||
filterEntry.extraInfo = bookmark->note();
|
filterEntry.extraInfo = bookmark->note();
|
||||||
else if (!bookmark->lineText().isEmpty())
|
else if (!bookmark->lineText().isEmpty())
|
||||||
@@ -104,14 +112,4 @@ QList<LocatorFilterEntry> BookmarkFilter::matchesFor(QFutureInterface<LocatorFil
|
|||||||
return m_results;
|
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
|
} // Bookmarks::Internal
|
||||||
|
@@ -16,9 +16,6 @@ public:
|
|||||||
void prepareSearch(const QString &entry) override;
|
void prepareSearch(const QString &entry) override;
|
||||||
QList<Core::LocatorFilterEntry> matchesFor(QFutureInterface<Core::LocatorFilterEntry> &future,
|
QList<Core::LocatorFilterEntry> matchesFor(QFutureInterface<Core::LocatorFilterEntry> &future,
|
||||||
const QString &entry) override;
|
const QString &entry) override;
|
||||||
void accept(const Core::LocatorFilterEntry &selection, QString *newText,
|
|
||||||
int *selectionStart, int *selectionLength) const override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BookmarkManager *m_manager = nullptr; // not owned
|
BookmarkManager *m_manager = nullptr; // not owned
|
||||||
QList<Core::LocatorFilterEntry> m_results;
|
QList<Core::LocatorFilterEntry> m_results;
|
||||||
|
Reference in New Issue
Block a user