diff options
author | Eike Ziller <eike.ziller@qt.io> | 2019-01-28 12:46:30 +0100 |
---|---|---|
committer | Eike Ziller <eike.ziller@qt.io> | 2019-01-31 10:32:36 +0000 |
commit | d386b3c2412c4e0fb2dd32a51ebcf83ca2a32442 (patch) | |
tree | a3eada8f38760995a126bab80a169aa2064ac9ea /src/plugins/coreplugin/helpitem.cpp | |
parent | 1dee275f58e9f9df2e2719325157cfdec42fe1cf (diff) | |
download | qt-creator-d386b3c2412c4e0fb2dd32a51ebcf83ca2a32442.tar.gz |
Help: Avoid ambiguity of help ID being interpreted as URL
Users know if they have a URL or not, we should not guess (and then even
guess differently at different places)
Change-Id: Iaaf69a94baadbee0ff427a2bc9065b714dcf8478
Reviewed-by: David Schulz <david.schulz@qt.io>
Diffstat (limited to 'src/plugins/coreplugin/helpitem.cpp')
-rw-r--r-- | src/plugins/coreplugin/helpitem.cpp | 57 |
1 files changed, 40 insertions, 17 deletions
diff --git a/src/plugins/coreplugin/helpitem.cpp b/src/plugins/coreplugin/helpitem.cpp index fd7bebb52f..d2d444f44b 100644 --- a/src/plugins/coreplugin/helpitem.cpp +++ b/src/plugins/coreplugin/helpitem.cpp @@ -40,6 +40,26 @@ HelpItem::HelpItem(const QString &helpId) : m_helpId(helpId) {} +HelpItem::HelpItem(const QUrl &url) + : m_helpUrl(url) +{} + +HelpItem::HelpItem(const QUrl &url, const QString &docMark, HelpItem::Category category) + : m_helpUrl(url) + , m_docMark(docMark) + , m_category(category) +{} + +HelpItem::HelpItem(const QUrl &url, + const QString &docMark, + HelpItem::Category category, + const QMap<QString, QUrl> &helpLinks) + : m_helpUrl(url) + , m_docMark(docMark) + , m_category(category) + , m_helpLinks(helpLinks) +{} + HelpItem::HelpItem(const QString &helpId, const QString &docMark, Category category) : m_helpId(helpId), m_docMark(docMark), m_category(category) {} @@ -49,6 +69,16 @@ HelpItem::HelpItem(const QString &helpId, const QString &docMark, Category categ m_helpId(helpId), m_docMark(docMark), m_category(category), m_helpLinks(helpLinks) {} +void HelpItem::setHelpUrl(const QUrl &url) +{ + m_helpUrl = url; +} + +const QUrl &HelpItem::helpUrl() const +{ + return m_helpUrl; +} + void HelpItem::setHelpId(const QString &id) { m_helpId = id; } @@ -69,13 +99,9 @@ HelpItem::Category HelpItem::category() const bool HelpItem::isValid() const { - if (m_helpId.isEmpty()) + if (m_helpUrl.isEmpty() && m_helpId.isEmpty()) return false; - if (!links().isEmpty()) - return true; - if (QUrl(m_helpId).isValid()) - return true; - return false; + return !links().isEmpty(); } QString HelpItem::extractContent(bool extended) const @@ -87,14 +113,7 @@ QString HelpItem::extractContent(bool extended) const htmlExtractor.setMode(Utils::HtmlDocExtractor::FirstParagraph); QString contents; - QMap<QString, QUrl> helpLinks = links(); - if (helpLinks.isEmpty()) { - // Maybe this is already an URL... - QUrl url(m_helpId); - if (url.isValid()) - helpLinks.insert(m_helpId, m_helpId); - } - foreach (const QUrl &url, helpLinks) { + for (const QUrl &url : links()) { const QString html = QString::fromUtf8(Core::HelpManager::fileData(url)); switch (m_category) { case Brief: @@ -135,9 +154,13 @@ QString HelpItem::extractContent(bool extended) const return contents; } -QMap<QString, QUrl> HelpItem::links() const +const QMap<QString, QUrl> &HelpItem::links() const { - if (!m_helpLinks) - m_helpLinks = Core::HelpManager::linksForIdentifier(m_helpId); + if (!m_helpLinks) { + if (!m_helpUrl.isEmpty()) + m_helpLinks.emplace(QMap<QString, QUrl>({{m_helpUrl.toString(), m_helpUrl}})); + else + m_helpLinks = Core::HelpManager::linksForIdentifier(m_helpId); + } return *m_helpLinks; } |