diff --git a/src/plugins/coreplugin/helpitem.cpp b/src/plugins/coreplugin/helpitem.cpp index ec5ead12e07..268c00ce67b 100644 --- a/src/plugins/coreplugin/helpitem.cpp +++ b/src/plugins/coreplugin/helpitem.cpp @@ -173,3 +173,34 @@ const QMap &HelpItem::links() const } return *m_helpLinks; } + +static QUrl findBestLink(const QMap &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()); +} diff --git a/src/plugins/coreplugin/helpitem.h b/src/plugins/coreplugin/helpitem.h index 794eaca8f31..5468659b2a4 100644 --- a/src/plugins/coreplugin/helpitem.h +++ b/src/plugins/coreplugin/helpitem.h @@ -78,6 +78,7 @@ public: QString extractContent(bool extended) const; const QMap &links() const; + const QUrl bestLink() const; private: QUrl m_helpUrl; diff --git a/src/plugins/help/helpplugin.cpp b/src/plugins/help/helpplugin.cpp index df16af3101c..ada46f3b3ec 100644 --- a/src/plugins/help/helpplugin.cpp +++ b/src/plugins/help/helpplugin.cpp @@ -620,30 +620,6 @@ HelpViewer *HelpPluginPrivate::viewerForContextHelp() return viewerForHelpViewerLocation(LocalHelpManager::contextHelpOption()); } -static QUrl findBestLink(const QMap &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 &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),