Help: Move finding the best documentation link to HelpItem

Change-Id: I5032d380295d942cd4f334e4bf47e349dd5b0aea
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
Eike Ziller
2019-02-04 16:13:59 +01:00
parent a0254ea7ee
commit f973b4e94a
3 changed files with 33 additions and 27 deletions

View File

@@ -173,3 +173,34 @@ const QMap<QString, QUrl> &HelpItem::links() const
}
return *m_helpLinks;
}
static QUrl findBestLink(const QMap<QString, QUrl> &links)
{
if (links.isEmpty())
return QUrl();
if (links.size() == 1)
return links.first();
QUrl source = links.first();
// workaround to show the latest Qt version
int version = 0;
QRegExp exp("(\\d+)");
foreach (const QUrl &link, links) {
const QString &authority = link.authority();
if (authority.startsWith("com.trolltech.")
|| authority.startsWith("org.qt-project.")) {
if (exp.indexIn(authority) >= 0) {
const int tmpVersion = exp.cap(1).toInt();
if (tmpVersion > version) {
source = link;
version = tmpVersion;
}
}
}
}
return source;
}
const QUrl HelpItem::bestLink() const
{
return findBestLink(links());
}

View File

@@ -78,6 +78,7 @@ public:
QString extractContent(bool extended) const;
const QMap<QString, QUrl> &links() const;
const QUrl bestLink() const;
private:
QUrl m_helpUrl;

View File

@@ -620,30 +620,6 @@ HelpViewer *HelpPluginPrivate::viewerForContextHelp()
return viewerForHelpViewerLocation(LocalHelpManager::contextHelpOption());
}
static QUrl findBestLink(const QMap<QString, QUrl> &links)
{
if (links.isEmpty())
return QUrl();
QUrl source = links.constBegin().value();
// workaround to show the latest Qt version
int version = 0;
QRegExp exp("(\\d+)");
foreach (const QUrl &link, links) {
const QString &authority = link.authority();
if (authority.startsWith("com.trolltech.")
|| authority.startsWith("org.qt-project.")) {
if (exp.indexIn(authority) >= 0) {
const int tmpVersion = exp.cap(1).toInt();
if (tmpVersion > version) {
source = link;
version = tmpVersion;
}
}
}
}
return source;
}
void HelpPluginPrivate::requestContextHelp()
{
// Find out what to show
@@ -660,9 +636,7 @@ void HelpPluginPrivate::requestContextHelp()
void HelpPluginPrivate::showContextHelp(const HelpItem &contextHelp)
{
const QMap<QString, QUrl> &links = contextHelp.links();
const QUrl source = findBestLink(links);
const QUrl source = contextHelp.bestLink();
if (!source.isValid()) {
// No link found or no context object
HelpViewer *viewer = showHelpUrl(QUrl(Help::Constants::AboutBlank),