2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-08-27 12:11:55 +02:00
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2010-08-27 12:11:55 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2010-08-27 12:11:55 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
2014-10-01 13:21:18 +02:00
|
|
|
** conditions see http://www.qt.io/licensing. For further information
|
|
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2010-08-27 12:11:55 +02:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-10-01 13:21:18 +02:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2012-10-02 09:12:39 +02:00
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2010-08-27 12:11:55 +02:00
|
|
|
|
|
|
|
|
#include "helpitem.h"
|
|
|
|
|
|
|
|
|
|
#include <coreplugin/helpmanager.h>
|
|
|
|
|
#include <utils/htmldocextractor.h>
|
|
|
|
|
|
|
|
|
|
using namespace TextEditor;
|
|
|
|
|
|
|
|
|
|
HelpItem::HelpItem()
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
HelpItem::HelpItem(const QString &helpId, Category category) :
|
|
|
|
|
m_helpId(helpId), m_docMark(helpId), m_category(category)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
HelpItem::HelpItem(const QString &helpId, const QString &docMark, Category category) :
|
|
|
|
|
m_helpId(helpId), m_docMark(docMark), m_category(category)
|
|
|
|
|
{}
|
|
|
|
|
|
2013-05-15 12:46:08 +02:00
|
|
|
HelpItem::HelpItem(const QString &helpId, const QString &docMark, Category category,
|
|
|
|
|
const QMap<QString, QUrl> &helpLinks) :
|
|
|
|
|
m_helpId(helpId), m_docMark(docMark), m_category(category), m_helpLinks(helpLinks)
|
|
|
|
|
{}
|
|
|
|
|
|
2010-08-27 12:11:55 +02:00
|
|
|
HelpItem::~HelpItem()
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
void HelpItem::setHelpId(const QString &id)
|
|
|
|
|
{ m_helpId = id; }
|
|
|
|
|
|
|
|
|
|
const QString &HelpItem::helpId() const
|
|
|
|
|
{ return m_helpId; }
|
|
|
|
|
|
|
|
|
|
void HelpItem::setDocMark(const QString &mark)
|
|
|
|
|
{ m_docMark = mark; }
|
|
|
|
|
|
|
|
|
|
const QString &HelpItem::docMark() const
|
|
|
|
|
{ return m_docMark; }
|
|
|
|
|
|
|
|
|
|
void HelpItem::setCategory(Category cat)
|
|
|
|
|
{ m_category = cat; }
|
|
|
|
|
|
|
|
|
|
HelpItem::Category HelpItem::category() const
|
|
|
|
|
{ return m_category; }
|
|
|
|
|
|
|
|
|
|
bool HelpItem::isValid() const
|
|
|
|
|
{
|
2013-05-15 12:46:08 +02:00
|
|
|
if (m_helpId.isEmpty())
|
|
|
|
|
return false;
|
|
|
|
|
if (!retrieveHelpLinks().isEmpty())
|
2010-08-27 12:11:55 +02:00
|
|
|
return true;
|
2011-11-10 11:55:05 +01:00
|
|
|
if (QUrl(m_helpId).isValid())
|
|
|
|
|
return true;
|
2010-08-27 12:11:55 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString HelpItem::extractContent(bool extended) const
|
|
|
|
|
{
|
|
|
|
|
Utils::HtmlDocExtractor htmlExtractor;
|
|
|
|
|
if (extended)
|
2010-09-01 12:08:38 +02:00
|
|
|
htmlExtractor.setMode(Utils::HtmlDocExtractor::Extended);
|
2010-08-27 12:11:55 +02:00
|
|
|
else
|
2010-09-01 12:08:38 +02:00
|
|
|
htmlExtractor.setMode(Utils::HtmlDocExtractor::FirstParagraph);
|
2010-08-27 12:11:55 +02:00
|
|
|
|
|
|
|
|
QString contents;
|
2013-05-15 12:46:08 +02:00
|
|
|
QMap<QString, QUrl> helpLinks = retrieveHelpLinks();
|
2011-11-10 11:55:05 +01:00
|
|
|
if (helpLinks.isEmpty()) {
|
|
|
|
|
// Maybe this is already an URL...
|
|
|
|
|
QUrl url(m_helpId);
|
|
|
|
|
if (url.isValid())
|
|
|
|
|
helpLinks.insert(m_helpId, m_helpId);
|
|
|
|
|
}
|
2010-08-27 12:11:55 +02:00
|
|
|
foreach (const QUrl &url, helpLinks) {
|
2013-08-29 19:00:34 +02:00
|
|
|
const QString html = QString::fromUtf8(Core::HelpManager::fileData(url));
|
2010-08-27 12:11:55 +02:00
|
|
|
switch (m_category) {
|
|
|
|
|
case Brief:
|
|
|
|
|
contents = htmlExtractor.getClassOrNamespaceBrief(html, m_docMark);
|
|
|
|
|
break;
|
|
|
|
|
case ClassOrNamespace:
|
|
|
|
|
contents = htmlExtractor.getClassOrNamespaceDescription(html, m_docMark);
|
|
|
|
|
break;
|
|
|
|
|
case Function:
|
|
|
|
|
contents = htmlExtractor.getFunctionDescription(html, m_docMark);
|
|
|
|
|
break;
|
|
|
|
|
case Enum:
|
|
|
|
|
contents = htmlExtractor.getEnumDescription(html, m_docMark);
|
|
|
|
|
break;
|
|
|
|
|
case Typedef:
|
|
|
|
|
contents = htmlExtractor.getTypedefDescription(html, m_docMark);
|
|
|
|
|
break;
|
|
|
|
|
case Macro:
|
|
|
|
|
contents = htmlExtractor.getMacroDescription(html, m_docMark);
|
|
|
|
|
break;
|
2010-11-17 14:48:25 +01:00
|
|
|
case QmlComponent:
|
|
|
|
|
contents = htmlExtractor.getQmlComponentDescription(html, m_docMark);
|
|
|
|
|
break;
|
|
|
|
|
case QmlProperty:
|
|
|
|
|
contents = htmlExtractor.getQmlPropertyDescription(html, m_docMark);
|
2010-08-27 12:11:55 +02:00
|
|
|
break;
|
2011-11-10 11:55:05 +01:00
|
|
|
case QMakeVariableOfFunction:
|
|
|
|
|
contents = htmlExtractor.getQMakeVariableOrFunctionDescription(html, m_docMark);
|
|
|
|
|
break;
|
2010-08-27 12:11:55 +02:00
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!contents.isEmpty())
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return contents;
|
|
|
|
|
}
|
2013-05-15 12:46:08 +02:00
|
|
|
|
|
|
|
|
QMap<QString, QUrl> HelpItem::retrieveHelpLinks() const
|
|
|
|
|
{
|
|
|
|
|
if (m_helpLinks.isEmpty())
|
2013-08-29 19:00:34 +02:00
|
|
|
m_helpLinks = Core::HelpManager::linksForIdentifier(m_helpId);
|
2013-05-15 12:46:08 +02:00
|
|
|
return m_helpLinks;
|
|
|
|
|
}
|