From 1cc7342ef16cf904915355de9ee88c0250bca852 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Thu, 6 Apr 2023 16:34:33 +0200 Subject: [PATCH] JsonFieldPage: Use locator matcher for line edit completion This may be tested in File | New File... | C/C++ | C++ Class, Base class line edit should provide class completion. With locator matcher the task is being executed ~20% faster. This patch also solves the potential issue with interference between parallel runs of classes filter in locator and in LineEditField. Change-Id: Ice3e719d9cbe72ec4cd11bd4362a94e9c3ce8874 Reviewed-by: Christian Kandeler Reviewed-by: Reviewed-by: Qt CI Bot --- .../jsonwizard/jsonfieldpage.cpp | 30 +++++-------------- 1 file changed, 7 insertions(+), 23 deletions(-) diff --git a/src/plugins/projectexplorer/jsonwizard/jsonfieldpage.cpp b/src/plugins/projectexplorer/jsonwizard/jsonfieldpage.cpp index 45f8e682abc..3fc9d9aea6c 100644 --- a/src/plugins/projectexplorer/jsonwizard/jsonfieldpage.cpp +++ b/src/plugins/projectexplorer/jsonwizard/jsonfieldpage.cpp @@ -16,10 +16,7 @@ #include #include -#include #include -#include -#include #include #include @@ -29,7 +26,6 @@ #include #include #include -#include #include #include #include @@ -603,25 +599,17 @@ void LineEditField::setupCompletion(FancyLineEdit *lineEdit) using namespace Utils; if (m_completion == Completion::None) return; - ILocatorFilter * const classesFilter = findOrDefault( - ILocatorFilter::allLocatorFilters(), - equal(&ILocatorFilter::id, Id("Classes"))); - if (!classesFilter) - return; - classesFilter->prepareSearch({}); - const auto watcher = new QFutureWatcher; - const auto handleResults = [this, lineEdit, watcher](int firstIndex, int endIndex) { + const auto handleResults = [this, lineEdit](const QList &entries) { QSet namespaces; QStringList classes; Project * const project = ProjectTree::currentProject(); - for (int i = firstIndex; i < endIndex; ++i) { + for (const LocatorFilterEntry &entry : entries) { static const auto isReservedName = [](const QString &name) { static const QRegularExpression rx1("^_[A-Z].*"); static const QRegularExpression rx2(".*::_[A-Z].*"); return name.contains("__") || rx1.match(name).hasMatch() || rx2.match(name).hasMatch(); }; - const LocatorFilterEntry &entry = watcher->resultAt(i); const bool hasNamespace = !entry.extraInfo.isEmpty() && !entry.extraInfo.startsWith('<') && !entry.extraInfo.contains("::<") && !isReservedName(entry.extraInfo) @@ -658,15 +646,11 @@ void LineEditField::setupCompletion(FancyLineEdit *lineEdit) completionList.sort(); lineEdit->setSpecialCompleter(new QCompleter(completionList, lineEdit)); }; - QObject::connect(watcher, &QFutureWatcher::resultsReadyAt, lineEdit, - handleResults); - QObject::connect(watcher, &QFutureWatcher::finished, - watcher, &QFutureWatcher::deleteLater); - watcher->setFuture(runAsync([classesFilter](QFutureInterface &f) { - const QList matches = classesFilter->matchesFor(f, {}); - if (!matches.isEmpty()) - f.reportResults(QVector(matches.cbegin(), matches.cend())); - })); + LocatorMatcher *matcher = new LocatorMatcher; + matcher->setTasks(LocatorMatcher::classMatchers()); + QObject::connect(matcher, &LocatorMatcher::serialOutputDataReady, lineEdit, handleResults); + QObject::connect(matcher, &LocatorMatcher::done, matcher, &QObject::deleteLater); + matcher->start(); } void LineEditField::setText(const QString &text)