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());
}