From c86b86b2546424dd6ec5bccf4b50ab04965fded4 Mon Sep 17 00:00:00 2001 From: Marcus Tillmanns Date: Tue, 1 Nov 2022 09:27:54 +0100 Subject: [PATCH] Help: Remove duplicate results Workaround for QTBUG-108131 Change-Id: If3de18249fe11b753323c5375559d5ffd0ef0673 Reviewed-by: Eike Ziller --- src/plugins/help/helpindexfilter.cpp | 5 +---- src/plugins/help/helpmanager.cpp | 27 +++++++++++++++++++++------ src/plugins/help/helpmanager.h | 4 ++++ src/plugins/help/localhelpmanager.cpp | 6 ++++++ src/plugins/help/localhelpmanager.h | 2 ++ src/shared/help/indexwindow.cpp | 5 +---- 6 files changed, 35 insertions(+), 14 deletions(-) diff --git a/src/plugins/help/helpindexfilter.cpp b/src/plugins/help/helpindexfilter.cpp index fd3473b57a0..f6bdf08e8b7 100644 --- a/src/plugins/help/helpindexfilter.cpp +++ b/src/plugins/help/helpindexfilter.cpp @@ -101,10 +101,7 @@ void HelpIndexFilter::accept(const LocatorFilterEntry &selection, Q_UNUSED(selectionStart) Q_UNUSED(selectionLength) const QString &key = selection.displayName; - QMultiMap links; - const QList docs = LocalHelpManager::helpEngine().documentsForKeyword(key, QString()); - for (const auto &doc : docs) - links.insert(doc.title, doc.url); + const QMultiMap links = LocalHelpManager::linksForKeyword(key); emit linksActivated(links, key); } diff --git a/src/plugins/help/helpmanager.cpp b/src/plugins/help/helpmanager.cpp index a716bb537af..74b907b3374 100644 --- a/src/plugins/help/helpmanager.cpp +++ b/src/plugins/help/helpmanager.cpp @@ -195,17 +195,32 @@ QSet HelpManager::userDocumentationPaths() return d->m_userRegisteredFiles; } -// This should go into Qt 4.8 once we start using it for Qt Creator +QMultiMap HelpManager::linksForKeyword(QHelpEngineCore *engine, + const QString &key, + std::optional filterName) +{ + QMultiMap links; + const QList docs = filterName.has_value() + ? engine->documentsForKeyword(key, filterName.value()) + : engine->documentsForKeyword(key); + + for (const auto &doc : docs) + links.insert(doc.title, doc.url); + + // Remove duplicates (workaround for QTBUG-108131) + links.removeIf([&links](const QMultiMap::iterator it) { + return links.find(it.key(), it.value()) != it; + }); + + return links; +} + QMultiMap HelpManager::linksForKeyword(const QString &key) { QTC_ASSERT(!d->m_needsSetup, return {}); if (key.isEmpty()) return {}; - QMultiMap links; - const QList docs = d->m_helpEngine->documentsForKeyword(key, QString()); - for (const auto &doc : docs) - links.insert(doc.title, doc.url); - return links; + return HelpManager::linksForKeyword(d->m_helpEngine, key, QString()); } QMultiMap HelpManager::linksForIdentifier(const QString &id) diff --git a/src/plugins/help/helpmanager.h b/src/plugins/help/helpmanager.h index 55d98db53eb..89954ffbb6a 100644 --- a/src/plugins/help/helpmanager.h +++ b/src/plugins/help/helpmanager.h @@ -8,6 +8,7 @@ QT_FORWARD_DECLARE_CLASS(QUrl) #include +#include #include namespace Help { @@ -34,6 +35,9 @@ public: QMultiMap linksForIdentifier(const QString &id) override; QMultiMap linksForKeyword(const QString &key) override; + static QMultiMap linksForKeyword(QHelpEngineCore *engine, + const QString &key, + std::optional filterName); static QUrl findFile(const QUrl &url); QByteArray fileData(const QUrl &url) override; diff --git a/src/plugins/help/localhelpmanager.cpp b/src/plugins/help/localhelpmanager.cpp index b395ebf2f70..1c4c54c65be 100644 --- a/src/plugins/help/localhelpmanager.cpp +++ b/src/plugins/help/localhelpmanager.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -521,3 +522,8 @@ bool LocalHelpManager::openOnlineHelp(const QUrl &url) } return false; } + +QMultiMap LocalHelpManager::linksForKeyword(const QString &keyword) +{ + return HelpManager::linksForKeyword(&LocalHelpManager::helpEngine(), keyword, std::nullopt); +} diff --git a/src/plugins/help/localhelpmanager.h b/src/plugins/help/localhelpmanager.h index b383f97185c..e8064920b99 100644 --- a/src/plugins/help/localhelpmanager.h +++ b/src/plugins/help/localhelpmanager.h @@ -99,6 +99,8 @@ public: static bool canOpenOnlineHelp(const QUrl &url); static bool openOnlineHelp(const QUrl &url); + static QMultiMap linksForKeyword(const QString &keyword); + signals: void fallbackFontChanged(const QFont &font); void fontZoomChanged(int percentage); diff --git a/src/shared/help/indexwindow.cpp b/src/shared/help/indexwindow.cpp index 4d52e1a8e4c..4441a963162 100644 --- a/src/shared/help/indexwindow.cpp +++ b/src/shared/help/indexwindow.cpp @@ -175,10 +175,7 @@ void IndexWindow::disableSearchLineEdit() void IndexWindow::open(const QModelIndex &index, bool newPage) { const QString keyword = m_filteredIndexModel->data(index, Qt::DisplayRole).toString(); - QMultiMap links; - const QList docs = LocalHelpManager::helpEngine().documentsForKeyword(keyword); - for (const auto &doc : docs) - links.insert(doc.title, doc.url); + const QMultiMap links = LocalHelpManager::linksForKeyword(keyword); emit linksActivated(links, keyword, newPage); }