diff --git a/src/plugins/coreplugin/helpitem.cpp b/src/plugins/coreplugin/helpitem.cpp index 544c9be9c94..2a972cb98eb 100644 --- a/src/plugins/coreplugin/helpitem.cpp +++ b/src/plugins/coreplugin/helpitem.cpp @@ -211,7 +211,7 @@ const HelpItem::Links &HelpItem::links() const m_helpLinks.emplace(Links{{m_keyword, m_helpUrl}}); } else { m_helpLinks.emplace(); // set a value even if there are no help IDs - QMap helpLinks; + QMultiMap helpLinks; for (const QString &id : m_helpIds) { helpLinks = Core::HelpManager::linksForIdentifier(id); if (!helpLinks.isEmpty()) { diff --git a/src/plugins/coreplugin/helpmanager.cpp b/src/plugins/coreplugin/helpmanager.cpp index 3e8e5b40037..4fbafd202bc 100644 --- a/src/plugins/coreplugin/helpmanager.cpp +++ b/src/plugins/coreplugin/helpmanager.cpp @@ -86,14 +86,14 @@ void unregisterDocumentation(const QStringList &fileNames) m_instance->unregisterDocumentation(fileNames); } -QMap linksForIdentifier(const QString &id) +QMultiMap linksForIdentifier(const QString &id) { - return checkInstance() ? m_instance->linksForIdentifier(id) : QMap(); + return checkInstance() ? m_instance->linksForIdentifier(id) : QMultiMap(); } -QMap linksForKeyword(const QString &keyword) +QMultiMap linksForKeyword(const QString &keyword) { - return checkInstance() ? m_instance->linksForKeyword(keyword) : QMap(); + return checkInstance() ? m_instance->linksForKeyword(keyword) : QMultiMap(); } QByteArray fileData(const QUrl &url) diff --git a/src/plugins/coreplugin/helpmanager.h b/src/plugins/coreplugin/helpmanager.h index 7b7e4f052e7..ac948b633d9 100644 --- a/src/plugins/coreplugin/helpmanager.h +++ b/src/plugins/coreplugin/helpmanager.h @@ -63,8 +63,8 @@ CORE_EXPORT QString documentationPath(); CORE_EXPORT void registerDocumentation(const QStringList &fileNames); CORE_EXPORT void unregisterDocumentation(const QStringList &fileNames); -CORE_EXPORT QMap linksForIdentifier(const QString &id); -CORE_EXPORT QMap linksForKeyword(const QString &id); +CORE_EXPORT QMultiMap linksForIdentifier(const QString &id); +CORE_EXPORT QMultiMap linksForKeyword(const QString &id); CORE_EXPORT QByteArray fileData(const QUrl &url); CORE_EXPORT void showHelpUrl(const QUrl &url, HelpViewerLocation location = HelpModeAlways); diff --git a/src/plugins/coreplugin/helpmanager_implementation.h b/src/plugins/coreplugin/helpmanager_implementation.h index 9af4a499380..c317a95e361 100644 --- a/src/plugins/coreplugin/helpmanager_implementation.h +++ b/src/plugins/coreplugin/helpmanager_implementation.h @@ -40,8 +40,8 @@ protected: public: virtual void registerDocumentation(const QStringList &fileNames) = 0; virtual void unregisterDocumentation(const QStringList &fileNames) = 0; - virtual QMap linksForIdentifier(const QString &id) = 0; - virtual QMap linksForKeyword(const QString &keyword) = 0; + virtual QMultiMap linksForIdentifier(const QString &id) = 0; + virtual QMultiMap linksForKeyword(const QString &keyword) = 0; virtual QByteArray fileData(const QUrl &url) = 0; virtual void showHelpUrl(const QUrl &url, HelpViewerLocation location = HelpModeAlways) = 0; }; diff --git a/src/plugins/help/filtersettingspage.cpp b/src/plugins/help/filtersettingspage.cpp index cfd184dfc9a..805ab844ed6 100644 --- a/src/plugins/help/filtersettingspage.cpp +++ b/src/plugins/help/filtersettingspage.cpp @@ -24,8 +24,10 @@ ****************************************************************************/ #include "filtersettingspage.h" - #include "helpconstants.h" + +#ifndef HELP_NEW_FILTER_ENGINE + #include "helpmanager.h" #include @@ -38,6 +40,15 @@ #include #include +#else + +#include +#include +#include +#include "localhelpmanager.h" + +#endif + using namespace Help::Internal; FilterSettingsPage::FilterSettingsPage() @@ -47,6 +58,8 @@ FilterSettingsPage::FilterSettingsPage() setCategory(Help::Constants::HELP_CATEGORY); } +#ifndef HELP_NEW_FILTER_ENGINE + QWidget *FilterSettingsPage::widget() { if (!m_widget) { @@ -254,3 +267,48 @@ void FilterSettingsPage::updateFilterDescription(const QString &filter) { m_ui.label->setText(msgFilterLabel(filter)); } + +#else + +QWidget *FilterSettingsPage::widget() +{ + if (!m_widget) { + LocalHelpManager::setupGuiHelpEngine(); + m_widget = new QHelpFilterSettingsWidget(nullptr); + m_widget->readSettings(LocalHelpManager::filterEngine()); + + connect(Core::HelpManager::Signals::instance(), + &Core::HelpManager::Signals::documentationChanged, + this, + &FilterSettingsPage::updateFilterPage); + + updateFilterPage(); + } + return m_widget; +} + +void FilterSettingsPage::apply() +{ + if (m_widget->applySettings(LocalHelpManager::filterEngine())) + emit filtersChanged(); + + m_widget->readSettings(LocalHelpManager::filterEngine()); +} + +void FilterSettingsPage::finish() +{ + disconnect(Core::HelpManager::Signals::instance(), + &Core::HelpManager::Signals::documentationChanged, + this, + &FilterSettingsPage::updateFilterPage); + delete m_widget; +} + +void FilterSettingsPage::updateFilterPage() +{ + m_widget->setAvailableComponents(LocalHelpManager::filterEngine()->availableComponents()); + m_widget->setAvailableVersions(LocalHelpManager::filterEngine()->availableVersions()); +} + +#endif + diff --git a/src/plugins/help/filtersettingspage.h b/src/plugins/help/filtersettingspage.h index 4d5d102107b..6d98f096d87 100644 --- a/src/plugins/help/filtersettingspage.h +++ b/src/plugins/help/filtersettingspage.h @@ -25,11 +25,16 @@ #pragma once -#include "ui_filtersettingspage.h" #include #include +#ifndef HELP_NEW_FILTER_ENGINE +#include "ui_filtersettingspage.h" +#else +class QHelpFilterSettingsWidget; +#endif + namespace Help { namespace Internal { @@ -48,9 +53,11 @@ signals: void filtersChanged(); private: + + void updateFilterPage(); +#ifndef HELP_NEW_FILTER_ENGINE void updateAttributes(QListWidgetItem *item); void updateFilterMap(); - void updateFilterPage(); void addFilter(); void removeFilter(); void updateFilterDescription(const QString &filter); @@ -64,6 +71,10 @@ private: FilterMap m_filterMapBackup; QStringList m_removedFilters; +#else + QPointer m_widget; +#endif + }; } // namespace Help diff --git a/src/plugins/help/help.pro b/src/plugins/help/help.pro index 7b58578ef1c..1299eb63849 100644 --- a/src/plugins/help/help.pro +++ b/src/plugins/help/help.pro @@ -4,6 +4,10 @@ INCLUDEPATH += $$PWD include(../../qtcreatorplugin.pri) +minQtVersion(5, 15, 0) { +DEFINES += HELP_NEW_FILTER_ENGINE +} + DEFINES += \ QT_CLUCENE_SUPPORT \ HELP_LIBRARY diff --git a/src/plugins/help/help.qbs b/src/plugins/help/help.qbs index e1268e729d2..2eea437473e 100644 --- a/src/plugins/help/help.qbs +++ b/src/plugins/help/help.qbs @@ -1,4 +1,4 @@ -import qbs 1.0 +import qbs.Utilities Project { name: "Help" @@ -28,6 +28,8 @@ Project { defines.push("QTC_WEBENGINE_HELPVIEWER"); if (qlitehtml.present) defines.push("QTC_LITEHTML_HELPVIEWER") + if (Utilities.versionCompare(Qt.core.version, "5.15") >= 0) + defines.push("HELP_NEW_FILTER_ENGINE"); return defines; } diff --git a/src/plugins/help/helpindexfilter.cpp b/src/plugins/help/helpindexfilter.cpp index c58c6543209..7b51f8812cc 100644 --- a/src/plugins/help/helpindexfilter.cpp +++ b/src/plugins/help/helpindexfilter.cpp @@ -32,15 +32,27 @@ #include #include #include -#include #include #include + +#ifndef HELP_NEW_FILTER_ENGINE + +#include + #include #include #include #include +#else + +#include "localhelpmanager.h" +#include +#include +#include + +#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 HelpIndexFilter::matchesFor(QFutureInterface &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 HelpIndexFilter::matchesFor(QFutureInterface &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(); + + const Qt::CaseSensitivity cs = caseSensitivity(entry); + QList 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 &links = HelpManager::instance()->linksForKeyword(key); +#ifndef HELP_NEW_FILTER_ENGINE + const QMultiMap &links = HelpManager::instance()->linksForKeyword(key); +#else + QMultiMap links; + const QList 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 &future) invalidateCache(); } +#ifndef HELP_NEW_FILTER_ENGINE + QSet HelpIndexFilter::searchMatches(const QString &databaseFilePath, const QString &term, int limit) { @@ -180,6 +267,16 @@ QSet 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(); diff --git a/src/plugins/help/helpindexfilter.h b/src/plugins/help/helpindexfilter.h index 04873fe958a..40c19d54a8e 100644 --- a/src/plugins/help/helpindexfilter.h +++ b/src/plugins/help/helpindexfilter.h @@ -42,24 +42,38 @@ public: ~HelpIndexFilter() final; // ILocatorFilter - void prepareSearch(const QString &entry) override; QList matchesFor(QFutureInterface &future, const QString &entry) override; void accept(Core::LocatorFilterEntry selection, QString *newText, int *selectionStart, int *selectionLength) const override; void refresh(QFutureInterface &future) override; +#ifndef HELP_NEW_FILTER_ENGINE + void prepareSearch(const QString &entry) override; Q_INVOKABLE QSet searchMatches(const QString &databaseFilePath, const QString &term, int limit); +#else + Q_INVOKABLE QStringList allIndices() const; +#endif + signals: - void linksActivated(const QMap &links, const QString &key) const; + void linksActivated(const QMultiMap &links, const QString &key) const; private: void invalidateCache(); +#ifndef HELP_NEW_FILTER_ENGINE QStringList m_helpDatabases; QSet m_keywordCache; QString m_searchTermCache; +#else + bool updateCache(QFutureInterface &future, + const QStringList &cache, const QString &entry); + + QStringList m_allIndicesCache; + QStringList m_lastIndicesCache; + QString m_lastEntry; +#endif bool m_needsUpdate = true; QMutex m_mutex; QIcon m_icon; diff --git a/src/plugins/help/helpmanager.cpp b/src/plugins/help/helpmanager.cpp index 09fdc041fe3..4fff954512d 100644 --- a/src/plugins/help/helpmanager.cpp +++ b/src/plugins/help/helpmanager.cpp @@ -43,10 +43,15 @@ #include #include + +#ifndef HELP_NEW_FILTER_ENGINE #include #include #include #include +#else +#include +#endif using namespace Core; @@ -84,6 +89,8 @@ struct HelpManagerPrivate static HelpManager *m_instance = nullptr; static HelpManagerPrivate *d = nullptr; +#ifndef HELP_NEW_FILTER_ENGINE + // -- DbCleaner struct DbCleaner @@ -93,6 +100,8 @@ struct DbCleaner QString name; }; +#endif + // -- HelpManager HelpManager::HelpManager(QObject *parent) : @@ -225,20 +234,36 @@ QSet HelpManager::userDocumentationPaths() } // This should go into Qt 4.8 once we start using it for Qt Creator -QMap HelpManager::linksForKeyword(const QString &key) +QMultiMap HelpManager::linksForKeyword(const QString &key) { QTC_ASSERT(!d->m_needsSetup, return {}); if (key.isEmpty()) return {}; +#ifndef HELP_NEW_FILTER_ENGINE return d->m_helpEngine->linksForKeyword(key); +#else + QMultiMap links; + const QList docs = d->m_helpEngine->documentsForKeyword(key, QString()); + for (const auto doc : docs) + links.insert(doc.title, doc.url); + return links; +#endif } -QMap HelpManager::linksForIdentifier(const QString &id) +QMultiMap HelpManager::linksForIdentifier(const QString &id) { QTC_ASSERT(!d->m_needsSetup, return {}); if (id.isEmpty()) return {}; +#ifndef HELP_NEW_FILTER_ENGINE return d->m_helpEngine->linksForIdentifier(id); +#else + QMultiMap links; + const QList docs = d->m_helpEngine->documentsForIdentifier(id, QString()); + for (const auto doc : docs) + links.insert(doc.title, doc.url); + return links; +#endif } QUrl HelpManager::findFile(const QUrl &url) @@ -292,6 +317,8 @@ QVariant HelpManager::customValue(const QString &key, const QVariant &value) return d->m_helpEngine->customValue(key, value); } +#ifndef HELP_NEW_FILTER_ENGINE + HelpManager::Filters HelpManager::filters() { QTC_ASSERT(!d->m_needsSetup, return {}); @@ -358,6 +385,8 @@ void HelpManager::addUserDefinedFilter(const QString &filter, const QStringList emit m_instance->collectionFileChanged(); } +#endif + void HelpManager::aboutToShutdown() { if (d && d->m_registerFuture.isRunning()) { @@ -378,6 +407,9 @@ void HelpManager::setupHelpManager() // create the help engine d->m_helpEngine = new QHelpEngineCore(collectionFilePath(), m_instance); +#ifdef HELP_NEW_FILTER_ENGINE + d->m_helpEngine->setUsesFilterEngine(true); +#endif d->m_helpEngine->setupData(); for (const QString &filePath : d->documentationFromInstaller()) diff --git a/src/plugins/help/helpmanager.h b/src/plugins/help/helpmanager.h index bcde6b794cd..6edaae859b8 100644 --- a/src/plugins/help/helpmanager.h +++ b/src/plugins/help/helpmanager.h @@ -40,8 +40,6 @@ class HelpManager : public QObject, public Core::HelpManager::Implementation Q_OBJECT public: - using Filters = QHash; - explicit HelpManager(QObject *parent = nullptr); ~HelpManager() override; @@ -56,8 +54,8 @@ public: static void registerUserDocumentation(const QStringList &filePaths); static QSet userDocumentationPaths(); - QMap linksForIdentifier(const QString &id) override; - QMap linksForKeyword(const QString &key) override; + QMultiMap linksForIdentifier(const QString &id) override; + QMultiMap linksForKeyword(const QString &key) override; static QUrl findFile(const QUrl &url); QByteArray fileData(const QUrl &url) override; @@ -69,12 +67,16 @@ public: static void setCustomValue(const QString &key, const QVariant &value); static QVariant customValue(const QString &key, const QVariant &value = QVariant()); +#ifndef HELP_NEW_FILTER_ENGINE + using Filters = QHash; + static Filters filters(); static Filters fixedFilters(); static Filters userDefinedFilters(); static void removeUserDefinedFilter(const QString &filter); static void addUserDefinedFilter(const QString &filter, const QStringList &attr); +#endif static void aboutToShutdown(); diff --git a/src/plugins/help/helpplugin.cpp b/src/plugins/help/helpplugin.cpp index 9542a457c49..4a6c47f879c 100644 --- a/src/plugins/help/helpplugin.cpp +++ b/src/plugins/help/helpplugin.cpp @@ -116,7 +116,7 @@ public: void activateContents(); void saveExternalWindowSettings(); - void showLinksInCurrentViewer(const QMap &links, const QString &key); + void showLinksInCurrentViewer(const QMultiMap &links, const QString &key); void setupHelpEngineIfNeeded(); @@ -124,7 +124,10 @@ public: void slotSystemInformation(); +#ifndef HELP_NEW_FILTER_ENGINE void resetFilter(); +#endif + static void activateHelpMode() { ModeManager::activateMode(Constants::ID_MODE_HELP); } static bool canShowHelpSideBySide(); @@ -314,6 +317,8 @@ ExtensionSystem::IPlugin::ShutdownFlag HelpPlugin::aboutToShutdown() return SynchronousShutdown; } +#ifndef HELP_NEW_FILTER_ENGINE + void HelpPluginPrivate::resetFilter() { const QString &filterInternal = QString::fromLatin1("Qt Creator %1.%2.%3") @@ -348,6 +353,8 @@ void HelpPluginPrivate::resetFilter() LocalHelpManager::instance(), &LocalHelpManager::updateFilterModel); } +#endif + void HelpPluginPrivate::saveExternalWindowSettings() { if (!m_externalWindow) @@ -436,7 +443,7 @@ HelpWidget *HelpPlugin::modeHelpWidget() return dd->m_centralWidget; } -void HelpPluginPrivate::showLinksInCurrentViewer(const QMap &links, const QString &key) +void HelpPluginPrivate::showLinksInCurrentViewer(const QMultiMap &links, const QString &key) { if (links.size() < 1) return; @@ -577,7 +584,7 @@ void HelpPluginPrivate::showContextHelp(const HelpItem &contextHelp) } else if (links.size() == 1 && !contextHelp.isFuzzyMatch()) { showHelpUrl(links.front().second, LocalHelpManager::contextHelpOption()); } else { - QMap map; + QMultiMap map; for (const HelpItem::Link &link : links) map.insert(link.first, link.second); auto tc = new TopicChooser(ICore::dialogParent(), contextHelp.keyword(), map); @@ -683,7 +690,9 @@ void HelpPluginPrivate::doSetupIfNeeded() { LocalHelpManager::setupGuiHelpEngine(); if (m_setupNeeded) { +#ifndef HELP_NEW_FILTER_ENGINE resetFilter(); +#endif m_setupNeeded = false; m_centralWidget->openPagesManager()->setupInitialPages(); LocalHelpManager::bookmarkManager().setupBookmarkModels(); diff --git a/src/plugins/help/helpwidget.cpp b/src/plugins/help/helpwidget.cpp index e8d85caa181..09e2560e107 100644 --- a/src/plugins/help/helpwidget.cpp +++ b/src/plugins/help/helpwidget.cpp @@ -61,6 +61,11 @@ #include #include +#ifdef HELP_NEW_FILTER_ENGINE +#include +#include +#endif + static const char kWindowSideBarSettingsKey[] = "Help/WindowSideBar"; static const char kModeSideBarSettingsKey[] = "Help/ModeSideBar"; @@ -359,15 +364,24 @@ HelpWidget::HelpWidget(const Core::Context &context, WidgetStyle style, QWidget m_filterComboBox = new QComboBox; m_filterComboBox->setMinimumContentsLength(15); + layout->addWidget(m_filterComboBox); +#ifndef HELP_NEW_FILTER_ENGINE m_filterComboBox->setModel(LocalHelpManager::filterModel()); m_filterComboBox->setCurrentIndex(LocalHelpManager::filterIndex()); - layout->addWidget(m_filterComboBox); connect(m_filterComboBox, QOverload::of(&QComboBox::activated), LocalHelpManager::instance(), &LocalHelpManager::setFilterIndex); connect(LocalHelpManager::instance(), &LocalHelpManager::filterIndexChanged, m_filterComboBox, &QComboBox::setCurrentIndex); +#else + connect(&LocalHelpManager::helpEngine(), &QHelpEngine::setupFinished, + this, &HelpWidget::setupFilterCombo, Qt::QueuedConnection); + connect(m_filterComboBox, QOverload::of(&QComboBox::activated), + this, &HelpWidget::filterDocumentation); + connect(LocalHelpManager::filterEngine(), &QHelpFilterEngine::filterActivated, + this, &HelpWidget::currentFilterChanged); +#endif Core::ActionContainer *windowMenu = Core::ActionManager::actionContainer( Core::Constants::M_WINDOW); @@ -487,6 +501,41 @@ HelpWidget::HelpWidget(const Core::Context &context, WidgetStyle style, QWidget } } +#ifdef HELP_NEW_FILTER_ENGINE + +void HelpWidget::setupFilterCombo() +{ + const QString currentFilter = LocalHelpManager::filterEngine()->activeFilter(); + m_filterComboBox->clear(); + m_filterComboBox->addItem(tr("Unfiltered")); + const QStringList allFilters = LocalHelpManager::filterEngine()->filters(); + if (!allFilters.isEmpty()) + m_filterComboBox->insertSeparator(1); + for (const QString &filter : allFilters) + m_filterComboBox->addItem(filter, filter); + + int idx = m_filterComboBox->findData(currentFilter); + if (idx < 0) + idx = 0; + m_filterComboBox->setCurrentIndex(idx); +} + +void HelpWidget::filterDocumentation(int filterIndex) +{ + const QString filter = m_filterComboBox->itemData(filterIndex).toString(); + LocalHelpManager::filterEngine()->setActiveFilter(filter); +} + +void HelpWidget::currentFilterChanged(const QString &filter) +{ + int index = m_filterComboBox->findData(filter); + if (index < 0) + index = 0; + m_filterComboBox->setCurrentIndex(index); +} + +#endif + HelpWidget::~HelpWidget() { saveState(); @@ -753,7 +802,7 @@ HelpViewer *HelpWidget::openNewPage(const QUrl &url) return page; } -void HelpWidget::showLinks(const QMap &links, +void HelpWidget::showLinks(const QMultiMap &links, const QString &keyword, bool newPage) { if (links.size() < 1) diff --git a/src/plugins/help/helpwidget.h b/src/plugins/help/helpwidget.h index 40cca45e3d4..e79314d940c 100644 --- a/src/plugins/help/helpwidget.h +++ b/src/plugins/help/helpwidget.h @@ -96,7 +96,7 @@ public: void open(const QUrl &url, bool newPage = false); HelpViewer *openNewPage(const QUrl &url); void openFromSearch(const QUrl &url, const QStringList &searchTerms, bool newPage = false); - void showLinks(const QMap &links, const QString &key, + void showLinks(const QMultiMap &links, const QString &key, bool newPage = false); void activateSideBarItem(const QString &id); @@ -142,6 +142,12 @@ private: void addSideBar(); QString sideBarSettingsKey() const; +#ifdef HELP_NEW_FILTER_ENGINE + void setupFilterCombo(); + void filterDocumentation(int filterIndex); + void currentFilterChanged(const QString &filter); +#endif + OpenPagesModel m_model; OpenPagesManager *m_openPagesManager = nullptr; Core::IContext *m_context = nullptr; diff --git a/src/plugins/help/localhelpmanager.cpp b/src/plugins/help/localhelpmanager.cpp index f8a02eb7cc5..100fe940c83 100644 --- a/src/plugins/help/localhelpmanager.cpp +++ b/src/plugins/help/localhelpmanager.cpp @@ -70,10 +70,14 @@ QHelpEngine* LocalHelpManager::m_guiEngine = nullptr; QMutex LocalHelpManager::m_bkmarkMutex; BookmarkManager* LocalHelpManager::m_bookmarkManager = nullptr; +#ifndef HELP_NEW_FILTER_ENGINE + QStandardItemModel *LocalHelpManager::m_filterModel = nullptr; QString LocalHelpManager::m_currentFilter = QString(); int LocalHelpManager::m_currentFilterIndex = -1; +#endif + static const char kHelpHomePageKey[] = "Help/HomePage"; static const char kFontFamilyKey[] = "Help/FallbackFontFamily"; static const char kFontStyleNameKey[] = "Help/FallbackFontStyleName"; @@ -123,7 +127,9 @@ LocalHelpManager::LocalHelpManager(QObject *parent) { m_instance = this; qRegisterMetaType("Help::Internal::LocalHelpManager::HelpData"); +#ifndef HELP_NEW_FILTER_ENGINE m_filterModel = new QStandardItemModel(this); +#endif } LocalHelpManager::~LocalHelpManager() @@ -396,8 +402,12 @@ QHelpEngine &LocalHelpManager::helpEngine() { if (!m_guiEngine) { QMutexLocker _(&m_guiMutex); - if (!m_guiEngine) + if (!m_guiEngine) { m_guiEngine = new QHelpEngine(QString()); +#ifdef HELP_NEW_FILTER_ENGINE + m_guiEngine->setUsesFilterEngine(true); +#endif + } } return *m_guiEngine; } @@ -495,6 +505,8 @@ LocalHelpManager::HelpData LocalHelpManager::helpData(const QUrl &url) return data; } +#ifndef HELP_NEW_FILTER_ENGINE + QAbstractItemModel *LocalHelpManager::filterModel() { return m_filterModel; @@ -544,6 +556,15 @@ void LocalHelpManager::updateFilterModel() emit m_instance->filterIndexChanged(m_currentFilterIndex); } +#else + +QHelpFilterEngine *LocalHelpManager::filterEngine() +{ + return helpEngine().filterEngine(); +} + +#endif + bool LocalHelpManager::canOpenOnlineHelp(const QUrl &url) { const QString address = url.toString(); diff --git a/src/plugins/help/localhelpmanager.h b/src/plugins/help/localhelpmanager.h index c2f5284f59f..aac3a46871f 100644 --- a/src/plugins/help/localhelpmanager.h +++ b/src/plugins/help/localhelpmanager.h @@ -31,9 +31,12 @@ #include #include #include +#ifndef HELP_NEW_FILTER_ENGINE #include - #include +#else +QT_FORWARD_DECLARE_CLASS(QHelpFilterEngine) +#endif QT_FORWARD_DECLARE_CLASS(QHelpEngine) @@ -116,17 +119,23 @@ public: static QByteArray loadErrorMessage(const QUrl &url, const QString &errorString); Q_INVOKABLE static Help::Internal::LocalHelpManager::HelpData helpData(const QUrl &url); +#ifndef HELP_NEW_FILTER_ENGINE static QAbstractItemModel *filterModel(); static void setFilterIndex(int index); static int filterIndex(); static void updateFilterModel(); +#else + static QHelpFilterEngine *filterEngine(); +#endif static bool canOpenOnlineHelp(const QUrl &url); static bool openOnlineHelp(const QUrl &url); signals: +#ifndef HELP_NEW_FILTER_ENGINE void filterIndexChanged(int index); +#endif void fallbackFontChanged(const QFont &font); void returnOnCloseChanged(); void scrollWheelZoomingEnabledChanged(bool enabled); @@ -136,9 +145,11 @@ private: static bool m_guiNeedsSetup; static bool m_needsCollectionFile; +#ifndef HELP_NEW_FILTER_ENGINE static QStandardItemModel *m_filterModel; static QString m_currentFilter; static int m_currentFilterIndex; +#endif static QMutex m_guiMutex; static QHelpEngine *m_guiEngine; diff --git a/src/shared/help/indexwindow.cpp b/src/shared/help/indexwindow.cpp index f55ce3091bb..41eea6c2137 100644 --- a/src/shared/help/indexwindow.cpp +++ b/src/shared/help/indexwindow.cpp @@ -196,7 +196,7 @@ void IndexWindow::disableSearchLineEdit() void IndexWindow::open(const QModelIndex &index, bool newPage) { QString keyword = m_filteredIndexModel->data(index, Qt::DisplayRole).toString(); - QMap links = LocalHelpManager::helpEngine().indexModel()->linksForKeyword(keyword); + QMultiMap links = LocalHelpManager::helpEngine().indexModel()->linksForKeyword(keyword); emit linksActivated(links, keyword, newPage); } diff --git a/src/shared/help/indexwindow.h b/src/shared/help/indexwindow.h index 1b44c1f5768..8b1dec0872d 100644 --- a/src/shared/help/indexwindow.h +++ b/src/shared/help/indexwindow.h @@ -88,7 +88,7 @@ public: void setOpenInNewPageActionVisible(bool visible); signals: - void linksActivated(const QMap &links, + void linksActivated(const QMultiMap &links, const QString &keyword, bool newPage); private: diff --git a/src/shared/help/topicchooser.cpp b/src/shared/help/topicchooser.cpp index b7e5db7f3fe..44852da95bb 100644 --- a/src/shared/help/topicchooser.cpp +++ b/src/shared/help/topicchooser.cpp @@ -33,7 +33,7 @@ #include TopicChooser::TopicChooser(QWidget *parent, const QString &keyword, - const QMap &links) + const QMultiMap &links) : QDialog(parent) , m_filterModel(new QSortFilterProxyModel(this)) { @@ -49,7 +49,7 @@ TopicChooser::TopicChooser(QWidget *parent, const QString &keyword, m_filterModel->setSourceModel(model); m_filterModel->setFilterCaseSensitivity(Qt::CaseInsensitive); - QMap::const_iterator it = links.constBegin(); + QMultiMap::const_iterator it = links.constBegin(); for (; it != links.constEnd(); ++it) { m_links.append(it.value()); QStandardItem *item = new QStandardItem(it.key()); diff --git a/src/shared/help/topicchooser.h b/src/shared/help/topicchooser.h index 88c6fa90b64..8f278428c71 100644 --- a/src/shared/help/topicchooser.h +++ b/src/shared/help/topicchooser.h @@ -42,7 +42,7 @@ class TopicChooser : public QDialog public: TopicChooser(QWidget *parent, const QString &keyword, - const QMap &links); + const QMultiMap &links); QUrl link() const;