Commit f37e589e authored by Erik Verbruggen's avatar Erik Verbruggen
Browse files

Added constant values for enumerators in their tooltips.

Change-Id: I75c5dc43832d42588302bc0dadefcd4b6e2addc6
Reviewed-on: http://codereview.qt.nokia.com/414

Reviewed-by: default avatarChristian Kamm <christian.d.kamm@nokia.com>
parent b9742018
......@@ -35,6 +35,7 @@
#include <coreplugin/ifile.h>
#include <FullySpecifiedType.h>
#include <Literals.h>
#include <Names.h>
#include <CoreTypes.h>
#include <Scope.h>
......@@ -192,8 +193,10 @@ void CppElementEvaluator::handleLookupItemMatch(const Snapshot &snapshot,
if (m_lookupBaseClasses)
cppClass->lookupBases(declaration, context);
m_element = QSharedPointer<CppElement>(cppClass);
} else if (declaration->isEnum() || declaration->enclosingScope()->isEnum()) {
m_element = QSharedPointer<CppElement>(new CppEnum(declaration));
} else if (Enum *enumDecl = declaration->asEnum()) {
m_element = QSharedPointer<CppElement>(new CppEnum(enumDecl));
} else if (EnumeratorDeclaration *enumerator = dynamic_cast<EnumeratorDeclaration *>(declaration)) {
m_element = QSharedPointer<CppElement>(new CppEnumerator(enumerator));
} else if (declaration->isTypedef()) {
m_element = QSharedPointer<CppElement>(new CppTypedef(declaration));
} else if (declaration->isFunction() || (type.isValid() && type->isFunctionType())) {
......@@ -449,18 +452,11 @@ CppFunction::~CppFunction()
{}
// CppEnum
CppEnum::CppEnum(Symbol *declaration) : CppDeclarableElement(declaration)
CppEnum::CppEnum(Enum *declaration)
: CppDeclarableElement(declaration)
{
setHelpCategory(TextEditor::HelpItem::Enum);
if (declaration->enclosingScope()->isEnum()) {
Symbol *enumSymbol = declaration->enclosingScope()->asEnum();
Overview overview;
setHelpMark(overview.prettyName(enumSymbol->name()));
setTooltip(overview.prettyName(LookupContext::fullyQualifiedName(enumSymbol)));
} else {
setTooltip(qualifiedName());
}
setTooltip(qualifiedName());
}
CppEnum::~CppEnum()
......@@ -546,3 +542,31 @@ bool CppTemplate::isFunctionTemplate() const
{
return !m_isClassTemplate;
}
CppEnumerator::CppEnumerator(CPlusPlus::EnumeratorDeclaration *declaration)
: CppDeclarableElement(declaration)
{
setHelpCategory(TextEditor::HelpItem::Enum);
Overview overview;
Symbol *enumSymbol = declaration->enclosingScope()->asEnum();
const QString enumName = overview.prettyName(LookupContext::fullyQualifiedName(enumSymbol));
const QString enumeratorName = overview.prettyName(declaration->name());
QString enumeratorValue;
if (const StringLiteral *value = declaration->constantValue()) {
enumeratorValue = QString::fromUtf8(value->chars(), value->size());
}
setHelpMark(overview.prettyName(enumSymbol->name()));
QString tooltip = enumeratorName;
if (!enumName.isEmpty())
tooltip.prepend(enumName + QLatin1Char(' '));
if (!enumeratorValue.isEmpty())
tooltip.append(QLatin1String(" = ") + enumeratorValue);
setTooltip(tooltip);
}
CppEnumerator::~CppEnumerator()
{}
......@@ -64,7 +64,7 @@ class CppElement;
class CppElementEvaluator
{
public:
CppElementEvaluator(CPPEditorWidget *editor);
explicit CppElementEvaluator(CPPEditorWidget *editor);
void setTextCursor(const QTextCursor &tc);
void setLookupBaseClasses(const bool lookup);
......@@ -124,7 +124,7 @@ private:
class Unknown : public CppElement
{
public:
Unknown(const QString &type);
explicit Unknown(const QString &type);
virtual ~Unknown();
const QString &type() const;
......@@ -136,7 +136,7 @@ private:
class CppInclude : public CppElement
{
public:
CppInclude(const CPlusPlus::Document::Include &includeFile);
explicit CppInclude(const CPlusPlus::Document::Include &includeFile);
virtual ~CppInclude();
const QString &path() const;
......@@ -150,14 +150,14 @@ private:
class CppMacro : public CppElement
{
public:
CppMacro(const CPlusPlus::Macro &macro);
explicit CppMacro(const CPlusPlus::Macro &macro);
virtual ~CppMacro();
};
class CppDeclarableElement : public CppElement
{
public:
CppDeclarableElement(CPlusPlus::Symbol *declaration);
explicit CppDeclarableElement(CPlusPlus::Symbol *declaration);
virtual ~CppDeclarableElement();
const QString &name() const;
......@@ -181,14 +181,14 @@ private:
class CppNamespace : public CppDeclarableElement
{
public:
CppNamespace(CPlusPlus::Symbol *declaration);
explicit CppNamespace(CPlusPlus::Symbol *declaration);
virtual ~CppNamespace();
};
class CppClass : public CppDeclarableElement
{
public:
CppClass(CPlusPlus::Symbol *declaration);
explicit CppClass(CPlusPlus::Symbol *declaration);
virtual ~CppClass();
void lookupBases(CPlusPlus::Symbol *declaration, const CPlusPlus::LookupContext &context);
......@@ -202,21 +202,21 @@ private:
class CppFunction : public CppDeclarableElement
{
public:
CppFunction(CPlusPlus::Symbol *declaration);
explicit CppFunction(CPlusPlus::Symbol *declaration);
virtual ~CppFunction();
};
class CppEnum : public CppDeclarableElement
{
public:
CppEnum(CPlusPlus::Symbol *declaration);
explicit CppEnum(CPlusPlus::Enum *declaration);
virtual ~CppEnum();
};
class CppTypedef : public CppDeclarableElement
{
public:
CppTypedef(CPlusPlus::Symbol *declaration);
explicit CppTypedef(CPlusPlus::Symbol *declaration);
virtual ~CppTypedef();
};
......@@ -232,7 +232,7 @@ public:
class CppTemplate : public CppDeclarableElement
{
public:
CppTemplate(CPlusPlus::Symbol *declaration);
explicit CppTemplate(CPlusPlus::Symbol *declaration);
virtual ~CppTemplate();
bool isClassTemplate() const;
......@@ -242,6 +242,13 @@ private:
bool m_isClassTemplate;
};
class CppEnumerator : public CppDeclarableElement
{
public:
explicit CppEnumerator(CPlusPlus::EnumeratorDeclaration *declaration);
virtual ~CppEnumerator();
};
} // namespace Internal
} // namespace CppEditor
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment