2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2010-03-05 11:25:49 +01:00
|
|
|
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-06-17 00:01:27 +10:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Commercial Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
|
|
|
|
** accordance with the Qt Commercial License Agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Nokia.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** If you are unsure which license is appropriate for your use, please
|
2009-08-14 09:30:56 +02:00
|
|
|
** contact the sales department at http://qt.nokia.com/contact.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
**************************************************************************/
|
2008-12-02 15:08:31 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "cpphoverhandler.h"
|
2008-12-16 12:22:08 +01:00
|
|
|
#include "cppeditor.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
#include <coreplugin/icore.h>
|
2010-06-11 13:11:37 +02:00
|
|
|
#include <coreplugin/helpmanager.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <coreplugin/uniqueidmanager.h>
|
2008-12-16 12:22:08 +01:00
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
|
|
|
|
#include <cpptools/cppmodelmanagerinterface.h>
|
2009-01-19 12:39:20 +01:00
|
|
|
#include <extensionsystem/pluginmanager.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <texteditor/itexteditor.h>
|
2008-12-09 15:23:47 +01:00
|
|
|
#include <texteditor/basetexteditor.h>
|
2010-07-13 14:43:47 +02:00
|
|
|
#include <texteditor/displaysettings.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <debugger/debuggerconstants.h>
|
|
|
|
|
|
|
|
|
|
#include <FullySpecifiedType.h>
|
|
|
|
|
#include <Scope.h>
|
|
|
|
|
#include <Symbol.h>
|
|
|
|
|
#include <Symbols.h>
|
|
|
|
|
#include <cplusplus/ExpressionUnderCursor.h>
|
|
|
|
|
#include <cplusplus/Overview.h>
|
|
|
|
|
#include <cplusplus/TypeOfExpression.h>
|
2010-07-12 13:24:45 +02:00
|
|
|
#include <cplusplus/LookupContext.h>
|
|
|
|
|
#include <cplusplus/LookupItem.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-01-19 12:39:20 +01:00
|
|
|
#include <QtCore/QDir>
|
|
|
|
|
#include <QtCore/QFileInfo>
|
2010-07-20 12:35:08 +02:00
|
|
|
#include <QtCore/QtAlgorithms>
|
|
|
|
|
#include <QtCore/QStringBuilder>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <QtGui/QToolTip>
|
|
|
|
|
#include <QtGui/QTextCursor>
|
|
|
|
|
|
2008-12-16 12:22:08 +01:00
|
|
|
using namespace CppEditor::Internal;
|
2008-12-09 15:23:47 +01:00
|
|
|
using namespace CPlusPlus;
|
2009-01-20 11:52:04 +01:00
|
|
|
using namespace Core;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-07-12 13:24:45 +02:00
|
|
|
namespace {
|
2010-07-14 17:31:50 +02:00
|
|
|
void moveCursorToEndOfName(QTextCursor *tc) {
|
2010-07-12 13:24:45 +02:00
|
|
|
QTextDocument *doc = tc->document();
|
|
|
|
|
if (!doc)
|
|
|
|
|
return;
|
|
|
|
|
|
2010-07-14 17:31:50 +02:00
|
|
|
QChar ch = doc->characterAt(tc->position());
|
|
|
|
|
while (ch.isLetterOrNumber() || ch == QLatin1Char('_')) {
|
|
|
|
|
tc->movePosition(QTextCursor::NextCharacter);
|
|
|
|
|
ch = doc->characterAt(tc->position());
|
2010-07-12 13:24:45 +02:00
|
|
|
}
|
|
|
|
|
}
|
2010-07-20 12:35:08 +02:00
|
|
|
|
|
|
|
|
void buildClassHierarchyHelper(Symbol *symbol,
|
|
|
|
|
const LookupContext &context,
|
|
|
|
|
const Overview &overview,
|
|
|
|
|
QList<QStringList> *hierarchy) {
|
|
|
|
|
if (ClassOrNamespace *classSymbol = context.lookupType(symbol)) {
|
|
|
|
|
const QList<ClassOrNamespace *> &bases = classSymbol->usings();
|
|
|
|
|
foreach (ClassOrNamespace *baseClass, bases) {
|
|
|
|
|
const QList<Symbol *> &symbols = baseClass->symbols();
|
|
|
|
|
foreach (Symbol *baseSymbol, symbols) {
|
|
|
|
|
if (baseSymbol->isClass()) {
|
|
|
|
|
hierarchy->back().append(overview.prettyName(baseSymbol->name()));
|
|
|
|
|
buildClassHierarchyHelper(baseSymbol, context, overview, hierarchy);
|
|
|
|
|
hierarchy->append(hierarchy->back());
|
|
|
|
|
hierarchy->back().removeLast();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void buildClassHierarchy(Symbol *symbol,
|
|
|
|
|
const LookupContext &context,
|
|
|
|
|
const Overview &overview,
|
|
|
|
|
QList<QStringList> *hierarchy) {
|
|
|
|
|
if (hierarchy->isEmpty())
|
|
|
|
|
hierarchy->append(QStringList());
|
|
|
|
|
buildClassHierarchyHelper(symbol, context, overview, hierarchy);
|
|
|
|
|
hierarchy->removeLast();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct ClassHierarchyComp
|
|
|
|
|
{
|
|
|
|
|
bool operator()(const QStringList &a, const QStringList &b)
|
|
|
|
|
{ return a.size() < b.size(); }
|
|
|
|
|
};
|
2010-07-12 13:24:45 +02:00
|
|
|
}
|
|
|
|
|
|
2008-12-16 12:22:08 +01:00
|
|
|
CppHoverHandler::CppHoverHandler(QObject *parent)
|
2010-07-12 13:24:45 +02:00
|
|
|
: QObject(parent), m_modelManager(0), m_matchingHelpCandidate(-1)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-07-12 13:24:45 +02:00
|
|
|
m_modelManager =
|
|
|
|
|
ExtensionSystem::PluginManager::instance()->getObject<CppTools::CppModelManagerInterface>();
|
|
|
|
|
|
|
|
|
|
m_htmlDocExtractor.setLengthReference(1000, true);
|
2008-12-16 12:22:08 +01:00
|
|
|
|
|
|
|
|
// Listen for editor opened events in order to connect to tooltip/helpid requests
|
2010-06-11 13:11:37 +02:00
|
|
|
connect(ICore::instance()->editorManager(), SIGNAL(editorOpened(Core::IEditor *)),
|
2008-12-16 12:22:08 +01:00
|
|
|
this, SLOT(editorOpened(Core::IEditor *)));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2009-01-20 11:52:04 +01:00
|
|
|
void CppHoverHandler::editorOpened(IEditor *editor)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2008-12-16 12:22:08 +01:00
|
|
|
CPPEditorEditable *cppEditor = qobject_cast<CPPEditorEditable *>(editor);
|
|
|
|
|
if (!cppEditor)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
connect(cppEditor, SIGNAL(tooltipRequested(TextEditor::ITextEditor*, QPoint, int)),
|
|
|
|
|
this, SLOT(showToolTip(TextEditor::ITextEditor*, QPoint, int)));
|
|
|
|
|
|
|
|
|
|
connect(cppEditor, SIGNAL(contextHelpIdRequested(TextEditor::ITextEditor*, int)),
|
|
|
|
|
this, SLOT(updateContextHelpId(TextEditor::ITextEditor*, int)));
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-07-12 13:24:45 +02:00
|
|
|
void CppHoverHandler::updateContextHelpId(TextEditor::ITextEditor *editor, int pos)
|
|
|
|
|
{
|
|
|
|
|
if (!editor)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// If the tooltip is visible and there is a help match, this match is used to update the help
|
|
|
|
|
// id. Otherwise, the identification process happens.
|
|
|
|
|
if (!QToolTip::isVisible() || m_matchingHelpCandidate == -1)
|
|
|
|
|
identifyMatch(editor, pos);
|
|
|
|
|
|
|
|
|
|
if (m_matchingHelpCandidate != -1)
|
|
|
|
|
editor->setContextHelpId(m_helpCandidates.at(m_matchingHelpCandidate).m_helpId);
|
|
|
|
|
else
|
|
|
|
|
editor->setContextHelpId(QString());
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-16 12:22:08 +01:00
|
|
|
void CppHoverHandler::showToolTip(TextEditor::ITextEditor *editor, const QPoint &point, int pos)
|
|
|
|
|
{
|
2010-07-20 12:35:08 +02:00
|
|
|
TextEditor::BaseTextEditor *baseEditor = baseTextEditor(editor);
|
|
|
|
|
if (!baseEditor)
|
2008-12-02 12:01:29 +01:00
|
|
|
return;
|
|
|
|
|
|
2010-07-12 13:24:45 +02:00
|
|
|
editor->setContextHelpId(QString());
|
2008-12-16 12:22:08 +01:00
|
|
|
|
2010-07-12 13:24:45 +02:00
|
|
|
ICore *core = ICore::instance();
|
|
|
|
|
const int dbgContext =
|
|
|
|
|
core->uniqueIDManager()->uniqueIdentifier(Debugger::Constants::C_DEBUGMODE);
|
|
|
|
|
if (core->hasContext(dbgContext))
|
2008-12-02 12:01:29 +01:00
|
|
|
return;
|
|
|
|
|
|
2010-07-12 13:24:45 +02:00
|
|
|
identifyMatch(editor, pos);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-07-12 13:24:45 +02:00
|
|
|
if (m_toolTip.isEmpty()) {
|
2008-12-02 12:01:29 +01:00
|
|
|
QToolTip::hideText();
|
2010-07-12 13:24:45 +02:00
|
|
|
} else {
|
2010-07-20 12:35:08 +02:00
|
|
|
if (!m_classHierarchy.isEmpty())
|
|
|
|
|
generateDiagramTooltip(baseEditor->displaySettings().m_integrateDocsIntoTooltips);
|
|
|
|
|
else
|
|
|
|
|
generateNormalTooltip(baseEditor->displaySettings().m_integrateDocsIntoTooltips);
|
2010-07-12 13:24:45 +02:00
|
|
|
|
2010-07-20 12:35:08 +02:00
|
|
|
if (m_matchingHelpCandidate != -1)
|
|
|
|
|
addF1ToTooltip();
|
2010-07-12 13:24:45 +02:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
const QPoint pnt = point - QPoint(0,
|
|
|
|
|
#ifdef Q_WS_WIN
|
|
|
|
|
24
|
|
|
|
|
#else
|
|
|
|
|
16
|
|
|
|
|
#endif
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
QToolTip::showText(pnt, m_toolTip);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-12 13:24:45 +02:00
|
|
|
void CppHoverHandler::identifyMatch(TextEditor::ITextEditor *editor, int pos)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-07-12 13:24:45 +02:00
|
|
|
resetMatchings();
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-07-12 13:24:45 +02:00
|
|
|
if (!m_modelManager)
|
|
|
|
|
return;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-07-12 13:24:45 +02:00
|
|
|
const Snapshot &snapshot = m_modelManager->snapshot();
|
|
|
|
|
Document::Ptr doc = snapshot.document(editor->file()->fileName());
|
|
|
|
|
if (!doc)
|
|
|
|
|
return;
|
2009-02-11 10:01:36 +01:00
|
|
|
|
2010-07-12 13:24:45 +02:00
|
|
|
int line = 0;
|
|
|
|
|
int column = 0;
|
|
|
|
|
editor->convertPosition(pos, &line, &column);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-07-12 13:24:45 +02:00
|
|
|
if (!matchDiagnosticMessage(doc, line) &&
|
|
|
|
|
!matchIncludeFile(doc, line) &&
|
|
|
|
|
!matchMacroInUse(doc, pos)) {
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-07-12 13:24:45 +02:00
|
|
|
TextEditor::BaseTextEditor *baseEditor = baseTextEditor(editor);
|
|
|
|
|
if (!baseEditor)
|
|
|
|
|
return;
|
2009-02-16 15:43:24 +01:00
|
|
|
|
2010-07-12 13:24:45 +02:00
|
|
|
bool extraSelectionTooltip = false;
|
|
|
|
|
if (!baseEditor->extraSelectionTooltip(pos).isEmpty()) {
|
|
|
|
|
m_toolTip = baseEditor->extraSelectionTooltip(pos);
|
|
|
|
|
extraSelectionTooltip = true;
|
|
|
|
|
}
|
2009-02-16 15:43:24 +01:00
|
|
|
|
2010-07-12 13:24:45 +02:00
|
|
|
QTextCursor tc(baseEditor->document());
|
|
|
|
|
tc.setPosition(pos);
|
2010-07-14 17:31:50 +02:00
|
|
|
moveCursorToEndOfName(&tc);
|
2009-02-16 17:55:05 +01:00
|
|
|
|
2010-07-12 13:24:45 +02:00
|
|
|
// Fetch the expression's code
|
|
|
|
|
ExpressionUnderCursor expressionUnderCursor;
|
|
|
|
|
const QString &expression = expressionUnderCursor(tc);
|
|
|
|
|
Scope *scope = doc->scopeAt(line, column);
|
2009-02-16 15:43:24 +01:00
|
|
|
|
2010-07-12 13:24:45 +02:00
|
|
|
TypeOfExpression typeOfExpression;
|
|
|
|
|
typeOfExpression.init(doc, snapshot);
|
|
|
|
|
const QList<LookupItem> &lookupItems = typeOfExpression(expression, scope);
|
|
|
|
|
if (lookupItems.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const LookupItem &lookupItem = lookupItems.first(); // ### TODO: select the best candidate.
|
2010-07-20 12:35:08 +02:00
|
|
|
handleLookupItemMatch(lookupItem, typeOfExpression.context(), !extraSelectionTooltip);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-07-12 13:24:45 +02:00
|
|
|
evaluateHelpCandidates();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-07-12 13:24:45 +02:00
|
|
|
bool CppHoverHandler::matchDiagnosticMessage(const CPlusPlus::Document::Ptr &document,
|
2010-07-14 14:20:17 +02:00
|
|
|
unsigned line)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-07-12 13:24:45 +02:00
|
|
|
foreach (const Document::DiagnosticMessage &m, document->diagnosticMessages()) {
|
2010-07-14 14:20:17 +02:00
|
|
|
if (m.line() == line) {
|
2008-12-18 10:52:29 +01:00
|
|
|
m_toolTip = m.text();
|
2010-07-12 13:24:45 +02:00
|
|
|
return true;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2008-12-18 10:52:29 +01:00
|
|
|
}
|
2010-07-12 13:24:45 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-07-14 14:20:17 +02:00
|
|
|
bool CppHoverHandler::matchIncludeFile(const CPlusPlus::Document::Ptr &document, unsigned line)
|
2010-07-12 13:24:45 +02:00
|
|
|
{
|
|
|
|
|
foreach (const Document::Include &includeFile, document->includes()) {
|
2010-07-14 14:20:17 +02:00
|
|
|
if (includeFile.line() == line) {
|
2010-07-12 13:24:45 +02:00
|
|
|
m_toolTip = QDir::toNativeSeparators(includeFile.fileName());
|
|
|
|
|
const QString &fileName = QFileInfo(includeFile.fileName()).fileName();
|
2010-07-20 12:35:08 +02:00
|
|
|
m_helpCandidates.append(HelpCandidate(fileName, fileName, HelpCandidate::Brief));
|
2010-07-12 13:24:45 +02:00
|
|
|
return true;
|
2008-12-10 17:21:01 +01:00
|
|
|
}
|
|
|
|
|
}
|
2010-07-12 13:24:45 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
2008-12-10 17:21:01 +01:00
|
|
|
|
2010-07-14 14:20:17 +02:00
|
|
|
bool CppHoverHandler::matchMacroInUse(const CPlusPlus::Document::Ptr &document, unsigned pos)
|
2010-07-12 13:24:45 +02:00
|
|
|
{
|
|
|
|
|
foreach (const Document::MacroUse &use, document->macroUses()) {
|
|
|
|
|
if (use.contains(pos)) {
|
2010-07-14 14:20:17 +02:00
|
|
|
const unsigned begin = use.begin();
|
2010-07-13 12:46:43 +02:00
|
|
|
const QString &name = use.macro().name();
|
|
|
|
|
if (pos < begin + name.length()) {
|
|
|
|
|
m_toolTip = use.macro().toString();
|
|
|
|
|
m_helpCandidates.append(HelpCandidate(name, name, HelpCandidate::Macro));
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2010-07-12 13:24:45 +02:00
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-07-20 12:35:08 +02:00
|
|
|
void CppHoverHandler::handleLookupItemMatch(const LookupItem &lookupItem,
|
|
|
|
|
const LookupContext &context,
|
|
|
|
|
const bool assignTooltip)
|
2010-07-12 13:24:45 +02:00
|
|
|
{
|
|
|
|
|
Symbol *matchingDeclaration = lookupItem.declaration();
|
|
|
|
|
FullySpecifiedType matchingType = lookupItem.type();
|
2010-05-14 09:52:53 +02:00
|
|
|
|
2010-07-12 13:24:45 +02:00
|
|
|
Overview overview;
|
|
|
|
|
overview.setShowArgumentNames(true);
|
|
|
|
|
overview.setShowReturnTypes(true);
|
|
|
|
|
|
|
|
|
|
if (!matchingDeclaration && assignTooltip) {
|
2010-07-13 17:19:36 +02:00
|
|
|
m_toolTip = overview.prettyType(matchingType, QString());
|
2010-07-12 13:24:45 +02:00
|
|
|
} else {
|
|
|
|
|
QString qualifiedName;
|
|
|
|
|
if (matchingDeclaration->enclosingSymbol()->isClass() ||
|
|
|
|
|
matchingDeclaration->enclosingSymbol()->isNamespace() ||
|
|
|
|
|
matchingDeclaration->enclosingSymbol()->isEnum()) {
|
2010-07-19 16:03:49 +02:00
|
|
|
qualifiedName.append(overview.prettyName(
|
|
|
|
|
LookupContext::fullyQualifiedName(matchingDeclaration)));
|
2010-07-20 12:35:08 +02:00
|
|
|
|
|
|
|
|
if (matchingDeclaration->isClass() ||
|
|
|
|
|
matchingDeclaration->isForwardClassDeclaration()) {
|
|
|
|
|
buildClassHierarchy(matchingDeclaration, context, overview, &m_classHierarchy);
|
|
|
|
|
}
|
2010-07-13 17:19:36 +02:00
|
|
|
} else {
|
|
|
|
|
qualifiedName.append(overview.prettyName(matchingDeclaration->name()));
|
2010-07-12 13:24:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (assignTooltip) {
|
|
|
|
|
if (matchingDeclaration->isClass() ||
|
|
|
|
|
matchingDeclaration->isNamespace() ||
|
|
|
|
|
matchingDeclaration->isForwardClassDeclaration() ||
|
|
|
|
|
matchingDeclaration->isEnum()) {
|
|
|
|
|
m_toolTip = qualifiedName;
|
|
|
|
|
} else {
|
|
|
|
|
m_toolTip = overview.prettyType(matchingType, qualifiedName);
|
2010-04-06 13:30:41 +02:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2010-07-12 13:24:45 +02:00
|
|
|
|
2010-07-21 17:25:58 +02:00
|
|
|
HelpCandidate::Category helpCategory = HelpCandidate::Unknown;
|
2010-07-13 17:19:36 +02:00
|
|
|
if (matchingDeclaration->isNamespace() ||
|
|
|
|
|
matchingDeclaration->isClass() ||
|
|
|
|
|
matchingDeclaration->isForwardClassDeclaration()) {
|
|
|
|
|
helpCategory = HelpCandidate::ClassOrNamespace;
|
2010-07-21 17:25:58 +02:00
|
|
|
} else if (matchingDeclaration->isEnum() ||
|
|
|
|
|
matchingDeclaration->enclosingSymbol()->isEnum()) {
|
2010-07-13 17:19:36 +02:00
|
|
|
helpCategory = HelpCandidate::Enum;
|
|
|
|
|
} else if (matchingDeclaration->isTypedef()) {
|
|
|
|
|
helpCategory = HelpCandidate::Typedef;
|
2010-07-21 17:25:58 +02:00
|
|
|
} else if (matchingDeclaration->isFunction() ||
|
|
|
|
|
(matchingType.isValid() && matchingType->isFunctionType())){
|
2010-07-13 17:19:36 +02:00
|
|
|
helpCategory = HelpCandidate::Function;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-21 17:25:58 +02:00
|
|
|
if (helpCategory != HelpCandidate::Unknown) {
|
|
|
|
|
// Help identifiers are simply the name with no signature, arguments or return type.
|
|
|
|
|
// They might or might not include a qualification. So two candidates are created.
|
|
|
|
|
overview.setShowArgumentNames(false);
|
|
|
|
|
overview.setShowReturnTypes(false);
|
|
|
|
|
overview.setShowFunctionSignatures(false);
|
|
|
|
|
const QString &simpleName = overview.prettyName(matchingDeclaration->name());
|
|
|
|
|
|
|
|
|
|
QString mark;
|
|
|
|
|
if (matchingType.isValid() && matchingType->isFunctionType()) {
|
|
|
|
|
overview.setShowFunctionSignatures(true);
|
|
|
|
|
mark = overview.prettyType(matchingType, simpleName);
|
|
|
|
|
} else if (matchingDeclaration->enclosingSymbol()->isEnum()) {
|
|
|
|
|
Symbol *enumSymbol = matchingDeclaration->enclosingSymbol()->asEnum();
|
|
|
|
|
mark = overview.prettyName(enumSymbol->name());
|
|
|
|
|
} else {
|
|
|
|
|
mark = simpleName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_helpCandidates.append(HelpCandidate(simpleName, mark, helpCategory));
|
|
|
|
|
m_helpCandidates.append(HelpCandidate(qualifiedName, mark, helpCategory));
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2010-07-12 13:24:45 +02:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-07-12 13:24:45 +02:00
|
|
|
void CppHoverHandler::evaluateHelpCandidates()
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < m_helpCandidates.size(); ++i) {
|
|
|
|
|
if (helpIdExists(m_helpCandidates.at(i).m_helpId)) {
|
|
|
|
|
m_matchingHelpCandidate = i;
|
|
|
|
|
return;
|
2008-12-10 11:58:25 +01:00
|
|
|
}
|
|
|
|
|
}
|
2010-07-12 13:24:45 +02:00
|
|
|
}
|
2008-12-10 11:58:25 +01:00
|
|
|
|
2010-07-12 13:24:45 +02:00
|
|
|
bool CppHoverHandler::helpIdExists(const QString &helpId) const
|
|
|
|
|
{
|
|
|
|
|
QMap<QString, QUrl> helpLinks = Core::HelpManager::instance()->linksForIdentifier(helpId);
|
|
|
|
|
if (!helpLinks.isEmpty())
|
|
|
|
|
return true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2008-12-18 10:52:29 +01:00
|
|
|
|
2010-07-20 12:35:08 +02:00
|
|
|
QString CppHoverHandler::getDocContents() const
|
2010-07-12 13:24:45 +02:00
|
|
|
{
|
|
|
|
|
Q_ASSERT(m_matchingHelpCandidate >= 0);
|
|
|
|
|
|
2010-07-20 12:35:08 +02:00
|
|
|
return getDocContents(m_helpCandidates.at(m_matchingHelpCandidate));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString CppHoverHandler::getDocContents(const HelpCandidate &help) const
|
|
|
|
|
{
|
2010-07-12 13:24:45 +02:00
|
|
|
QString contents;
|
|
|
|
|
QMap<QString, QUrl> helpLinks =
|
|
|
|
|
Core::HelpManager::instance()->linksForIdentifier(help.m_helpId);
|
|
|
|
|
foreach (const QUrl &url, helpLinks) {
|
|
|
|
|
const QByteArray &html = Core::HelpManager::instance()->fileData(url);
|
|
|
|
|
switch (help.m_category) {
|
2010-07-20 12:35:08 +02:00
|
|
|
case HelpCandidate::Brief:
|
2010-07-21 17:25:58 +02:00
|
|
|
contents = m_htmlDocExtractor.getClassOrNamespaceBrief(html, help.m_docMark);
|
2010-07-12 13:24:45 +02:00
|
|
|
break;
|
|
|
|
|
case HelpCandidate::ClassOrNamespace:
|
2010-07-21 17:25:58 +02:00
|
|
|
contents = m_htmlDocExtractor.getClassOrNamespaceDescription(html, help.m_docMark);
|
2010-07-12 13:24:45 +02:00
|
|
|
break;
|
|
|
|
|
case HelpCandidate::Function:
|
2010-07-21 17:25:58 +02:00
|
|
|
contents = m_htmlDocExtractor.getFunctionDescription(html, help.m_docMark);
|
2010-07-12 13:24:45 +02:00
|
|
|
break;
|
|
|
|
|
case HelpCandidate::Enum:
|
2010-07-21 17:25:58 +02:00
|
|
|
contents = m_htmlDocExtractor.getEnumDescription(html, help.m_docMark);
|
2010-07-12 13:24:45 +02:00
|
|
|
break;
|
|
|
|
|
case HelpCandidate::Typedef:
|
2010-07-21 17:25:58 +02:00
|
|
|
contents = m_htmlDocExtractor.getTypedefDescription(html, help.m_docMark);
|
2010-07-12 13:24:45 +02:00
|
|
|
break;
|
|
|
|
|
case HelpCandidate::Macro:
|
2010-07-21 17:25:58 +02:00
|
|
|
contents = m_htmlDocExtractor.getMacroDescription(html, help.m_docMark);
|
2010-07-12 13:24:45 +02:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
2009-07-22 15:55:45 +02:00
|
|
|
}
|
2010-07-12 13:24:45 +02:00
|
|
|
|
|
|
|
|
if (!contents.isEmpty())
|
|
|
|
|
break;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2010-07-12 13:24:45 +02:00
|
|
|
return contents;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-20 12:35:08 +02:00
|
|
|
void CppHoverHandler::generateDiagramTooltip(const bool integrateDocs)
|
|
|
|
|
{
|
|
|
|
|
QString clazz = m_toolTip;
|
|
|
|
|
|
|
|
|
|
qSort(m_classHierarchy.begin(), m_classHierarchy.end(), ClassHierarchyComp());
|
|
|
|
|
|
|
|
|
|
QStringList directBaseClasses;
|
|
|
|
|
foreach (const QStringList &hierarchy, m_classHierarchy) {
|
|
|
|
|
if (hierarchy.size() > 1)
|
|
|
|
|
break;
|
|
|
|
|
directBaseClasses.append(hierarchy.at(0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString diagram(QLatin1String("<table>"));
|
|
|
|
|
for (int i = 0; i < directBaseClasses.size(); ++i) {
|
|
|
|
|
if (i == 0) {
|
|
|
|
|
diagram.append(QString(
|
|
|
|
|
"<tr><td>%1</td><td>"
|
|
|
|
|
"<img src=\":/cppeditor/images/rightarrow.png\"></td>"
|
|
|
|
|
"<td>%2</td></tr>").arg(m_toolTip).arg(directBaseClasses.at(i)));
|
|
|
|
|
} else {
|
|
|
|
|
diagram.append(QString(
|
|
|
|
|
"<tr><td></td><td>"
|
|
|
|
|
"<img src=\":/cppeditor/images/larrow.png\"></td>"
|
|
|
|
|
"<td>%1</td></tr>").arg(directBaseClasses.at(i)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
diagram.append(QLatin1String("</table>"));
|
|
|
|
|
m_toolTip = diagram;
|
|
|
|
|
|
|
|
|
|
if (integrateDocs) {
|
|
|
|
|
if (m_matchingHelpCandidate != -1) {
|
|
|
|
|
m_toolTip.append(getDocContents());
|
|
|
|
|
} else {
|
|
|
|
|
// Look for documented base classes. Diagram the nearest one or the nearest ones (in
|
|
|
|
|
// the case there are many at the same level).
|
|
|
|
|
int helpLevel = 0;
|
|
|
|
|
QList<int> baseClassesWithHelp;
|
|
|
|
|
for (int i = 0; i < m_classHierarchy.size(); ++i) {
|
|
|
|
|
const QStringList &hierarchy = m_classHierarchy.at(i);
|
|
|
|
|
if (helpLevel != 0 && hierarchy.size() != helpLevel)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
const QString &name = hierarchy.last();
|
|
|
|
|
if (helpIdExists(name)) {
|
|
|
|
|
baseClassesWithHelp.append(i);
|
|
|
|
|
if (helpLevel == 0)
|
|
|
|
|
helpLevel = hierarchy.size();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!baseClassesWithHelp.isEmpty()) {
|
|
|
|
|
// Choose the first one as the help match.
|
|
|
|
|
QString base = m_classHierarchy.at(baseClassesWithHelp.at(0)).last();
|
|
|
|
|
HelpCandidate help(base, base, HelpCandidate::ClassOrNamespace);
|
|
|
|
|
m_helpCandidates.append(help);
|
|
|
|
|
m_matchingHelpCandidate = m_helpCandidates.size() - 1;
|
|
|
|
|
|
|
|
|
|
if (baseClassesWithHelp.size() == 1 && helpLevel == 1) {
|
|
|
|
|
m_toolTip.append(getDocContents(help));
|
|
|
|
|
} else {
|
|
|
|
|
foreach (int hierarchyIndex, baseClassesWithHelp) {
|
|
|
|
|
m_toolTip.append(QLatin1String("<p>"));
|
|
|
|
|
const QStringList &hierarchy = m_classHierarchy.at(hierarchyIndex);
|
|
|
|
|
Q_ASSERT(helpLevel <= hierarchy.size());
|
|
|
|
|
|
|
|
|
|
// Following contents are inside tables so they are on the exact same
|
|
|
|
|
// alignment as the top level diagram.
|
|
|
|
|
diagram = QString(QLatin1String("<table><tr><td>%1</td>")).arg(clazz);
|
|
|
|
|
for (int i = 0; i < helpLevel; ++i) {
|
|
|
|
|
diagram.append(
|
|
|
|
|
QLatin1String("<td><img src=\":/cppeditor/images/rightarrow.png\">"
|
|
|
|
|
"</td><td>") %
|
|
|
|
|
hierarchy.at(i) %
|
|
|
|
|
QLatin1String("</td>"));
|
|
|
|
|
}
|
|
|
|
|
diagram.append(QLatin1String("</tr></table>"));
|
|
|
|
|
|
|
|
|
|
base = hierarchy.at(helpLevel - 1);
|
|
|
|
|
QString contents =
|
|
|
|
|
getDocContents(HelpCandidate(base, base, HelpCandidate::Brief));
|
|
|
|
|
if (!contents.isEmpty()) {
|
|
|
|
|
m_toolTip.append(diagram % QLatin1String("<table><tr><td>") %
|
|
|
|
|
contents % QLatin1String("</td></tr></table>"));
|
|
|
|
|
}
|
|
|
|
|
m_toolTip.append(QLatin1String("</p>"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CppHoverHandler::generateNormalTooltip(const bool integrateDocs)
|
|
|
|
|
{
|
|
|
|
|
if (m_matchingHelpCandidate != -1) {
|
|
|
|
|
QString contents;
|
|
|
|
|
if (integrateDocs)
|
|
|
|
|
contents = getDocContents();
|
|
|
|
|
if (!contents.isEmpty()) {
|
|
|
|
|
HelpCandidate::Category cat = m_helpCandidates.at(m_matchingHelpCandidate).m_category;
|
|
|
|
|
if (cat == HelpCandidate::ClassOrNamespace)
|
|
|
|
|
m_toolTip.append(contents);
|
|
|
|
|
else
|
|
|
|
|
m_toolTip = contents;
|
|
|
|
|
} else {
|
|
|
|
|
m_toolTip = Qt::escape(m_toolTip);
|
|
|
|
|
m_toolTip.prepend(QLatin1String("<nobr>"));
|
|
|
|
|
m_toolTip.append(QLatin1String("</nobr>"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CppHoverHandler::addF1ToTooltip()
|
|
|
|
|
{
|
|
|
|
|
m_toolTip = QString(QLatin1String("<table><tr><td valign=middle>%1</td><td> "
|
|
|
|
|
"<img src=\":/cppeditor/images/f1.png\"></td>"
|
|
|
|
|
"</tr></table>")).arg(m_toolTip);
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-12 13:24:45 +02:00
|
|
|
void CppHoverHandler::resetMatchings()
|
|
|
|
|
{
|
|
|
|
|
m_matchingHelpCandidate = -1;
|
|
|
|
|
m_helpCandidates.clear();
|
|
|
|
|
m_toolTip.clear();
|
2010-07-20 12:35:08 +02:00
|
|
|
m_classHierarchy.clear();
|
2010-07-12 13:24:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TextEditor::BaseTextEditor *CppHoverHandler::baseTextEditor(TextEditor::ITextEditor *editor)
|
|
|
|
|
{
|
2010-07-20 12:35:08 +02:00
|
|
|
if (!editor)
|
|
|
|
|
return 0;
|
2010-07-12 13:24:45 +02:00
|
|
|
return qobject_cast<TextEditor::BaseTextEditor *>(editor->widget());
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|