forked from qt-creator/qt-creator
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:
@@ -173,3 +173,34 @@ const QMap<QString, QUrl> &HelpItem::links() const
|
|||||||
}
|
}
|
||||||
return *m_helpLinks;
|
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());
|
||||||
|
}
|
||||||
|
@@ -78,6 +78,7 @@ public:
|
|||||||
QString extractContent(bool extended) const;
|
QString extractContent(bool extended) const;
|
||||||
|
|
||||||
const QMap<QString, QUrl> &links() const;
|
const QMap<QString, QUrl> &links() const;
|
||||||
|
const QUrl bestLink() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QUrl m_helpUrl;
|
QUrl m_helpUrl;
|
||||||
|
@@ -620,30 +620,6 @@ HelpViewer *HelpPluginPrivate::viewerForContextHelp()
|
|||||||
return viewerForHelpViewerLocation(LocalHelpManager::contextHelpOption());
|
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()
|
void HelpPluginPrivate::requestContextHelp()
|
||||||
{
|
{
|
||||||
// Find out what to show
|
// Find out what to show
|
||||||
@@ -660,9 +636,7 @@ void HelpPluginPrivate::requestContextHelp()
|
|||||||
|
|
||||||
void HelpPluginPrivate::showContextHelp(const HelpItem &contextHelp)
|
void HelpPluginPrivate::showContextHelp(const HelpItem &contextHelp)
|
||||||
{
|
{
|
||||||
const QMap<QString, QUrl> &links = contextHelp.links();
|
const QUrl source = contextHelp.bestLink();
|
||||||
|
|
||||||
const QUrl source = findBestLink(links);
|
|
||||||
if (!source.isValid()) {
|
if (!source.isValid()) {
|
||||||
// No link found or no context object
|
// No link found or no context object
|
||||||
HelpViewer *viewer = showHelpUrl(QUrl(Help::Constants::AboutBlank),
|
HelpViewer *viewer = showHelpUrl(QUrl(Help::Constants::AboutBlank),
|
||||||
|
Reference in New Issue
Block a user