Integrate new filter engine

Adapt the code to deprecated usage of map as a multi map,
hence all cases replaced by QMultiMap.

Change-Id: I2d480467cd6e91d3e880555e6a21058dec056b3f
Reviewed-by: Karsten Heimrich <karsten.heimrich@qt.io>
This commit is contained in:
Jarek Kobus
2019-10-16 13:28:28 +02:00
parent bf6ecbb042
commit 9ca7326d90
21 changed files with 352 additions and 36 deletions

View File

@@ -211,7 +211,7 @@ const HelpItem::Links &HelpItem::links() const
m_helpLinks.emplace(Links{{m_keyword, m_helpUrl}}); m_helpLinks.emplace(Links{{m_keyword, m_helpUrl}});
} else { } else {
m_helpLinks.emplace(); // set a value even if there are no help IDs m_helpLinks.emplace(); // set a value even if there are no help IDs
QMap<QString, QUrl> helpLinks; QMultiMap<QString, QUrl> helpLinks;
for (const QString &id : m_helpIds) { for (const QString &id : m_helpIds) {
helpLinks = Core::HelpManager::linksForIdentifier(id); helpLinks = Core::HelpManager::linksForIdentifier(id);
if (!helpLinks.isEmpty()) { if (!helpLinks.isEmpty()) {

View File

@@ -86,14 +86,14 @@ void unregisterDocumentation(const QStringList &fileNames)
m_instance->unregisterDocumentation(fileNames); m_instance->unregisterDocumentation(fileNames);
} }
QMap<QString, QUrl> linksForIdentifier(const QString &id) QMultiMap<QString, QUrl> linksForIdentifier(const QString &id)
{ {
return checkInstance() ? m_instance->linksForIdentifier(id) : QMap<QString, QUrl>(); return checkInstance() ? m_instance->linksForIdentifier(id) : QMultiMap<QString, QUrl>();
} }
QMap<QString, QUrl> linksForKeyword(const QString &keyword) QMultiMap<QString, QUrl> linksForKeyword(const QString &keyword)
{ {
return checkInstance() ? m_instance->linksForKeyword(keyword) : QMap<QString, QUrl>(); return checkInstance() ? m_instance->linksForKeyword(keyword) : QMultiMap<QString, QUrl>();
} }
QByteArray fileData(const QUrl &url) QByteArray fileData(const QUrl &url)

View File

@@ -63,8 +63,8 @@ CORE_EXPORT QString documentationPath();
CORE_EXPORT void registerDocumentation(const QStringList &fileNames); CORE_EXPORT void registerDocumentation(const QStringList &fileNames);
CORE_EXPORT void unregisterDocumentation(const QStringList &fileNames); CORE_EXPORT void unregisterDocumentation(const QStringList &fileNames);
CORE_EXPORT QMap<QString, QUrl> linksForIdentifier(const QString &id); CORE_EXPORT QMultiMap<QString, QUrl> linksForIdentifier(const QString &id);
CORE_EXPORT QMap<QString, QUrl> linksForKeyword(const QString &id); CORE_EXPORT QMultiMap<QString, QUrl> linksForKeyword(const QString &id);
CORE_EXPORT QByteArray fileData(const QUrl &url); CORE_EXPORT QByteArray fileData(const QUrl &url);
CORE_EXPORT void showHelpUrl(const QUrl &url, HelpViewerLocation location = HelpModeAlways); CORE_EXPORT void showHelpUrl(const QUrl &url, HelpViewerLocation location = HelpModeAlways);

View File

@@ -40,8 +40,8 @@ protected:
public: public:
virtual void registerDocumentation(const QStringList &fileNames) = 0; virtual void registerDocumentation(const QStringList &fileNames) = 0;
virtual void unregisterDocumentation(const QStringList &fileNames) = 0; virtual void unregisterDocumentation(const QStringList &fileNames) = 0;
virtual QMap<QString, QUrl> linksForIdentifier(const QString &id) = 0; virtual QMultiMap<QString, QUrl> linksForIdentifier(const QString &id) = 0;
virtual QMap<QString, QUrl> linksForKeyword(const QString &keyword) = 0; virtual QMultiMap<QString, QUrl> linksForKeyword(const QString &keyword) = 0;
virtual QByteArray fileData(const QUrl &url) = 0; virtual QByteArray fileData(const QUrl &url) = 0;
virtual void showHelpUrl(const QUrl &url, HelpViewerLocation location = HelpModeAlways) = 0; virtual void showHelpUrl(const QUrl &url, HelpViewerLocation location = HelpModeAlways) = 0;
}; };

View File

@@ -24,8 +24,10 @@
****************************************************************************/ ****************************************************************************/
#include "filtersettingspage.h" #include "filtersettingspage.h"
#include "helpconstants.h" #include "helpconstants.h"
#ifndef HELP_NEW_FILTER_ENGINE
#include "helpmanager.h" #include "helpmanager.h"
#include <filternamedialog.h> #include <filternamedialog.h>
@@ -38,6 +40,15 @@
#include <QFileDialog> #include <QFileDialog>
#include <QMessageBox> #include <QMessageBox>
#else
#include <QtCore/QVersionNumber>
#include <QtHelp/QHelpFilterEngine>
#include <QtHelp/QHelpFilterSettingsWidget>
#include "localhelpmanager.h"
#endif
using namespace Help::Internal; using namespace Help::Internal;
FilterSettingsPage::FilterSettingsPage() FilterSettingsPage::FilterSettingsPage()
@@ -47,6 +58,8 @@ FilterSettingsPage::FilterSettingsPage()
setCategory(Help::Constants::HELP_CATEGORY); setCategory(Help::Constants::HELP_CATEGORY);
} }
#ifndef HELP_NEW_FILTER_ENGINE
QWidget *FilterSettingsPage::widget() QWidget *FilterSettingsPage::widget()
{ {
if (!m_widget) { if (!m_widget) {
@@ -254,3 +267,48 @@ void FilterSettingsPage::updateFilterDescription(const QString &filter)
{ {
m_ui.label->setText(msgFilterLabel(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

View File

@@ -25,11 +25,16 @@
#pragma once #pragma once
#include "ui_filtersettingspage.h"
#include <coreplugin/dialogs/ioptionspage.h> #include <coreplugin/dialogs/ioptionspage.h>
#include <QPointer> #include <QPointer>
#ifndef HELP_NEW_FILTER_ENGINE
#include "ui_filtersettingspage.h"
#else
class QHelpFilterSettingsWidget;
#endif
namespace Help { namespace Help {
namespace Internal { namespace Internal {
@@ -48,9 +53,11 @@ signals:
void filtersChanged(); void filtersChanged();
private: private:
void updateFilterPage();
#ifndef HELP_NEW_FILTER_ENGINE
void updateAttributes(QListWidgetItem *item); void updateAttributes(QListWidgetItem *item);
void updateFilterMap(); void updateFilterMap();
void updateFilterPage();
void addFilter(); void addFilter();
void removeFilter(); void removeFilter();
void updateFilterDescription(const QString &filter); void updateFilterDescription(const QString &filter);
@@ -64,6 +71,10 @@ private:
FilterMap m_filterMapBackup; FilterMap m_filterMapBackup;
QStringList m_removedFilters; QStringList m_removedFilters;
#else
QPointer<QHelpFilterSettingsWidget> m_widget;
#endif
}; };
} // namespace Help } // namespace Help

View File

@@ -4,6 +4,10 @@ INCLUDEPATH += $$PWD
include(../../qtcreatorplugin.pri) include(../../qtcreatorplugin.pri)
minQtVersion(5, 15, 0) {
DEFINES += HELP_NEW_FILTER_ENGINE
}
DEFINES += \ DEFINES += \
QT_CLUCENE_SUPPORT \ QT_CLUCENE_SUPPORT \
HELP_LIBRARY HELP_LIBRARY

View File

@@ -1,4 +1,4 @@
import qbs 1.0 import qbs.Utilities
Project { Project {
name: "Help" name: "Help"
@@ -28,6 +28,8 @@ Project {
defines.push("QTC_WEBENGINE_HELPVIEWER"); defines.push("QTC_WEBENGINE_HELPVIEWER");
if (qlitehtml.present) if (qlitehtml.present)
defines.push("QTC_LITEHTML_HELPVIEWER") defines.push("QTC_LITEHTML_HELPVIEWER")
if (Utilities.versionCompare(Qt.core.version, "5.15") >= 0)
defines.push("HELP_NEW_FILTER_ENGINE");
return defines; return defines;
} }

View File

@@ -32,15 +32,27 @@
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <coreplugin/helpmanager.h> #include <coreplugin/helpmanager.h>
#include <extensionsystem/pluginmanager.h> #include <extensionsystem/pluginmanager.h>
#include <utils/algorithm.h>
#include <utils/utilsicons.h> #include <utils/utilsicons.h>
#include <QIcon> #include <QIcon>
#ifndef HELP_NEW_FILTER_ENGINE
#include <utils/algorithm.h>
#include <QSqlDatabase> #include <QSqlDatabase>
#include <QSqlDriver> #include <QSqlDriver>
#include <QSqlError> #include <QSqlError>
#include <QSqlQuery> #include <QSqlQuery>
#else
#include "localhelpmanager.h"
#include <QtHelp/QHelpEngine>
#include <QtHelp/QHelpFilterEngine>
#include <QtHelp/QHelpLink>
#endif
using namespace Core; using namespace Core;
using namespace Help; using namespace Help;
@@ -66,6 +78,8 @@ HelpIndexFilter::HelpIndexFilter()
HelpIndexFilter::~HelpIndexFilter() = default; HelpIndexFilter::~HelpIndexFilter() = default;
#ifndef HELP_NEW_FILTER_ENGINE
void HelpIndexFilter::prepareSearch(const QString &entry) void HelpIndexFilter::prepareSearch(const QString &entry)
{ {
Q_UNUSED(entry) Q_UNUSED(entry)
@@ -133,6 +147,70 @@ QList<LocatorFilterEntry> HelpIndexFilter::matchesFor(QFutureInterface<LocatorFi
return entries; 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, void HelpIndexFilter::accept(LocatorFilterEntry selection,
QString *newText, int *selectionStart, int *selectionLength) const QString *newText, int *selectionStart, int *selectionLength) const
{ {
@@ -140,7 +218,14 @@ void HelpIndexFilter::accept(LocatorFilterEntry selection,
Q_UNUSED(selectionStart) Q_UNUSED(selectionStart)
Q_UNUSED(selectionLength) Q_UNUSED(selectionLength)
const QString &key = selection.displayName; 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); emit linksActivated(links, key);
} }
@@ -150,6 +235,8 @@ void HelpIndexFilter::refresh(QFutureInterface<void> &future)
invalidateCache(); invalidateCache();
} }
#ifndef HELP_NEW_FILTER_ENGINE
QSet<QString> HelpIndexFilter::searchMatches(const QString &databaseFilePath, QSet<QString> HelpIndexFilter::searchMatches(const QString &databaseFilePath,
const QString &term, int limit) const QString &term, int limit)
{ {
@@ -180,6 +267,16 @@ QSet<QString> HelpIndexFilter::searchMatches(const QString &databaseFilePath,
return keywords; return keywords;
} }
#else
QStringList HelpIndexFilter::allIndices() const
{
LocalHelpManager::setupGuiHelpEngine();
return LocalHelpManager::filterEngine()->indices(QString());
}
#endif
void HelpIndexFilter::invalidateCache() void HelpIndexFilter::invalidateCache()
{ {
m_mutex.lock(); m_mutex.lock();

View File

@@ -42,24 +42,38 @@ public:
~HelpIndexFilter() final; ~HelpIndexFilter() final;
// ILocatorFilter // ILocatorFilter
void prepareSearch(const QString &entry) override;
QList<Core::LocatorFilterEntry> matchesFor(QFutureInterface<Core::LocatorFilterEntry> &future, QList<Core::LocatorFilterEntry> matchesFor(QFutureInterface<Core::LocatorFilterEntry> &future,
const QString &entry) override; const QString &entry) override;
void accept(Core::LocatorFilterEntry selection, void accept(Core::LocatorFilterEntry selection,
QString *newText, int *selectionStart, int *selectionLength) const override; QString *newText, int *selectionStart, int *selectionLength) const override;
void refresh(QFutureInterface<void> &future) override; void refresh(QFutureInterface<void> &future) override;
#ifndef HELP_NEW_FILTER_ENGINE
void prepareSearch(const QString &entry) override;
Q_INVOKABLE QSet<QString> searchMatches(const QString &databaseFilePath, Q_INVOKABLE QSet<QString> searchMatches(const QString &databaseFilePath,
const QString &term, int limit); const QString &term, int limit);
#else
Q_INVOKABLE QStringList allIndices() const;
#endif
signals: signals:
void linksActivated(const QMap<QString, QUrl> &links, const QString &key) const; void linksActivated(const QMultiMap<QString, QUrl> &links, const QString &key) const;
private: private:
void invalidateCache(); void invalidateCache();
#ifndef HELP_NEW_FILTER_ENGINE
QStringList m_helpDatabases; QStringList m_helpDatabases;
QSet<QString> m_keywordCache; QSet<QString> m_keywordCache;
QString m_searchTermCache; QString m_searchTermCache;
#else
bool updateCache(QFutureInterface<Core::LocatorFilterEntry> &future,
const QStringList &cache, const QString &entry);
QStringList m_allIndicesCache;
QStringList m_lastIndicesCache;
QString m_lastEntry;
#endif
bool m_needsUpdate = true; bool m_needsUpdate = true;
QMutex m_mutex; QMutex m_mutex;
QIcon m_icon; QIcon m_icon;

View File

@@ -43,10 +43,15 @@
#include <QHelpEngineCore> #include <QHelpEngineCore>
#include <QMutexLocker> #include <QMutexLocker>
#ifndef HELP_NEW_FILTER_ENGINE
#include <QSqlDatabase> #include <QSqlDatabase>
#include <QSqlDriver> #include <QSqlDriver>
#include <QSqlError> #include <QSqlError>
#include <QSqlQuery> #include <QSqlQuery>
#else
#include <QtHelp/QHelpLink>
#endif
using namespace Core; using namespace Core;
@@ -84,6 +89,8 @@ struct HelpManagerPrivate
static HelpManager *m_instance = nullptr; static HelpManager *m_instance = nullptr;
static HelpManagerPrivate *d = nullptr; static HelpManagerPrivate *d = nullptr;
#ifndef HELP_NEW_FILTER_ENGINE
// -- DbCleaner // -- DbCleaner
struct DbCleaner struct DbCleaner
@@ -93,6 +100,8 @@ struct DbCleaner
QString name; QString name;
}; };
#endif
// -- HelpManager // -- HelpManager
HelpManager::HelpManager(QObject *parent) : HelpManager::HelpManager(QObject *parent) :
@@ -225,20 +234,36 @@ QSet<QString> HelpManager::userDocumentationPaths()
} }
// This should go into Qt 4.8 once we start using it for Qt Creator // This should go into Qt 4.8 once we start using it for Qt Creator
QMap<QString, QUrl> HelpManager::linksForKeyword(const QString &key) QMultiMap<QString, QUrl> HelpManager::linksForKeyword(const QString &key)
{ {
QTC_ASSERT(!d->m_needsSetup, return {}); QTC_ASSERT(!d->m_needsSetup, return {});
if (key.isEmpty()) if (key.isEmpty())
return {}; return {};
#ifndef HELP_NEW_FILTER_ENGINE
return d->m_helpEngine->linksForKeyword(key); return d->m_helpEngine->linksForKeyword(key);
#else
QMultiMap<QString, QUrl> links;
const QList<QHelpLink> docs = d->m_helpEngine->documentsForKeyword(key, QString());
for (const auto doc : docs)
links.insert(doc.title, doc.url);
return links;
#endif
} }
QMap<QString, QUrl> HelpManager::linksForIdentifier(const QString &id) QMultiMap<QString, QUrl> HelpManager::linksForIdentifier(const QString &id)
{ {
QTC_ASSERT(!d->m_needsSetup, return {}); QTC_ASSERT(!d->m_needsSetup, return {});
if (id.isEmpty()) if (id.isEmpty())
return {}; return {};
#ifndef HELP_NEW_FILTER_ENGINE
return d->m_helpEngine->linksForIdentifier(id); return d->m_helpEngine->linksForIdentifier(id);
#else
QMultiMap<QString, QUrl> links;
const QList<QHelpLink> 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) 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); return d->m_helpEngine->customValue(key, value);
} }
#ifndef HELP_NEW_FILTER_ENGINE
HelpManager::Filters HelpManager::filters() HelpManager::Filters HelpManager::filters()
{ {
QTC_ASSERT(!d->m_needsSetup, return {}); QTC_ASSERT(!d->m_needsSetup, return {});
@@ -358,6 +385,8 @@ void HelpManager::addUserDefinedFilter(const QString &filter, const QStringList
emit m_instance->collectionFileChanged(); emit m_instance->collectionFileChanged();
} }
#endif
void HelpManager::aboutToShutdown() void HelpManager::aboutToShutdown()
{ {
if (d && d->m_registerFuture.isRunning()) { if (d && d->m_registerFuture.isRunning()) {
@@ -378,6 +407,9 @@ void HelpManager::setupHelpManager()
// create the help engine // create the help engine
d->m_helpEngine = new QHelpEngineCore(collectionFilePath(), m_instance); d->m_helpEngine = new QHelpEngineCore(collectionFilePath(), m_instance);
#ifdef HELP_NEW_FILTER_ENGINE
d->m_helpEngine->setUsesFilterEngine(true);
#endif
d->m_helpEngine->setupData(); d->m_helpEngine->setupData();
for (const QString &filePath : d->documentationFromInstaller()) for (const QString &filePath : d->documentationFromInstaller())

View File

@@ -40,8 +40,6 @@ class HelpManager : public QObject, public Core::HelpManager::Implementation
Q_OBJECT Q_OBJECT
public: public:
using Filters = QHash<QString, QStringList>;
explicit HelpManager(QObject *parent = nullptr); explicit HelpManager(QObject *parent = nullptr);
~HelpManager() override; ~HelpManager() override;
@@ -56,8 +54,8 @@ public:
static void registerUserDocumentation(const QStringList &filePaths); static void registerUserDocumentation(const QStringList &filePaths);
static QSet<QString> userDocumentationPaths(); static QSet<QString> userDocumentationPaths();
QMap<QString, QUrl> linksForIdentifier(const QString &id) override; QMultiMap<QString, QUrl> linksForIdentifier(const QString &id) override;
QMap<QString, QUrl> linksForKeyword(const QString &key) override; QMultiMap<QString, QUrl> linksForKeyword(const QString &key) override;
static QUrl findFile(const QUrl &url); static QUrl findFile(const QUrl &url);
QByteArray fileData(const QUrl &url) override; QByteArray fileData(const QUrl &url) override;
@@ -69,12 +67,16 @@ public:
static void setCustomValue(const QString &key, const QVariant &value); static void setCustomValue(const QString &key, const QVariant &value);
static QVariant customValue(const QString &key, const QVariant &value = QVariant()); static QVariant customValue(const QString &key, const QVariant &value = QVariant());
#ifndef HELP_NEW_FILTER_ENGINE
using Filters = QHash<QString, QStringList>;
static Filters filters(); static Filters filters();
static Filters fixedFilters(); static Filters fixedFilters();
static Filters userDefinedFilters(); static Filters userDefinedFilters();
static void removeUserDefinedFilter(const QString &filter); static void removeUserDefinedFilter(const QString &filter);
static void addUserDefinedFilter(const QString &filter, const QStringList &attr); static void addUserDefinedFilter(const QString &filter, const QStringList &attr);
#endif
static void aboutToShutdown(); static void aboutToShutdown();

View File

@@ -116,7 +116,7 @@ public:
void activateContents(); void activateContents();
void saveExternalWindowSettings(); void saveExternalWindowSettings();
void showLinksInCurrentViewer(const QMap<QString, QUrl> &links, const QString &key); void showLinksInCurrentViewer(const QMultiMap<QString, QUrl> &links, const QString &key);
void setupHelpEngineIfNeeded(); void setupHelpEngineIfNeeded();
@@ -124,7 +124,10 @@ public:
void slotSystemInformation(); void slotSystemInformation();
#ifndef HELP_NEW_FILTER_ENGINE
void resetFilter(); void resetFilter();
#endif
static void activateHelpMode() { ModeManager::activateMode(Constants::ID_MODE_HELP); } static void activateHelpMode() { ModeManager::activateMode(Constants::ID_MODE_HELP); }
static bool canShowHelpSideBySide(); static bool canShowHelpSideBySide();
@@ -314,6 +317,8 @@ ExtensionSystem::IPlugin::ShutdownFlag HelpPlugin::aboutToShutdown()
return SynchronousShutdown; return SynchronousShutdown;
} }
#ifndef HELP_NEW_FILTER_ENGINE
void HelpPluginPrivate::resetFilter() void HelpPluginPrivate::resetFilter()
{ {
const QString &filterInternal = QString::fromLatin1("Qt Creator %1.%2.%3") const QString &filterInternal = QString::fromLatin1("Qt Creator %1.%2.%3")
@@ -348,6 +353,8 @@ void HelpPluginPrivate::resetFilter()
LocalHelpManager::instance(), &LocalHelpManager::updateFilterModel); LocalHelpManager::instance(), &LocalHelpManager::updateFilterModel);
} }
#endif
void HelpPluginPrivate::saveExternalWindowSettings() void HelpPluginPrivate::saveExternalWindowSettings()
{ {
if (!m_externalWindow) if (!m_externalWindow)
@@ -436,7 +443,7 @@ HelpWidget *HelpPlugin::modeHelpWidget()
return dd->m_centralWidget; return dd->m_centralWidget;
} }
void HelpPluginPrivate::showLinksInCurrentViewer(const QMap<QString, QUrl> &links, const QString &key) void HelpPluginPrivate::showLinksInCurrentViewer(const QMultiMap<QString, QUrl> &links, const QString &key)
{ {
if (links.size() < 1) if (links.size() < 1)
return; return;
@@ -577,7 +584,7 @@ void HelpPluginPrivate::showContextHelp(const HelpItem &contextHelp)
} else if (links.size() == 1 && !contextHelp.isFuzzyMatch()) { } else if (links.size() == 1 && !contextHelp.isFuzzyMatch()) {
showHelpUrl(links.front().second, LocalHelpManager::contextHelpOption()); showHelpUrl(links.front().second, LocalHelpManager::contextHelpOption());
} else { } else {
QMap<QString, QUrl> map; QMultiMap<QString, QUrl> map;
for (const HelpItem::Link &link : links) for (const HelpItem::Link &link : links)
map.insert(link.first, link.second); map.insert(link.first, link.second);
auto tc = new TopicChooser(ICore::dialogParent(), contextHelp.keyword(), map); auto tc = new TopicChooser(ICore::dialogParent(), contextHelp.keyword(), map);
@@ -683,7 +690,9 @@ void HelpPluginPrivate::doSetupIfNeeded()
{ {
LocalHelpManager::setupGuiHelpEngine(); LocalHelpManager::setupGuiHelpEngine();
if (m_setupNeeded) { if (m_setupNeeded) {
#ifndef HELP_NEW_FILTER_ENGINE
resetFilter(); resetFilter();
#endif
m_setupNeeded = false; m_setupNeeded = false;
m_centralWidget->openPagesManager()->setupInitialPages(); m_centralWidget->openPagesManager()->setupInitialPages();
LocalHelpManager::bookmarkManager().setupBookmarkModels(); LocalHelpManager::bookmarkManager().setupBookmarkModels();

View File

@@ -61,6 +61,11 @@
#include <QStatusBar> #include <QStatusBar>
#include <QToolButton> #include <QToolButton>
#ifdef HELP_NEW_FILTER_ENGINE
#include <QtHelp/QHelpEngine>
#include <QtHelp/QHelpFilterEngine>
#endif
static const char kWindowSideBarSettingsKey[] = "Help/WindowSideBar"; static const char kWindowSideBarSettingsKey[] = "Help/WindowSideBar";
static const char kModeSideBarSettingsKey[] = "Help/ModeSideBar"; 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 = new QComboBox;
m_filterComboBox->setMinimumContentsLength(15); m_filterComboBox->setMinimumContentsLength(15);
layout->addWidget(m_filterComboBox);
#ifndef HELP_NEW_FILTER_ENGINE
m_filterComboBox->setModel(LocalHelpManager::filterModel()); m_filterComboBox->setModel(LocalHelpManager::filterModel());
m_filterComboBox->setCurrentIndex(LocalHelpManager::filterIndex()); m_filterComboBox->setCurrentIndex(LocalHelpManager::filterIndex());
layout->addWidget(m_filterComboBox);
connect(m_filterComboBox, QOverload<int>::of(&QComboBox::activated), connect(m_filterComboBox, QOverload<int>::of(&QComboBox::activated),
LocalHelpManager::instance(), &LocalHelpManager::setFilterIndex); LocalHelpManager::instance(), &LocalHelpManager::setFilterIndex);
connect(LocalHelpManager::instance(), connect(LocalHelpManager::instance(),
&LocalHelpManager::filterIndexChanged, &LocalHelpManager::filterIndexChanged,
m_filterComboBox, m_filterComboBox,
&QComboBox::setCurrentIndex); &QComboBox::setCurrentIndex);
#else
connect(&LocalHelpManager::helpEngine(), &QHelpEngine::setupFinished,
this, &HelpWidget::setupFilterCombo, Qt::QueuedConnection);
connect(m_filterComboBox, QOverload<int>::of(&QComboBox::activated),
this, &HelpWidget::filterDocumentation);
connect(LocalHelpManager::filterEngine(), &QHelpFilterEngine::filterActivated,
this, &HelpWidget::currentFilterChanged);
#endif
Core::ActionContainer *windowMenu = Core::ActionManager::actionContainer( Core::ActionContainer *windowMenu = Core::ActionManager::actionContainer(
Core::Constants::M_WINDOW); 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() HelpWidget::~HelpWidget()
{ {
saveState(); saveState();
@@ -753,7 +802,7 @@ HelpViewer *HelpWidget::openNewPage(const QUrl &url)
return page; return page;
} }
void HelpWidget::showLinks(const QMap<QString, QUrl> &links, void HelpWidget::showLinks(const QMultiMap<QString, QUrl> &links,
const QString &keyword, bool newPage) const QString &keyword, bool newPage)
{ {
if (links.size() < 1) if (links.size() < 1)

View File

@@ -96,7 +96,7 @@ public:
void open(const QUrl &url, bool newPage = false); void open(const QUrl &url, bool newPage = false);
HelpViewer *openNewPage(const QUrl &url); HelpViewer *openNewPage(const QUrl &url);
void openFromSearch(const QUrl &url, const QStringList &searchTerms, bool newPage = false); void openFromSearch(const QUrl &url, const QStringList &searchTerms, bool newPage = false);
void showLinks(const QMap<QString, QUrl> &links, const QString &key, void showLinks(const QMultiMap<QString, QUrl> &links, const QString &key,
bool newPage = false); bool newPage = false);
void activateSideBarItem(const QString &id); void activateSideBarItem(const QString &id);
@@ -142,6 +142,12 @@ private:
void addSideBar(); void addSideBar();
QString sideBarSettingsKey() const; QString sideBarSettingsKey() const;
#ifdef HELP_NEW_FILTER_ENGINE
void setupFilterCombo();
void filterDocumentation(int filterIndex);
void currentFilterChanged(const QString &filter);
#endif
OpenPagesModel m_model; OpenPagesModel m_model;
OpenPagesManager *m_openPagesManager = nullptr; OpenPagesManager *m_openPagesManager = nullptr;
Core::IContext *m_context = nullptr; Core::IContext *m_context = nullptr;

View File

@@ -70,10 +70,14 @@ QHelpEngine* LocalHelpManager::m_guiEngine = nullptr;
QMutex LocalHelpManager::m_bkmarkMutex; QMutex LocalHelpManager::m_bkmarkMutex;
BookmarkManager* LocalHelpManager::m_bookmarkManager = nullptr; BookmarkManager* LocalHelpManager::m_bookmarkManager = nullptr;
#ifndef HELP_NEW_FILTER_ENGINE
QStandardItemModel *LocalHelpManager::m_filterModel = nullptr; QStandardItemModel *LocalHelpManager::m_filterModel = nullptr;
QString LocalHelpManager::m_currentFilter = QString(); QString LocalHelpManager::m_currentFilter = QString();
int LocalHelpManager::m_currentFilterIndex = -1; int LocalHelpManager::m_currentFilterIndex = -1;
#endif
static const char kHelpHomePageKey[] = "Help/HomePage"; static const char kHelpHomePageKey[] = "Help/HomePage";
static const char kFontFamilyKey[] = "Help/FallbackFontFamily"; static const char kFontFamilyKey[] = "Help/FallbackFontFamily";
static const char kFontStyleNameKey[] = "Help/FallbackFontStyleName"; static const char kFontStyleNameKey[] = "Help/FallbackFontStyleName";
@@ -123,7 +127,9 @@ LocalHelpManager::LocalHelpManager(QObject *parent)
{ {
m_instance = this; m_instance = this;
qRegisterMetaType<Help::Internal::LocalHelpManager::HelpData>("Help::Internal::LocalHelpManager::HelpData"); qRegisterMetaType<Help::Internal::LocalHelpManager::HelpData>("Help::Internal::LocalHelpManager::HelpData");
#ifndef HELP_NEW_FILTER_ENGINE
m_filterModel = new QStandardItemModel(this); m_filterModel = new QStandardItemModel(this);
#endif
} }
LocalHelpManager::~LocalHelpManager() LocalHelpManager::~LocalHelpManager()
@@ -396,8 +402,12 @@ QHelpEngine &LocalHelpManager::helpEngine()
{ {
if (!m_guiEngine) { if (!m_guiEngine) {
QMutexLocker _(&m_guiMutex); QMutexLocker _(&m_guiMutex);
if (!m_guiEngine) if (!m_guiEngine) {
m_guiEngine = new QHelpEngine(QString()); m_guiEngine = new QHelpEngine(QString());
#ifdef HELP_NEW_FILTER_ENGINE
m_guiEngine->setUsesFilterEngine(true);
#endif
}
} }
return *m_guiEngine; return *m_guiEngine;
} }
@@ -495,6 +505,8 @@ LocalHelpManager::HelpData LocalHelpManager::helpData(const QUrl &url)
return data; return data;
} }
#ifndef HELP_NEW_FILTER_ENGINE
QAbstractItemModel *LocalHelpManager::filterModel() QAbstractItemModel *LocalHelpManager::filterModel()
{ {
return m_filterModel; return m_filterModel;
@@ -544,6 +556,15 @@ void LocalHelpManager::updateFilterModel()
emit m_instance->filterIndexChanged(m_currentFilterIndex); emit m_instance->filterIndexChanged(m_currentFilterIndex);
} }
#else
QHelpFilterEngine *LocalHelpManager::filterEngine()
{
return helpEngine().filterEngine();
}
#endif
bool LocalHelpManager::canOpenOnlineHelp(const QUrl &url) bool LocalHelpManager::canOpenOnlineHelp(const QUrl &url)
{ {
const QString address = url.toString(); const QString address = url.toString();

View File

@@ -31,9 +31,12 @@
#include <QMutex> #include <QMutex>
#include <QObject> #include <QObject>
#include <QUrl> #include <QUrl>
#ifndef HELP_NEW_FILTER_ENGINE
#include <QStandardItemModel> #include <QStandardItemModel>
#include <functional> #include <functional>
#else
QT_FORWARD_DECLARE_CLASS(QHelpFilterEngine)
#endif
QT_FORWARD_DECLARE_CLASS(QHelpEngine) QT_FORWARD_DECLARE_CLASS(QHelpEngine)
@@ -116,17 +119,23 @@ public:
static QByteArray loadErrorMessage(const QUrl &url, const QString &errorString); static QByteArray loadErrorMessage(const QUrl &url, const QString &errorString);
Q_INVOKABLE static Help::Internal::LocalHelpManager::HelpData helpData(const QUrl &url); Q_INVOKABLE static Help::Internal::LocalHelpManager::HelpData helpData(const QUrl &url);
#ifndef HELP_NEW_FILTER_ENGINE
static QAbstractItemModel *filterModel(); static QAbstractItemModel *filterModel();
static void setFilterIndex(int index); static void setFilterIndex(int index);
static int filterIndex(); static int filterIndex();
static void updateFilterModel(); static void updateFilterModel();
#else
static QHelpFilterEngine *filterEngine();
#endif
static bool canOpenOnlineHelp(const QUrl &url); static bool canOpenOnlineHelp(const QUrl &url);
static bool openOnlineHelp(const QUrl &url); static bool openOnlineHelp(const QUrl &url);
signals: signals:
#ifndef HELP_NEW_FILTER_ENGINE
void filterIndexChanged(int index); void filterIndexChanged(int index);
#endif
void fallbackFontChanged(const QFont &font); void fallbackFontChanged(const QFont &font);
void returnOnCloseChanged(); void returnOnCloseChanged();
void scrollWheelZoomingEnabledChanged(bool enabled); void scrollWheelZoomingEnabledChanged(bool enabled);
@@ -136,9 +145,11 @@ private:
static bool m_guiNeedsSetup; static bool m_guiNeedsSetup;
static bool m_needsCollectionFile; static bool m_needsCollectionFile;
#ifndef HELP_NEW_FILTER_ENGINE
static QStandardItemModel *m_filterModel; static QStandardItemModel *m_filterModel;
static QString m_currentFilter; static QString m_currentFilter;
static int m_currentFilterIndex; static int m_currentFilterIndex;
#endif
static QMutex m_guiMutex; static QMutex m_guiMutex;
static QHelpEngine *m_guiEngine; static QHelpEngine *m_guiEngine;

View File

@@ -196,7 +196,7 @@ void IndexWindow::disableSearchLineEdit()
void IndexWindow::open(const QModelIndex &index, bool newPage) void IndexWindow::open(const QModelIndex &index, bool newPage)
{ {
QString keyword = m_filteredIndexModel->data(index, Qt::DisplayRole).toString(); QString keyword = m_filteredIndexModel->data(index, Qt::DisplayRole).toString();
QMap<QString, QUrl> links = LocalHelpManager::helpEngine().indexModel()->linksForKeyword(keyword); QMultiMap<QString, QUrl> links = LocalHelpManager::helpEngine().indexModel()->linksForKeyword(keyword);
emit linksActivated(links, keyword, newPage); emit linksActivated(links, keyword, newPage);
} }

View File

@@ -88,7 +88,7 @@ public:
void setOpenInNewPageActionVisible(bool visible); void setOpenInNewPageActionVisible(bool visible);
signals: signals:
void linksActivated(const QMap<QString, QUrl> &links, void linksActivated(const QMultiMap<QString, QUrl> &links,
const QString &keyword, bool newPage); const QString &keyword, bool newPage);
private: private:

View File

@@ -33,7 +33,7 @@
#include <QSortFilterProxyModel> #include <QSortFilterProxyModel>
TopicChooser::TopicChooser(QWidget *parent, const QString &keyword, TopicChooser::TopicChooser(QWidget *parent, const QString &keyword,
const QMap<QString, QUrl> &links) const QMultiMap<QString, QUrl> &links)
: QDialog(parent) : QDialog(parent)
, m_filterModel(new QSortFilterProxyModel(this)) , m_filterModel(new QSortFilterProxyModel(this))
{ {
@@ -49,7 +49,7 @@ TopicChooser::TopicChooser(QWidget *parent, const QString &keyword,
m_filterModel->setSourceModel(model); m_filterModel->setSourceModel(model);
m_filterModel->setFilterCaseSensitivity(Qt::CaseInsensitive); m_filterModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
QMap<QString, QUrl>::const_iterator it = links.constBegin(); QMultiMap<QString, QUrl>::const_iterator it = links.constBegin();
for (; it != links.constEnd(); ++it) { for (; it != links.constEnd(); ++it) {
m_links.append(it.value()); m_links.append(it.value());
QStandardItem *item = new QStandardItem(it.key()); QStandardItem *item = new QStandardItem(it.key());

View File

@@ -42,7 +42,7 @@ class TopicChooser : public QDialog
public: public:
TopicChooser(QWidget *parent, const QString &keyword, TopicChooser(QWidget *parent, const QString &keyword,
const QMap<QString, QUrl> &links); const QMultiMap<QString, QUrl> &links);
QUrl link() const; QUrl link() const;