From 3b41b9b24be08f08106dd820614988b1ac426d82 Mon Sep 17 00:00:00 2001 From: Andre Hartmann Date: Thu, 15 Aug 2019 09:30:50 +0200 Subject: [PATCH] Locator: Extract MatchLevel and use it in several filters ... that already used index-based prioritising. There are a few more with two- or three-level priority, but these still use the old scheme with multiple lists good/better/bestEntries and converting them would not gain much. Change-Id: I21f7cfe07a3ae8183db9cb62311697d03db6e4da Reviewed-by: Eike Ziller --- .../coreplugin/locator/basefilefilter.cpp | 21 ++++++++++--------- .../coreplugin/locator/basefilefilter.h | 1 + .../coreplugin/locator/filesystemfilter.cpp | 13 +++--------- .../coreplugin/locator/filesystemfilter.h | 2 ++ .../coreplugin/locator/ilocatorfilter.h | 8 +++++++ src/plugins/cpptools/cpplocatorfilter.cpp | 11 +++++----- .../qmljstools/qmljsfunctionfilter.cpp | 9 ++++---- 7 files changed, 34 insertions(+), 31 deletions(-) diff --git a/src/plugins/coreplugin/locator/basefilefilter.cpp b/src/plugins/coreplugin/locator/basefilefilter.cpp index f10c2ead53c..9f900b7500b 100644 --- a/src/plugins/coreplugin/locator/basefilefilter.cpp +++ b/src/plugins/coreplugin/locator/basefilefilter.cpp @@ -88,24 +88,25 @@ void BaseFileFilter::prepareSearch(const QString &entry) d->m_data.forceNewSearchList = false; } -static int matchLevelFor(const QRegularExpressionMatch &match, const QString &matchText) +ILocatorFilter::MatchLevel BaseFileFilter::matchLevelFor(const QRegularExpressionMatch &match, + const QString &matchText) const { const int consecutivePos = match.capturedStart(1); if (consecutivePos == 0) - return 0; + return MatchLevel::Best; if (consecutivePos > 0) { const QChar prevChar = matchText.at(consecutivePos - 1); if (prevChar == '_' || prevChar == '.') - return 1; + return MatchLevel::Better; } if (match.capturedStart() == 0) - return 2; - return 3; + return MatchLevel::Good; + return MatchLevel::Normal; } QList BaseFileFilter::matchesFor(QFutureInterface &future, const QString &origEntry) { - QList entries[4]; + QList entries[int(MatchLevel::Count)]; // If search string contains spaces, treat them as wildcard '*' and search in full path const QString entry = QDir::fromNativeSeparators(origEntry).replace(' ', '*'); const EditorManager::FilePathInfo fp = EditorManager::splitLineAndColumnNumber(entry); @@ -113,7 +114,7 @@ QList BaseFileFilter::matchesFor(QFutureInterfacem_current.clear(); // free memory - return entries[0]; + return {}; } auto containsPathSeparator = [](const QString &candidate) { return candidate.contains('/') || candidate.contains('*'); @@ -151,7 +152,7 @@ QList BaseFileFilter::matchesFor(QFutureInterface BaseFileFilter::matchesFor(QFutureInterfacem_current.previousResultPaths.append(path); } } @@ -180,7 +181,7 @@ QList BaseFileFilter::matchesFor(QFutureInterface()); } void BaseFileFilter::accept(LocatorFilterEntry selection, diff --git a/src/plugins/coreplugin/locator/basefilefilter.h b/src/plugins/coreplugin/locator/basefilefilter.h index 8371adad7ce..9c538037eb1 100644 --- a/src/plugins/coreplugin/locator/basefilefilter.h +++ b/src/plugins/coreplugin/locator/basefilefilter.h @@ -76,6 +76,7 @@ protected: QSharedPointer fileIterator(); private: + MatchLevel matchLevelFor(const QRegularExpressionMatch &match, const QString &matchText) const; void updatePreviousResultData(); Internal::BaseFileFilterPrivate *d = nullptr; diff --git a/src/plugins/coreplugin/locator/filesystemfilter.cpp b/src/plugins/coreplugin/locator/filesystemfilter.cpp index 1266b008e74..5e04215539d 100644 --- a/src/plugins/coreplugin/locator/filesystemfilter.cpp +++ b/src/plugins/coreplugin/locator/filesystemfilter.cpp @@ -40,15 +40,8 @@ using namespace Core; using namespace Core::Internal; -enum class MatchLevel { - Best = 0, - Better, - Good, - Normal, - Number -}; - -static MatchLevel matchLevelFor(const QRegularExpressionMatch &match, const QString &matchText) +ILocatorFilter::MatchLevel FileSystemFilter::matchLevelFor(const QRegularExpressionMatch &match, + const QString &matchText) const { const int consecutivePos = match.capturedStart(1); if (consecutivePos == 0) @@ -80,7 +73,7 @@ void FileSystemFilter::prepareSearch(const QString &entry) QList FileSystemFilter::matchesFor(QFutureInterface &future, const QString &entry) { - QList entries[int(MatchLevel::Number)]; + QList entries[int(MatchLevel::Count)]; const QFileInfo entryInfo(entry); const QString entryFileName = entryInfo.fileName(); QString directory = entryInfo.path(); diff --git a/src/plugins/coreplugin/locator/filesystemfilter.h b/src/plugins/coreplugin/locator/filesystemfilter.h index abca3ed67a0..a1391060837 100644 --- a/src/plugins/coreplugin/locator/filesystemfilter.h +++ b/src/plugins/coreplugin/locator/filesystemfilter.h @@ -53,6 +53,8 @@ public: void refresh(QFutureInterface &) override {} private: + MatchLevel matchLevelFor(const QRegularExpressionMatch &match, const QString &matchText) const; + bool m_includeHidden = true; QString m_currentDocumentDirectory; }; diff --git a/src/plugins/coreplugin/locator/ilocatorfilter.h b/src/plugins/coreplugin/locator/ilocatorfilter.h index 92b00be8120..b98e8f96912 100644 --- a/src/plugins/coreplugin/locator/ilocatorfilter.h +++ b/src/plugins/coreplugin/locator/ilocatorfilter.h @@ -105,6 +105,14 @@ class CORE_EXPORT ILocatorFilter : public QObject Q_OBJECT public: + enum class MatchLevel { + Best = 0, + Better, + Good, + Normal, + Count + }; + enum Priority {Highest = 0, High = 1, Medium = 2, Low = 3}; ILocatorFilter(QObject *parent = nullptr); diff --git a/src/plugins/cpptools/cpplocatorfilter.cpp b/src/plugins/cpptools/cpplocatorfilter.cpp index 5ae84c08ac2..bfc93c7e531 100644 --- a/src/plugins/cpptools/cpplocatorfilter.cpp +++ b/src/plugins/cpptools/cpplocatorfilter.cpp @@ -69,8 +69,7 @@ void CppLocatorFilter::refresh(QFutureInterface &future) QList CppLocatorFilter::matchesFor( QFutureInterface &future, const QString &entry) { - enum { Best = 0, Better, Good, Normal, EntryNumber }; - QList entries[EntryNumber]; + QList entries[int(MatchLevel::Count)]; const Qt::CaseSensitivity caseSensitivityForPrefix = caseSensitivity(entry); const IndexItem::ItemType wanted = matchTypes(); @@ -113,13 +112,13 @@ QList CppLocatorFilter::matchesFor( } if (matchInParameterList) - entries[Normal].append(filterEntry); + entries[int(MatchLevel::Normal)].append(filterEntry); else if (filterEntry.displayName.startsWith(entry, caseSensitivityForPrefix)) - entries[Best].append(filterEntry); + entries[int(MatchLevel::Best)].append(filterEntry); else if (filterEntry.displayName.contains(entry, caseSensitivityForPrefix)) - entries[Better].append(filterEntry); + entries[int(MatchLevel::Better)].append(filterEntry); else - entries[Good].append(filterEntry); + entries[int(MatchLevel::Good)].append(filterEntry); } } diff --git a/src/plugins/qmljstools/qmljsfunctionfilter.cpp b/src/plugins/qmljstools/qmljsfunctionfilter.cpp index d9a2600263a..715347ebf34 100644 --- a/src/plugins/qmljstools/qmljsfunctionfilter.cpp +++ b/src/plugins/qmljstools/qmljsfunctionfilter.cpp @@ -58,8 +58,7 @@ QList FunctionFilter::matchesFor( QFutureInterface &future, const QString &entry) { - enum { Best = 0, Better, Good, EntryNumber }; - QList entries[EntryNumber]; + QList entries[int(MatchLevel::Count)]; const Qt::CaseSensitivity caseSensitivityForPrefix = caseSensitivity(entry); const QRegularExpression regexp = createRegExp(entry); @@ -83,11 +82,11 @@ QList FunctionFilter::matchesFor( filterEntry.highlightInfo = highlightInfo(match); if (filterEntry.displayName.startsWith(entry, caseSensitivityForPrefix)) - entries[Best].append(filterEntry); + entries[int(MatchLevel::Best)].append(filterEntry); else if (filterEntry.displayName.contains(entry, caseSensitivityForPrefix)) - entries[Better].append(filterEntry); + entries[int(MatchLevel::Better)].append(filterEntry); else - entries[Good].append(filterEntry); + entries[int(MatchLevel::Good)].append(filterEntry); } } }