From 911c486ff07a8314d3c6186c3a86888f84dd7817 Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Fri, 1 Mar 2024 10:15:05 +0100 Subject: [PATCH] Qt/Help: Fix the "Highest Version Only" setting for the online installer The Qt support has the option to only register the documentation for "the highest Qt version", which is enabled by default. That is based on finding the help files for registered Qt versions and only registering the right set depending on the settings. Unfortunately the online installer additionally registers the Qt documentation path as a separate documentation set in the install settings. (This was originally introduced to support documentation for components that are not directly related to a Qt version.) The Help plugin that handles this setting doesn't know that the Qt support explicitly doesn't want the documentation of some Qt versions registered. Let the Qt support explicitly tell the Help plugin about documentation files that should not be registered, even if they appear in the separate install setting. Change-Id: I0512adc0dfe9969481ce83094f5349a49aae5d9f Reviewed-by: Christian Kandeler Reviewed-by: Reviewed-by: Marcus Tillmanns --- src/plugins/coreplugin/helpmanager.cpp | 6 +++ src/plugins/coreplugin/helpmanager.h | 1 + .../coreplugin/helpmanager_implementation.h | 1 + src/plugins/help/helpmanager.cpp | 13 +++++ src/plugins/help/helpmanager.h | 1 + src/plugins/qtsupport/qtversionmanager.cpp | 49 ++++++++++++++++--- 6 files changed, 64 insertions(+), 7 deletions(-) diff --git a/src/plugins/coreplugin/helpmanager.cpp b/src/plugins/coreplugin/helpmanager.cpp index 2fda96bf1e2..01fc7eff478 100644 --- a/src/plugins/coreplugin/helpmanager.cpp +++ b/src/plugins/coreplugin/helpmanager.cpp @@ -97,5 +97,11 @@ void showHelpUrl(const QString &url, HelpViewerLocation location) showHelpUrl(QUrl(url), location); } +void setBlockedDocumentation(const QStringList &fileNames) +{ + if (checkInstance()) + m_instance->setBlockedDocumentation(fileNames); +} + } // HelpManager } // Core diff --git a/src/plugins/coreplugin/helpmanager.h b/src/plugins/coreplugin/helpmanager.h index 845b508015d..55d449e696b 100644 --- a/src/plugins/coreplugin/helpmanager.h +++ b/src/plugins/coreplugin/helpmanager.h @@ -38,6 +38,7 @@ enum HelpViewerLocation { CORE_EXPORT QString documentationPath(); CORE_EXPORT void registerDocumentation(const QStringList &fileNames); +CORE_EXPORT void setBlockedDocumentation(const QStringList &fileNames); CORE_EXPORT void unregisterDocumentation(const QStringList &fileNames); CORE_EXPORT QMultiMap linksForIdentifier(const QString &id); diff --git a/src/plugins/coreplugin/helpmanager_implementation.h b/src/plugins/coreplugin/helpmanager_implementation.h index c0d23563400..798a5a340ed 100644 --- a/src/plugins/coreplugin/helpmanager_implementation.h +++ b/src/plugins/coreplugin/helpmanager_implementation.h @@ -17,6 +17,7 @@ protected: public: virtual void registerDocumentation(const QStringList &fileNames) = 0; + virtual void setBlockedDocumentation(const QStringList &fileNames) = 0; virtual void unregisterDocumentation(const QStringList &fileNames) = 0; virtual QMultiMap linksForIdentifier(const QString &id) = 0; virtual QMultiMap linksForKeyword(const QString &keyword) = 0; diff --git a/src/plugins/help/helpmanager.cpp b/src/plugins/help/helpmanager.cpp index 6a232083bd1..7ec80e700d5 100644 --- a/src/plugins/help/helpmanager.cpp +++ b/src/plugins/help/helpmanager.cpp @@ -54,6 +54,7 @@ struct HelpManagerPrivate // data for delayed initialization QSet m_filesToRegister; + QSet m_blockedDocumentation; QSet m_filesToUnregister; QHash m_customValues; @@ -146,6 +147,12 @@ void HelpManager::registerDocumentation(const QStringList &files) ProgressManager::addTask(future, Tr::tr("Update Documentation"), kUpdateDocumentationTask); } +void HelpManager::setBlockedDocumentation(const QStringList &fileNames) +{ + for (const QString &filePath : fileNames) + d->m_blockedDocumentation.insert(filePath); +} + static void unregisterDocumentationNow(QPromise &promise, const QString collectionFilePath, const QStringList &files) @@ -334,6 +341,12 @@ void HelpManager::setupHelpManager() for (const QString &filePath : d->documentationFromInstaller()) d->m_filesToRegister.insert(filePath); + // The online installer registers documentation for Qt versions explicitly via an install + // setting, which defeats that we only register the Qt versions matching the setting. + // So the Qt support explicitly blocks the files that we do _not_ want to register, so the + // Help plugin knows about this. + d->m_filesToRegister -= d->m_blockedDocumentation; + d->cleanUpDocumentation(); if (!d->m_filesToUnregister.isEmpty()) { diff --git a/src/plugins/help/helpmanager.h b/src/plugins/help/helpmanager.h index 6a5874e7df2..5f0efe56200 100644 --- a/src/plugins/help/helpmanager.h +++ b/src/plugins/help/helpmanager.h @@ -29,6 +29,7 @@ public: static QString collectionFilePath(); void registerDocumentation(const QStringList &fileNames) override; + void setBlockedDocumentation(const QStringList &fileNames) override; void unregisterDocumentation(const QStringList &fileNames) override; static void registerUserDocumentation(const QStringList &filePaths); diff --git a/src/plugins/qtsupport/qtversionmanager.cpp b/src/plugins/qtsupport/qtversionmanager.cpp index acdaba62827..063a1309846 100644 --- a/src/plugins/qtsupport/qtversionmanager.cpp +++ b/src/plugins/qtsupport/qtversionmanager.cpp @@ -120,7 +120,8 @@ public: void updateDocumentation(const QtVersions &added, const QtVersions &removed, - const QtVersions &allNew); + const QtVersions &allNew, + bool updateBlockedDocumentation = false); void setNewQtVersions(const QtVersions &newVersions); QString qmakePath(const QString &qtchooser, const QString &version); @@ -174,7 +175,7 @@ void QtVersionManagerImpl::triggerQtVersionRestore() } // exists const QtVersions vs = QtVersionManager::versions(); - updateDocumentation(vs, {}, vs); + updateDocumentation(vs, {}, vs, /*updateBlockedDocumentation=*/true); } bool QtVersionManager::isLoaded() @@ -499,9 +500,13 @@ void QtVersionManager::registerExampleSet(const QString &displayName, using Path = QString; using FileName = QString; -static QList> documentationFiles(QtVersion *v) +using DocumentationFile = std::pair; +using DocumentationFiles = QList; +using AllDocumentationFiles = QHash; + +static DocumentationFiles allDocumentationFiles(QtVersion *v) { - QList> files; + DocumentationFiles files; const QStringList docPaths = QStringList( {v->docsPath().toString() + QChar('/'), v->docsPath().toString() + "/qch/"}); for (const QString &docPath : docPaths) { @@ -512,7 +517,17 @@ static QList> documentationFiles(QtVersion *v) return files; } -static QStringList documentationFiles(const QtVersions &vs, bool highestOnly = false) +static AllDocumentationFiles allDocumentationFiles(const QtVersions &versions) +{ + AllDocumentationFiles result; + for (QtVersion *v : versions) + result.insert(v, allDocumentationFiles(v)); + return result; +} + +static QStringList documentationFiles(const QtVersions &vs, + const AllDocumentationFiles &allDocumentationFiles, + bool highestOnly = false) { // if highestOnly is true, register each file only once per major Qt version, even if // multiple minor or patch releases of that major version are installed @@ -522,7 +537,8 @@ static QStringList documentationFiles(const QtVersions &vs, bool highestOnly = f for (QtVersion *v : versions) { const int majorVersion = v->qtVersion().majorVersion(); QSet &majorVersionFileNames = includedFileNames[majorVersion]; - for (const std::pair &file : documentationFiles(v)) { + const DocumentationFiles files = allDocumentationFiles.value(v); + for (const std::pair &file : files) { if (!highestOnly || !majorVersionFileNames.contains(file.second)) { filePaths.insert(file.first + file.second); majorVersionFileNames.insert(file.second); @@ -532,15 +548,23 @@ static QStringList documentationFiles(const QtVersions &vs, bool highestOnly = f return filePaths.values(); } +static QStringList documentationFiles(const QtVersions &vs) +{ + return documentationFiles(vs, allDocumentationFiles(vs)); +} + void QtVersionManagerImpl::updateDocumentation(const QtVersions &added, const QtVersions &removed, - const QtVersions &allNew) + const QtVersions &allNew, + bool updateBlockedDocumentation) { using DocumentationSetting = QtVersionManager::DocumentationSetting; const DocumentationSetting setting = QtVersionManager::documentationSetting(); + const AllDocumentationFiles allNewDocFiles = allDocumentationFiles(allNew); const QStringList docsOfAll = setting == DocumentationSetting::None ? QStringList() : documentationFiles(allNew, + allNewDocFiles, setting == DocumentationSetting::HighestOnly); const QStringList docsToRemove = Utils::filtered(documentationFiles(removed), @@ -551,6 +575,17 @@ void QtVersionManagerImpl::updateDocumentation(const QtVersions &added, [&docsOfAll](const QString &f) { return docsOfAll.contains(f); }); + + if (updateBlockedDocumentation) { + // The online installer registers documentation for Qt versions explicitly via an install + // setting, which defeats that we only register the Qt versions matching the setting. + // So the Qt support explicitly blocks the files that we do _not_ want to register, so the + // Help plugin knows about this. + const QSet reallyAllFiles = toSet(documentationFiles(allNew, allNewDocFiles)); + const QSet toBlock = reallyAllFiles - toSet(docsOfAll); + Core::HelpManager::setBlockedDocumentation(toList(toBlock)); + } + Core::HelpManager::unregisterDocumentation(docsToRemove); Core::HelpManager::registerDocumentation(docsToAdd); }