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
|
|
|
|
2010-08-03 15:42:14 +02:00
|
|
|
#include <coreplugin/editormanager/ieditor.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>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
#include <FullySpecifiedType.h>
|
2010-07-27 09:42:21 +02:00
|
|
|
#include <Names.h>
|
|
|
|
|
#include <CoreTypes.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
#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
|
|
|
|
2010-08-05 11:41:21 +02:00
|
|
|
#include <QtCore/QSet>
|
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/QTextCursor>
|
|
|
|
|
|
2010-07-28 16:33:44 +02:00
|
|
|
#include <algorithm>
|
|
|
|
|
|
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-27 09:42:21 +02:00
|
|
|
QString removeClassNameQualification(const QString &name) {
|
|
|
|
|
const int index = name.lastIndexOf(QLatin1Char(':'));
|
|
|
|
|
if (index == -1)
|
|
|
|
|
return name;
|
|
|
|
|
else
|
|
|
|
|
return name.right(name.length() - index - 1);
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
2010-08-05 11:41:21 +02:00
|
|
|
void buildClassHierarchyHelper(ClassOrNamespace *classSymbol,
|
2010-07-20 12:35:08 +02:00
|
|
|
const LookupContext &context,
|
|
|
|
|
const Overview &overview,
|
2010-08-05 11:41:21 +02:00
|
|
|
QList<QStringList> *hierarchy,
|
|
|
|
|
QSet<ClassOrNamespace *> *visited) {
|
|
|
|
|
visited->insert(classSymbol);
|
|
|
|
|
const QList<ClassOrNamespace *> &bases = classSymbol->usings();
|
|
|
|
|
foreach (ClassOrNamespace *baseClass, bases) {
|
|
|
|
|
const QList<Symbol *> &symbols = baseClass->symbols();
|
|
|
|
|
foreach (Symbol *baseSymbol, symbols) {
|
|
|
|
|
if (baseSymbol->isClass() && (
|
|
|
|
|
classSymbol = context.lookupType(baseSymbol)) &&
|
|
|
|
|
!visited->contains(classSymbol)) {
|
|
|
|
|
const QString &qualifiedName = overview.prettyName(
|
|
|
|
|
LookupContext::fullyQualifiedName(baseSymbol));
|
|
|
|
|
if (!qualifiedName.isEmpty()) {
|
|
|
|
|
hierarchy->back().append(qualifiedName);
|
|
|
|
|
buildClassHierarchyHelper(classSymbol,
|
|
|
|
|
context,
|
|
|
|
|
overview,
|
|
|
|
|
hierarchy,
|
|
|
|
|
visited);
|
|
|
|
|
hierarchy->append(hierarchy->back());
|
|
|
|
|
hierarchy->back().removeLast();
|
2010-07-20 12:35:08 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void buildClassHierarchy(Symbol *symbol,
|
|
|
|
|
const LookupContext &context,
|
|
|
|
|
const Overview &overview,
|
|
|
|
|
QList<QStringList> *hierarchy) {
|
2010-08-05 11:41:21 +02:00
|
|
|
if (ClassOrNamespace *classSymbol = context.lookupType(symbol)) {
|
2010-07-20 12:35:08 +02:00
|
|
|
hierarchy->append(QStringList());
|
2010-08-05 11:41:21 +02:00
|
|
|
QSet<ClassOrNamespace *> visited;
|
|
|
|
|
buildClassHierarchyHelper(classSymbol, context, overview, hierarchy, &visited);
|
|
|
|
|
hierarchy->removeLast();
|
|
|
|
|
}
|
2010-07-20 12:35:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct ClassHierarchyComp
|
|
|
|
|
{
|
|
|
|
|
bool operator()(const QStringList &a, const QStringList &b)
|
|
|
|
|
{ return a.size() < b.size(); }
|
|
|
|
|
};
|
2010-07-12 13:24:45 +02:00
|
|
|
}
|
|
|
|
|
|
2010-08-03 15:42:14 +02:00
|
|
|
CppHoverHandler::CppHoverHandler(QObject *parent) : BaseHoverHandler(parent), m_modelManager(0)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-07-12 13:24:45 +02:00
|
|
|
m_modelManager =
|
|
|
|
|
ExtensionSystem::PluginManager::instance()->getObject<CppTools::CppModelManagerInterface>();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-08-03 15:42:14 +02:00
|
|
|
bool CppHoverHandler::acceptEditor(IEditor *editor)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2008-12-16 12:22:08 +01:00
|
|
|
CPPEditorEditable *cppEditor = qobject_cast<CPPEditorEditable *>(editor);
|
2010-08-03 15:42:14 +02:00
|
|
|
if (cppEditor)
|
|
|
|
|
return true;
|
|
|
|
|
return false;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
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
|
|
|
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-27 09:42:21 +02:00
|
|
|
if (!matchDiagnosticMessage(doc, line)) {
|
|
|
|
|
if (!matchIncludeFile(doc, line) && !matchMacroInUse(doc, pos)) {
|
|
|
|
|
TextEditor::BaseTextEditor *baseEditor = baseTextEditor(editor);
|
|
|
|
|
if (!baseEditor)
|
|
|
|
|
return;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-07-27 09:42:21 +02:00
|
|
|
bool extraSelectionTooltip = false;
|
|
|
|
|
if (!baseEditor->extraSelectionTooltip(pos).isEmpty()) {
|
2010-08-03 15:42:14 +02:00
|
|
|
setToolTip(baseEditor->extraSelectionTooltip(pos));
|
2010-07-27 09:42:21 +02:00
|
|
|
extraSelectionTooltip = true;
|
|
|
|
|
}
|
2009-02-16 15:43:24 +01:00
|
|
|
|
2010-07-27 09:42:21 +02:00
|
|
|
QTextCursor tc(baseEditor->document());
|
|
|
|
|
tc.setPosition(pos);
|
|
|
|
|
moveCursorToEndOfName(&tc);
|
2009-02-16 15:43:24 +01:00
|
|
|
|
2010-07-27 09:42:21 +02:00
|
|
|
// Fetch the expression's code
|
|
|
|
|
ExpressionUnderCursor expressionUnderCursor;
|
|
|
|
|
const QString &expression = expressionUnderCursor(tc);
|
|
|
|
|
Scope *scope = doc->scopeAt(line, column);
|
2009-02-16 17:55:05 +01:00
|
|
|
|
2010-07-27 09:42:21 +02:00
|
|
|
TypeOfExpression typeOfExpression;
|
|
|
|
|
typeOfExpression.init(doc, snapshot);
|
|
|
|
|
const QList<LookupItem> &lookupItems = typeOfExpression(expression, scope);
|
|
|
|
|
if (lookupItems.isEmpty())
|
|
|
|
|
return;
|
2009-02-16 15:43:24 +01:00
|
|
|
|
2010-07-27 09:42:21 +02:00
|
|
|
const LookupItem &lookupItem = lookupItems.first(); // ### TODO: select best candidate.
|
|
|
|
|
handleLookupItemMatch(lookupItem, typeOfExpression.context(), !extraSelectionTooltip);
|
|
|
|
|
}
|
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) {
|
2010-08-03 15:42:14 +02:00
|
|
|
setToolTip(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-08-03 15:42:14 +02:00
|
|
|
setToolTip(QDir::toNativeSeparators(includeFile.fileName()));
|
2010-07-12 13:24:45 +02:00
|
|
|
const QString &fileName = QFileInfo(includeFile.fileName()).fileName();
|
2010-08-03 15:42:14 +02:00
|
|
|
addHelpCandidate(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()) {
|
2010-08-03 15:42:14 +02:00
|
|
|
setToolTip(use.macro().toString());
|
|
|
|
|
addHelpCandidate(HelpCandidate(name, name, HelpCandidate::Macro));
|
2010-07-13 12:46:43 +02:00
|
|
|
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-08-03 15:42:14 +02:00
|
|
|
setToolTip(overview.prettyType(matchingType, QString()));
|
2010-07-12 13:24:45 +02:00
|
|
|
} else {
|
2010-07-27 09:42:21 +02:00
|
|
|
QString name;
|
2010-08-11 12:26:02 +02:00
|
|
|
if (matchingDeclaration->scope()->isClass() ||
|
|
|
|
|
matchingDeclaration->scope()->isNamespace() ||
|
|
|
|
|
matchingDeclaration->scope()->isEnum()) {
|
2010-07-27 09:42:21 +02:00
|
|
|
name.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 {
|
2010-07-27 09:42:21 +02:00
|
|
|
name.append(overview.prettyName(matchingDeclaration->name()));
|
2010-07-12 13:24:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (assignTooltip) {
|
|
|
|
|
if (matchingDeclaration->isClass() ||
|
|
|
|
|
matchingDeclaration->isNamespace() ||
|
|
|
|
|
matchingDeclaration->isForwardClassDeclaration() ||
|
|
|
|
|
matchingDeclaration->isEnum()) {
|
2010-08-03 15:42:14 +02:00
|
|
|
setToolTip(name);
|
2010-07-12 13:24:45 +02:00
|
|
|
} else {
|
2010-08-03 15:42:14 +02:00
|
|
|
setToolTip(overview.prettyType(matchingType, name));
|
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() ||
|
2010-08-11 12:26:02 +02:00
|
|
|
matchingDeclaration->scope()->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-27 09:42:21 +02:00
|
|
|
} else if (matchingDeclaration->isDeclaration() && matchingType.isValid()) {
|
|
|
|
|
const Name *typeName = 0;
|
|
|
|
|
if (matchingType->isNamedType()) {
|
|
|
|
|
typeName = matchingType->asNamedType()->name();
|
|
|
|
|
} else if (matchingType->isPointerType() || matchingType->isReferenceType()) {
|
|
|
|
|
FullySpecifiedType type;
|
|
|
|
|
if (matchingType->isPointerType())
|
|
|
|
|
type = matchingType->asPointerType()->elementType();
|
|
|
|
|
else
|
|
|
|
|
type = matchingType->asReferenceType()->elementType();
|
|
|
|
|
if (type->isNamedType())
|
|
|
|
|
typeName = type->asNamedType()->name();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (typeName) {
|
|
|
|
|
if (ClassOrNamespace *clazz = context.lookupType(typeName, lookupItem.scope())) {
|
|
|
|
|
if (!clazz->symbols().isEmpty()) {
|
|
|
|
|
Symbol *symbol = clazz->symbols().at(0);
|
|
|
|
|
matchingDeclaration = symbol;
|
|
|
|
|
name = overview.prettyName(LookupContext::fullyQualifiedName(symbol));
|
2010-08-03 15:42:14 +02:00
|
|
|
setToolTip(name);
|
2010-07-27 09:42:21 +02:00
|
|
|
buildClassHierarchy(symbol, context, overview, &m_classHierarchy);
|
|
|
|
|
helpCategory = HelpCandidate::ClassOrNamespace;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-07-13 17:19:36 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-21 17:25:58 +02:00
|
|
|
if (helpCategory != HelpCandidate::Unknown) {
|
2010-07-27 09:42:21 +02:00
|
|
|
QString docMark = overview.prettyName(matchingDeclaration->name());
|
|
|
|
|
|
2010-07-21 17:25:58 +02:00
|
|
|
if (matchingType.isValid() && matchingType->isFunctionType()) {
|
2010-07-27 09:42:21 +02:00
|
|
|
// Functions marks can be found either by the main overload or signature based
|
|
|
|
|
// (with no argument names and no return). Help ids have no signature at all.
|
|
|
|
|
overview.setShowArgumentNames(false);
|
|
|
|
|
overview.setShowReturnTypes(false);
|
|
|
|
|
docMark = overview.prettyType(matchingType, docMark);
|
|
|
|
|
overview.setShowFunctionSignatures(false);
|
|
|
|
|
const QString &functionName = overview.prettyName(matchingDeclaration->name());
|
2010-08-03 15:42:14 +02:00
|
|
|
addHelpCandidate(HelpCandidate(functionName, docMark, helpCategory));
|
2010-08-11 12:26:02 +02:00
|
|
|
} else if (matchingDeclaration->scope()->isEnum()) {
|
|
|
|
|
Symbol *enumSymbol = matchingDeclaration->scope()->asEnum();
|
2010-07-27 09:42:21 +02:00
|
|
|
docMark = overview.prettyName(enumSymbol->name());
|
2010-07-21 17:25:58 +02:00
|
|
|
}
|
|
|
|
|
|
2010-08-03 15:42:14 +02:00
|
|
|
addHelpCandidate(HelpCandidate(name, docMark, helpCategory));
|
2010-07-21 17:25:58 +02:00
|
|
|
}
|
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()
|
|
|
|
|
{
|
2010-08-03 15:42:14 +02:00
|
|
|
for (int i = 0; i < helpCandidates().size() && matchingHelpCandidate() == -1; ++i) {
|
|
|
|
|
if (helpIdExists(helpCandidates().at(i).m_helpId)) {
|
|
|
|
|
setMatchingHelpCandidate(i);
|
2010-07-27 09:42:21 +02:00
|
|
|
} else {
|
|
|
|
|
// There are class help ids with and without qualification.
|
2010-08-03 15:42:14 +02:00
|
|
|
HelpCandidate candidate = helpCandidates().at(i);
|
2010-07-27 09:42:21 +02:00
|
|
|
const QString &helpId = removeClassNameQualification(candidate.m_helpId);
|
|
|
|
|
if (helpIdExists(helpId)) {
|
|
|
|
|
candidate.m_helpId = helpId;
|
2010-08-03 15:42:14 +02:00
|
|
|
setHelpCandidate(candidate, i);
|
|
|
|
|
setMatchingHelpCandidate(i);
|
2010-07-27 09:42:21 +02:00
|
|
|
}
|
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-08-03 15:42:14 +02:00
|
|
|
void CppHoverHandler::decorateToolTip(TextEditor::ITextEditor *editor)
|
2010-07-12 13:24:45 +02:00
|
|
|
{
|
2010-08-03 15:42:14 +02:00
|
|
|
if (!m_classHierarchy.isEmpty())
|
|
|
|
|
generateDiagramTooltip(extendToolTips(editor));
|
2010-07-22 12:00:21 +02:00
|
|
|
else
|
2010-08-03 15:42:14 +02:00
|
|
|
generateNormalTooltip(extendToolTips(editor));
|
2010-07-12 13:24:45 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-22 12:00:21 +02:00
|
|
|
void CppHoverHandler::generateDiagramTooltip(const bool extendTooltips)
|
2010-07-20 12:35:08 +02:00
|
|
|
{
|
2010-08-03 15:42:14 +02:00
|
|
|
QString clazz = toolTip();
|
2010-07-20 12:35:08 +02:00
|
|
|
|
|
|
|
|
qSort(m_classHierarchy.begin(), m_classHierarchy.end(), ClassHierarchyComp());
|
|
|
|
|
|
2010-07-28 16:33:44 +02:00
|
|
|
// Remove duplicates (in case there are any).
|
|
|
|
|
m_classHierarchy.erase(std::unique(m_classHierarchy.begin(), m_classHierarchy.end()),
|
|
|
|
|
m_classHierarchy.end());
|
|
|
|
|
|
2010-07-20 12:35:08 +02:00
|
|
|
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>"
|
2010-08-03 15:42:14 +02:00
|
|
|
"<td>%2</td></tr>").arg(toolTip()).arg(directBaseClasses.at(i)));
|
2010-07-20 12:35:08 +02:00
|
|
|
} 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>"));
|
2010-08-03 15:42:14 +02:00
|
|
|
setToolTip(diagram);
|
2010-07-20 12:35:08 +02:00
|
|
|
|
2010-08-03 15:42:14 +02:00
|
|
|
if (matchingHelpCandidate() != -1) {
|
|
|
|
|
appendToolTip(getDocContents(extendTooltips));
|
2010-07-22 12:00:21 +02:00
|
|
|
} 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;
|
|
|
|
|
|
2010-08-03 15:42:14 +02:00
|
|
|
bool exists = false;
|
|
|
|
|
QString name = hierarchy.last();
|
2010-07-22 12:00:21 +02:00
|
|
|
if (helpIdExists(name)) {
|
2010-08-03 15:42:14 +02:00
|
|
|
exists = true;
|
|
|
|
|
} else {
|
|
|
|
|
name = removeClassNameQualification(name);
|
|
|
|
|
if (helpIdExists(name)) {
|
|
|
|
|
exists = true;
|
|
|
|
|
m_classHierarchy[i].last() = name;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (exists) {
|
2010-07-22 12:00:21 +02:00
|
|
|
baseClassesWithHelp.append(i);
|
|
|
|
|
if (helpLevel == 0)
|
|
|
|
|
helpLevel = hierarchy.size();
|
2010-07-20 12:35:08 +02:00
|
|
|
}
|
2010-07-22 12:00:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
2010-08-03 15:42:14 +02:00
|
|
|
addHelpCandidate(help);
|
|
|
|
|
setMatchingHelpCandidate(helpCandidates().size() - 1);
|
2010-07-20 12:35:08 +02:00
|
|
|
|
2010-07-22 12:00:21 +02:00
|
|
|
if (baseClassesWithHelp.size() == 1 && helpLevel == 1) {
|
2010-08-03 15:42:14 +02:00
|
|
|
appendToolTip(getDocContents(help, extendTooltips));
|
2010-07-22 12:00:21 +02:00
|
|
|
} else {
|
|
|
|
|
foreach (int hierarchyIndex, baseClassesWithHelp) {
|
2010-08-03 15:42:14 +02:00
|
|
|
appendToolTip(QLatin1String("<p>"));
|
2010-07-22 12:00:21 +02:00
|
|
|
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);
|
2010-08-03 15:42:14 +02:00
|
|
|
const QString &contents =
|
2010-07-22 12:00:21 +02:00
|
|
|
getDocContents(HelpCandidate(base, base, HelpCandidate::Brief), false);
|
|
|
|
|
if (!contents.isEmpty()) {
|
2010-08-03 15:42:14 +02:00
|
|
|
appendToolTip(diagram % QLatin1String("<table><tr><td>") %
|
|
|
|
|
contents % QLatin1String("</td></tr></table>"));
|
2010-07-20 12:35:08 +02:00
|
|
|
}
|
2010-08-03 15:42:14 +02:00
|
|
|
appendToolTip(QLatin1String("</p>"));
|
2010-07-20 12:35:08 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-22 12:00:21 +02:00
|
|
|
void CppHoverHandler::generateNormalTooltip(const bool extendTooltips)
|
2010-07-20 12:35:08 +02:00
|
|
|
{
|
2010-08-03 15:42:14 +02:00
|
|
|
if (matchingHelpCandidate() != -1) {
|
2010-07-22 12:00:21 +02:00
|
|
|
const QString &contents = getDocContents(extendTooltips);
|
2010-07-20 12:35:08 +02:00
|
|
|
if (!contents.isEmpty()) {
|
2010-08-03 15:42:14 +02:00
|
|
|
HelpCandidate::Category cat = helpCandidate(matchingHelpCandidate()).m_category;
|
2010-07-20 12:35:08 +02:00
|
|
|
if (cat == HelpCandidate::ClassOrNamespace)
|
2010-08-03 15:42:14 +02:00
|
|
|
appendToolTip(contents);
|
2010-07-20 12:35:08 +02:00
|
|
|
else
|
2010-08-03 15:42:14 +02:00
|
|
|
setToolTip(contents);
|
2010-07-20 12:35:08 +02:00
|
|
|
} else {
|
2010-08-03 15:42:14 +02:00
|
|
|
QString tip = Qt::escape(toolTip());
|
|
|
|
|
tip.prepend(QLatin1String("<nobr>"));
|
|
|
|
|
tip.append(QLatin1String("</nobr>"));
|
|
|
|
|
setToolTip(tip);
|
2010-07-20 12:35:08 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-03 15:42:14 +02:00
|
|
|
void CppHoverHandler::resetExtras()
|
2010-07-12 13:24:45 +02:00
|
|
|
{
|
2010-07-20 12:35:08 +02:00
|
|
|
m_classHierarchy.clear();
|
2010-07-12 13:24:45 +02:00
|
|
|
}
|