6#include <QtHelp/QCompressedHelpInfo>
7#include <QtHelp/QHelpEngineCore>
8#include <QtHelp/QHelpFilterEngine>
10#include <QtCore/QVersionNumber>
45HelpDocSettings &HelpDocSettings::
operator=(
const HelpDocSettings &) =
default;
47HelpDocSettings &HelpDocSettings::
operator=(HelpDocSettings &&) =
default;
51 const QCompressedHelpInfo info = QCompressedHelpInfo::fromCompressedHelpFile(fileName);
56 const QString namespaceName = info.namespaceName();
58 if (d->m_namespaceToFileName.contains(namespaceName))
61 if (d->m_fileNameToNamespace.contains(fileName))
64 const QString component = info.component();
67 d->m_namespaceToFileName.insert(namespaceName, fileName);
68 d->m_fileNameToNamespace.insert(fileName, namespaceName);
70 d->m_namespaceToComponent.insert(namespaceName, component);
71 d->m_componentToNamespace[component].append(namespaceName);
73 d->m_namespaceToVersion.insert(namespaceName, version);
74 d->m_versionToNamespace[version].append(namespaceName);
81 if (namespaceName.isEmpty())
84 const QString fileName = d->m_namespaceToFileName.value(namespaceName);
85 if (fileName.isEmpty())
88 const QString component = d->m_namespaceToComponent.value(namespaceName);
89 const QVersionNumber version = d->m_namespaceToVersion.value(namespaceName);
91 d->m_namespaceToComponent.remove(namespaceName);
92 d->m_namespaceToVersion.remove(namespaceName);
93 d->m_namespaceToFileName.remove(namespaceName);
94 d->m_fileNameToNamespace.remove(fileName);
95 d->m_componentToNamespace[component].removeOne(namespaceName);
96 if (d->m_componentToNamespace[component].isEmpty())
97 d->m_componentToNamespace.remove(component);
98 d->m_versionToNamespace[version].removeOne(namespaceName);
99 if (d->m_versionToNamespace[version].isEmpty())
100 d->m_versionToNamespace.remove(version);
107 return d->m_fileNameToNamespace.value(fileName);
112 return d->m_componentToNamespace.keys();
117 return d->m_versionToNamespace.keys();
122 return d->m_namespaceToFileName.keys();
127 return d->m_namespaceToFileName;
130HelpDocSettings HelpDocSettings::
readSettings(QHelpEngineCore *helpEngine)
132 QHelpFilterEngine *filterEngine = helpEngine->filterEngine();
134 HelpDocSettings docSettings;
135 docSettings.d->m_namespaceToComponent = filterEngine->namespaceToComponent();
136 docSettings.d->m_namespaceToVersion = filterEngine->namespaceToVersion();
137 for (
auto it = docSettings.d->m_namespaceToComponent.constBegin();
138 it != docSettings.d->m_namespaceToComponent.constEnd(); ++it) {
139 const QString namespaceName = it.key();
140 const QString namespaceFileName = helpEngine->documentationFileName(namespaceName);
141 docSettings.d->m_namespaceToFileName.insert(namespaceName, namespaceFileName);
142 docSettings.d->m_fileNameToNamespace.insert(namespaceFileName, namespaceName);
143 docSettings.d->m_componentToNamespace[it.value()].append(namespaceName);
145 for (
auto it = docSettings.d->m_namespaceToVersion.constBegin();
146 it != docSettings.d->m_namespaceToVersion.constEnd(); ++it) {
147 docSettings.d->m_versionToNamespace[it.value()].append(it.key());
154 const QMap<QString, QString> &subtrahend)
156 auto result = minuend;
158 for (
auto itSubtrahend = subtrahend.cbegin(); itSubtrahend != subtrahend.cend(); ++itSubtrahend) {
159 auto itResult = result.find(itSubtrahend.key());
160 if (itResult != result.end() && itSubtrahend.value() == itResult.value())
161 result.erase(itResult);
168 const HelpDocSettings &settings)
172 const QMap<QString, QString> docsToRemove = subtract(
173 oldSettings.namespaceToFileName(),
174 settings.namespaceToFileName());
175 const QMap<QString, QString> docsToAdd = subtract(
176 settings.namespaceToFileName(),
177 oldSettings.namespaceToFileName());
179 for (
auto it = docsToRemove.cbegin(); it != docsToRemove.cend(); ++it) {
180 if (!helpEngine->unregisterDocumentation(it.key()))
181 qWarning() <<
"Cannot unregister documentation:" << it.key();
184 for (
const QString &fileName : docsToAdd) {
185 if (!helpEngine->registerDocumentation(fileName))
186 qWarning() <<
"Cannot register documentation file:" << fileName;
189 return !docsToRemove.isEmpty() || !docsToAdd.isEmpty();
QMap< QString, QVersionNumber > m_namespaceToVersion
QMap< QString, QStringList > m_componentToNamespace
QMap< QString, QString > m_namespaceToFileName
HelpDocSettingsPrivate(const HelpDocSettingsPrivate &other)=default
~HelpDocSettingsPrivate()=default
QMap< QVersionNumber, QStringList > m_versionToNamespace
QMap< QString, QString > m_namespaceToComponent
QMap< QString, QString > m_fileNameToNamespace
HelpDocSettingsPrivate()=default
HelpDocSettings(const HelpDocSettings &other)
bool removeDocumentation(const QString &namespaceName)
QString namespaceName(const QString &fileName) const
static bool applySettings(QHelpEngineCore *helpEngine, const HelpDocSettings &settings)
QMap< QString, QString > namespaceToFileName() const
static HelpDocSettings readSettings(QHelpEngineCore *helpEngine)
QList< QVersionNumber > versions() const
QStringList namespaces() const
HelpDocSettings(HelpDocSettings &&other)
HelpDocSettings & operator=(const HelpDocSettings &other)
QStringList components() const
HelpDocSettings & operator=(HelpDocSettings &&other)
bool addDocumentation(const QString &fileName)
static QMap< QString, QString > subtract(const QMap< QString, QString > &minuend, const QMap< QString, QString > &subtrahend)
Combined button and popup list for selecting options.