diff options
Diffstat (limited to 'src/plugins/help/helpindexfilter.cpp')
-rw-r--r-- | src/plugins/help/helpindexfilter.cpp | 101 |
1 files changed, 99 insertions, 2 deletions
diff --git a/src/plugins/help/helpindexfilter.cpp b/src/plugins/help/helpindexfilter.cpp index c58c654320..d3d78cf0f7 100644 --- a/src/plugins/help/helpindexfilter.cpp +++ b/src/plugins/help/helpindexfilter.cpp @@ -32,15 +32,27 @@ #include <coreplugin/icore.h> #include <coreplugin/helpmanager.h> #include <extensionsystem/pluginmanager.h> -#include <utils/algorithm.h> #include <utils/utilsicons.h> #include <QIcon> + +#ifndef HELP_NEW_FILTER_ENGINE + +#include <utils/algorithm.h> + #include <QSqlDatabase> #include <QSqlDriver> #include <QSqlError> #include <QSqlQuery> +#else + +#include "localhelpmanager.h" +#include <QtHelp/QHelpEngine> +#include <QtHelp/QHelpFilterEngine> +#include <QtHelp/QHelpLink> + +#endif using namespace Core; using namespace Help; @@ -66,6 +78,8 @@ HelpIndexFilter::HelpIndexFilter() HelpIndexFilter::~HelpIndexFilter() = default; +#ifndef HELP_NEW_FILTER_ENGINE + void HelpIndexFilter::prepareSearch(const QString &entry) { Q_UNUSED(entry) @@ -133,6 +147,70 @@ QList<LocatorFilterEntry> HelpIndexFilter::matchesFor(QFutureInterface<LocatorFi return entries; } +#else + +bool HelpIndexFilter::updateCache(QFutureInterface<LocatorFilterEntry> &future, + const QStringList &cache, const QString &entry) +{ + const Qt::CaseSensitivity cs = caseSensitivity(entry); + QStringList bestKeywords; + QStringList worseKeywords; + bestKeywords.reserve(cache.size()); + worseKeywords.reserve(cache.size()); + for (const QString &keyword : cache) { + if (future.isCanceled()) + return false; + if (keyword.startsWith(entry, cs)) + bestKeywords.append(keyword); + else if (keyword.contains(entry, cs)) + worseKeywords.append(keyword); + } + bestKeywords << worseKeywords; + m_lastIndicesCache = bestKeywords; + m_lastEntry = entry; + + return true; +} + +QList<LocatorFilterEntry> HelpIndexFilter::matchesFor(QFutureInterface<LocatorFilterEntry> &future, const QString &entry) +{ + m_mutex.lock(); // guard m_needsUpdate + bool forceUpdate = m_needsUpdate; + m_mutex.unlock(); + + if (forceUpdate) { + QStringList indices; + QMetaObject::invokeMethod(this, "allIndices", Qt::BlockingQueuedConnection, + Q_RETURN_ARG(QStringList, indices)); + m_mutex.lock(); // guard m_needsUpdate + m_needsUpdate = false; + m_mutex.unlock(); + m_allIndicesCache = indices; + // force updating the cache taking the m_allIndicesCache + m_lastIndicesCache = QStringList(); + m_lastEntry = QString(); + } + + const QStringList cacheBase = m_lastEntry.isEmpty() || !entry.contains(m_lastEntry) + ? m_allIndicesCache : m_lastIndicesCache; + + if (!updateCache(future, cacheBase, entry)) + return QList<LocatorFilterEntry>(); + + const Qt::CaseSensitivity cs = caseSensitivity(entry); + QList<LocatorFilterEntry> entries; + for (const QString &keyword : qAsConst(m_lastIndicesCache)) { + const int index = keyword.indexOf(entry, 0, cs); + LocatorFilterEntry filterEntry(this, keyword, QVariant(), m_icon); + filterEntry.highlightInfo = {index, entry.length()}; + entries.append(filterEntry); + } + + return entries; +} + +#endif + void HelpIndexFilter::accept(LocatorFilterEntry selection, QString *newText, int *selectionStart, int *selectionLength) const { @@ -140,7 +218,14 @@ void HelpIndexFilter::accept(LocatorFilterEntry selection, Q_UNUSED(selectionStart) Q_UNUSED(selectionLength) const QString &key = selection.displayName; - const QMap<QString, QUrl> &links = HelpManager::instance()->linksForKeyword(key); +#ifndef HELP_NEW_FILTER_ENGINE + const QMultiMap<QString, QUrl> &links = HelpManager::instance()->linksForKeyword(key); +#else + QMultiMap<QString, QUrl> links; + const QList<QHelpLink> docs = LocalHelpManager::helpEngine().documentsForKeyword(key, QString()); + for (const auto &doc : docs) + links.insert(doc.title, doc.url); +#endif emit linksActivated(links, key); } @@ -150,6 +235,8 @@ void HelpIndexFilter::refresh(QFutureInterface<void> &future) invalidateCache(); } +#ifndef HELP_NEW_FILTER_ENGINE + QSet<QString> HelpIndexFilter::searchMatches(const QString &databaseFilePath, const QString &term, int limit) { @@ -180,6 +267,16 @@ QSet<QString> HelpIndexFilter::searchMatches(const QString &databaseFilePath, return keywords; } +#else + +QStringList HelpIndexFilter::allIndices() const +{ + LocalHelpManager::setupGuiHelpEngine(); + return LocalHelpManager::filterEngine()->indices(QString()); +} + +#endif + void HelpIndexFilter::invalidateCache() { m_mutex.lock(); |