Help: Add option to only register highest versioned Qt documentation

In Options > Kits > Qt Versions. And make it the default.
It registers each documentation file only for the highest registered Qt
version. If you have Qt 5.12 and Qt 5.13 registered, but only installed
QtWebEngine for Qt 5.12, you'll get QtWebEngine documentation for Qt
5.12, but the other documentation is from Qt 5.13.
That is usually sufficient, since the documentation still contains "old"
API, and new API is flagged with "since".

This avoids registering a lot of documentation, which creates a startup
performance issue, and also leads to usually unneeded popups for which
Qt version some documentation should be shown.

The option also allows going back to registering all documentation,
and no Qt documentation at all.

Fixes: QTCREATORBUG-21482
Fixes: QTCREATORBUG-22799
Task-number: QTCREATORBUG-10004
Change-Id: I1c7bc73982d48d8e53f5083e2fa851b6c5f60f80
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Eike Ziller
2019-10-07 07:46:48 +02:00
parent 6b492866af
commit 3dfa188182
6 changed files with 118 additions and 22 deletions

View File

@@ -67,6 +67,9 @@ const char QTVERSION_FILENAME[] = "/qtversion.xml";
using VersionMap = QMap<int, BaseQtVersion *>;
static VersionMap m_versions;
const char DOCUMENTATION_SETTING_KEY[] = "QtSupport/DocumentationSetting";
static int m_idcount = 0;
// managed by QtProjectManagerPlugin
static QtVersionManager *m_instance = nullptr;
@@ -95,9 +98,6 @@ bool qtVersionNumberCompare(BaseQtVersion *a, BaseQtVersion *b)
static bool restoreQtVersions();
static void findSystemQt();
static void saveQtVersions();
static void updateDocumentation(const QList<BaseQtVersion *> &added,
const QList<BaseQtVersion *> &removed = {},
const QList<BaseQtVersion *> &allNew = {});
// --------------------------------------------------------------------------
// QtVersionManager
@@ -145,7 +145,8 @@ void QtVersionManager::triggerQtVersionRestore()
FileSystemWatcher::WatchModifiedDate);
} // exists
updateDocumentation(m_versions.values());
const QList<BaseQtVersion *> vs = versions();
updateDocumentation(vs, {}, vs);
}
bool QtVersionManager::isLoaded()
@@ -464,37 +465,57 @@ void QtVersionManager::removeVersion(BaseQtVersion *version)
delete version;
}
static QStringList documentationFiles(BaseQtVersion *v)
using Path = QString;
using FileName = QString;
static QList<std::pair<Path, FileName>> documentationFiles(BaseQtVersion *v)
{
QStringList files;
QList<std::pair<Path, FileName>> files;
const QStringList docPaths = QStringList(
{v->docsPath().toString() + QChar('/'), v->docsPath().toString() + "/qch/"});
for (const QString &docPath : docPaths) {
const QDir versionHelpDir(docPath);
for (const QString &helpFile : versionHelpDir.entryList(QStringList("*.qch"), QDir::Files))
files.append(docPath + helpFile);
files.append({docPath, helpFile});
}
return files;
}
static QStringList documentationFiles(const QList<BaseQtVersion *> &vs)
static QStringList documentationFiles(const QList<BaseQtVersion *> &vs, bool highestOnly = false)
{
QStringList files;
for (BaseQtVersion *v : vs)
files += documentationFiles(v);
return files;
QSet<QString> includedFileNames;
QSet<QString> filePaths;
const QList<BaseQtVersion *> versions = highestOnly ? QtVersionManager::sortVersions(vs) : vs;
for (BaseQtVersion *v : versions) {
for (const std::pair<Path, FileName> &file : documentationFiles(v)) {
if (!highestOnly || !includedFileNames.contains(file.second)) {
filePaths.insert(file.first + file.second);
includedFileNames.insert(file.second);
}
}
}
return filePaths.values();
}
static void updateDocumentation(const QList<BaseQtVersion *> &added,
const QList<BaseQtVersion *> &removed,
const QList<BaseQtVersion *> &allNew)
void QtVersionManager::updateDocumentation(const QList<BaseQtVersion *> &added,
const QList<BaseQtVersion *> &removed,
const QList<BaseQtVersion *> &allNew)
{
const QStringList docsOfAll = documentationFiles(allNew);
const DocumentationSetting setting = documentationSetting();
const QStringList docsOfAll = setting == DocumentationSetting::None
? QStringList()
: documentationFiles(allNew,
setting
== DocumentationSetting::HighestOnly);
const QStringList docsToRemove = Utils::filtered(documentationFiles(removed),
[&docsOfAll](const QString &f) {
return !docsOfAll.contains(f);
});
const QStringList docsToAdd = Utils::filtered(documentationFiles(added),
[&docsOfAll](const QString &f) {
return docsOfAll.contains(f);
});
Core::HelpManager::unregisterDocumentation(docsToRemove);
Core::HelpManager::registerDocumentation(documentationFiles(added));
Core::HelpManager::registerDocumentation(docsToAdd);
}
int QtVersionManager::getUniqueId()
@@ -613,4 +634,21 @@ void QtVersionManager::setNewQtVersions(const QList<BaseQtVersion *> &newVersion
emit m_instance->qtVersionsChanged(addedIds, removedIds, changedIds);
}
void QtVersionManager::setDocumentationSetting(const QtVersionManager::DocumentationSetting &setting)
{
if (setting == documentationSetting())
return;
Core::ICore::settings()->setValue(DOCUMENTATION_SETTING_KEY, int(setting));
// force re-evaluating which documentation should be registered
// by claiming that all are removed and re-added
const QList<BaseQtVersion *> vs = versions();
updateDocumentation(vs, vs, vs);
}
QtVersionManager::DocumentationSetting QtVersionManager::documentationSetting()
{
return DocumentationSetting(
Core::ICore::settings()->value(DOCUMENTATION_SETTING_KEY, 0).toInt());
}
} // namespace QtVersion