diff options
author | Andre Hartmann <aha_1980@gmx.de> | 2019-08-15 09:30:50 +0200 |
---|---|---|
committer | André Hartmann <aha_1980@gmx.de> | 2019-08-15 09:57:46 +0000 |
commit | 3b41b9b24be08f08106dd820614988b1ac426d82 (patch) | |
tree | 5d9f7253279fda8ee4d8fafba6c581e1326e9426 /src/plugins/coreplugin | |
parent | 847108d4f44c9d940162166b14e59f38ff99d54f (diff) | |
download | qt-creator-3b41b9b24be08f08106dd820614988b1ac426d82.tar.gz |
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 <eike.ziller@qt.io>
Diffstat (limited to 'src/plugins/coreplugin')
-rw-r--r-- | src/plugins/coreplugin/locator/basefilefilter.cpp | 21 | ||||
-rw-r--r-- | src/plugins/coreplugin/locator/basefilefilter.h | 1 | ||||
-rw-r--r-- | src/plugins/coreplugin/locator/filesystemfilter.cpp | 13 | ||||
-rw-r--r-- | src/plugins/coreplugin/locator/filesystemfilter.h | 2 | ||||
-rw-r--r-- | src/plugins/coreplugin/locator/ilocatorfilter.h | 8 |
5 files changed, 25 insertions, 20 deletions
diff --git a/src/plugins/coreplugin/locator/basefilefilter.cpp b/src/plugins/coreplugin/locator/basefilefilter.cpp index f10c2ead53..9f900b7500 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<LocatorFilterEntry> BaseFileFilter::matchesFor(QFutureInterface<LocatorFilterEntry> &future, const QString &origEntry) { - QList<LocatorFilterEntry> entries[4]; + QList<LocatorFilterEntry> 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<LocatorFilterEntry> BaseFileFilter::matchesFor(QFutureInterface<LocatorFil const QRegularExpression regexp = createRegExp(fp.filePath); if (!regexp.isValid()) { d->m_current.clear(); // free memory - return entries[0]; + return {}; } auto containsPathSeparator = [](const QString &candidate) { return candidate.contains('/') || candidate.contains('*'); @@ -151,7 +152,7 @@ QList<LocatorFilterEntry> BaseFileFilter::matchesFor(QFutureInterface<LocatorFil filterEntry.fileName = path.toString(); filterEntry.extraInfo = FilePath::fromFileInfo(fi).shortNativePath(); - const int matchLevel = matchLevelFor(match, matchText); + const MatchLevel matchLevel = matchLevelFor(match, matchText); if (hasPathSeparator) { match = regexp.match(filterEntry.extraInfo); filterEntry.highlightInfo = @@ -160,7 +161,7 @@ QList<LocatorFilterEntry> BaseFileFilter::matchesFor(QFutureInterface<LocatorFil filterEntry.highlightInfo = highlightInfo(match); } - entries[matchLevel].append(filterEntry); + entries[int(matchLevel)].append(filterEntry); d->m_current.previousResultPaths.append(path); } } @@ -180,7 +181,7 @@ QList<LocatorFilterEntry> BaseFileFilter::matchesFor(QFutureInterface<LocatorFil Utils::sort(entry, Core::LocatorFilterEntry::compareLexigraphically); } - return entries[0] + entries[1] + entries[2] + entries[3]; + return std::accumulate(std::begin(entries), std::end(entries), QList<LocatorFilterEntry>()); } void BaseFileFilter::accept(LocatorFilterEntry selection, diff --git a/src/plugins/coreplugin/locator/basefilefilter.h b/src/plugins/coreplugin/locator/basefilefilter.h index 8371adad7c..9c538037eb 100644 --- a/src/plugins/coreplugin/locator/basefilefilter.h +++ b/src/plugins/coreplugin/locator/basefilefilter.h @@ -76,6 +76,7 @@ protected: QSharedPointer<Iterator> 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 1266b008e7..5e04215539 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<LocatorFilterEntry> FileSystemFilter::matchesFor(QFutureInterface<LocatorFilterEntry> &future, const QString &entry) { - QList<LocatorFilterEntry> entries[int(MatchLevel::Number)]; + QList<LocatorFilterEntry> 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 abca3ed67a..a139106083 100644 --- a/src/plugins/coreplugin/locator/filesystemfilter.h +++ b/src/plugins/coreplugin/locator/filesystemfilter.h @@ -53,6 +53,8 @@ public: void refresh(QFutureInterface<void> &) 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 92b00be812..b98e8f9691 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); |