forked from qt-creator/qt-creator
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 <christian.kandeler@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:
@@ -16,10 +16,7 @@
|
|||||||
|
|
||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
#include <utils/fancylineedit.h>
|
#include <utils/fancylineedit.h>
|
||||||
#include <utils/fileutils.h>
|
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/runextensions.h>
|
|
||||||
#include <utils/stringutils.h>
|
|
||||||
#include <utils/theme/theme.h>
|
#include <utils/theme/theme.h>
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
@@ -29,7 +26,6 @@
|
|||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFormLayout>
|
#include <QFormLayout>
|
||||||
#include <QFutureWatcher>
|
|
||||||
#include <QItemSelectionModel>
|
#include <QItemSelectionModel>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QListView>
|
#include <QListView>
|
||||||
@@ -603,25 +599,17 @@ void LineEditField::setupCompletion(FancyLineEdit *lineEdit)
|
|||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
if (m_completion == Completion::None)
|
if (m_completion == Completion::None)
|
||||||
return;
|
return;
|
||||||
ILocatorFilter * const classesFilter = findOrDefault(
|
const auto handleResults = [this, lineEdit](const QList<LocatorFilterEntry> &entries) {
|
||||||
ILocatorFilter::allLocatorFilters(),
|
|
||||||
equal(&ILocatorFilter::id, Id("Classes")));
|
|
||||||
if (!classesFilter)
|
|
||||||
return;
|
|
||||||
classesFilter->prepareSearch({});
|
|
||||||
const auto watcher = new QFutureWatcher<LocatorFilterEntry>;
|
|
||||||
const auto handleResults = [this, lineEdit, watcher](int firstIndex, int endIndex) {
|
|
||||||
QSet<QString> namespaces;
|
QSet<QString> namespaces;
|
||||||
QStringList classes;
|
QStringList classes;
|
||||||
Project * const project = ProjectTree::currentProject();
|
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 auto isReservedName = [](const QString &name) {
|
||||||
static const QRegularExpression rx1("^_[A-Z].*");
|
static const QRegularExpression rx1("^_[A-Z].*");
|
||||||
static const QRegularExpression rx2(".*::_[A-Z].*");
|
static const QRegularExpression rx2(".*::_[A-Z].*");
|
||||||
return name.contains("__") || rx1.match(name).hasMatch()
|
return name.contains("__") || rx1.match(name).hasMatch()
|
||||||
|| rx2.match(name).hasMatch();
|
|| rx2.match(name).hasMatch();
|
||||||
};
|
};
|
||||||
const LocatorFilterEntry &entry = watcher->resultAt(i);
|
|
||||||
const bool hasNamespace = !entry.extraInfo.isEmpty()
|
const bool hasNamespace = !entry.extraInfo.isEmpty()
|
||||||
&& !entry.extraInfo.startsWith('<') && !entry.extraInfo.contains("::<")
|
&& !entry.extraInfo.startsWith('<') && !entry.extraInfo.contains("::<")
|
||||||
&& !isReservedName(entry.extraInfo)
|
&& !isReservedName(entry.extraInfo)
|
||||||
@@ -658,15 +646,11 @@ void LineEditField::setupCompletion(FancyLineEdit *lineEdit)
|
|||||||
completionList.sort();
|
completionList.sort();
|
||||||
lineEdit->setSpecialCompleter(new QCompleter(completionList, lineEdit));
|
lineEdit->setSpecialCompleter(new QCompleter(completionList, lineEdit));
|
||||||
};
|
};
|
||||||
QObject::connect(watcher, &QFutureWatcher<LocatorFilterEntry>::resultsReadyAt, lineEdit,
|
LocatorMatcher *matcher = new LocatorMatcher;
|
||||||
handleResults);
|
matcher->setTasks(LocatorMatcher::classMatchers());
|
||||||
QObject::connect(watcher, &QFutureWatcher<LocatorFilterEntry>::finished,
|
QObject::connect(matcher, &LocatorMatcher::serialOutputDataReady, lineEdit, handleResults);
|
||||||
watcher, &QFutureWatcher<LocatorFilterEntry>::deleteLater);
|
QObject::connect(matcher, &LocatorMatcher::done, matcher, &QObject::deleteLater);
|
||||||
watcher->setFuture(runAsync([classesFilter](QFutureInterface<LocatorFilterEntry> &f) {
|
matcher->start();
|
||||||
const QList<LocatorFilterEntry> matches = classesFilter->matchesFor(f, {});
|
|
||||||
if (!matches.isEmpty())
|
|
||||||
f.reportResults(QVector<LocatorFilterEntry>(matches.cbegin(), matches.cend()));
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LineEditField::setText(const QString &text)
|
void LineEditField::setText(const QString &text)
|
||||||
|
Reference in New Issue
Block a user