forked from qt-creator/qt-creator
		
	Improved the C++ hover handler.
Done with: bjorn
This commit is contained in:
		| @@ -42,7 +42,8 @@ Overview::Overview() | ||||
|     : _markArgument(0), | ||||
|       _showArgumentNames(false), | ||||
|       _showReturnTypes(false), | ||||
|       _showFunctionSignatures(true) | ||||
|       _showFunctionSignatures(true), | ||||
|       _showFullyQualifiedNames(false) | ||||
| { } | ||||
|  | ||||
| Overview::~Overview() | ||||
| @@ -88,6 +89,16 @@ void Overview::setShowFunctionSignatures(bool showFunctionSignatures) | ||||
|     _showFunctionSignatures = showFunctionSignatures; | ||||
| } | ||||
|  | ||||
| bool Overview::showFullyQualifiedNames() const | ||||
| { | ||||
|     return _showFullyQualifiedNames; | ||||
| } | ||||
|  | ||||
| void Overview::setShowFullyQualifiedNamed(bool showFullyQualifiedNames) | ||||
| { | ||||
|     _showFullyQualifiedNames = showFullyQualifiedNames; | ||||
| } | ||||
|  | ||||
| QString Overview::prettyName(Name *name) const | ||||
| { | ||||
|     NamePrettyPrinter pp(this); | ||||
|   | ||||
| @@ -57,6 +57,9 @@ public: | ||||
|     bool showFunctionSignatures() const; | ||||
|     void setShowFunctionSignatures(bool showFunctionSignatures); | ||||
|  | ||||
|     bool showFullyQualifiedNames() const; | ||||
|     void setShowFullyQualifiedNamed(bool showFullyQualifiedNames); | ||||
|  | ||||
|     // 1-based | ||||
|     // ### rename | ||||
|     unsigned markArgument() const; | ||||
| @@ -77,6 +80,7 @@ private: | ||||
|     bool _showArgumentNames: 1; | ||||
|     bool _showReturnTypes: 1; | ||||
|     bool _showFunctionSignatures: 1; | ||||
|     bool _showFullyQualifiedNames: 1; | ||||
| }; | ||||
|  | ||||
| } // end of namespace CPlusPlus | ||||
|   | ||||
| @@ -37,9 +37,41 @@ | ||||
| #include <CoreTypes.h> | ||||
| #include <Symbols.h> | ||||
| #include <Scope.h> | ||||
| #include <QStringList> | ||||
| #include <QtDebug> | ||||
|  | ||||
| using namespace CPlusPlus; | ||||
|  | ||||
|  | ||||
| static QString fullyQualifiedName(Symbol *symbol, const Overview *overview) | ||||
| { | ||||
|     QStringList nestedNameSpecifier; | ||||
|  | ||||
|     for (Scope *scope = symbol->scope(); scope && scope->enclosingScope(); | ||||
|          scope = scope->enclosingScope()) | ||||
|     { | ||||
|         Symbol *owner = scope->owner(); | ||||
|  | ||||
|         if (! owner) { | ||||
|             qWarning() << "invalid scope."; // ### better message. | ||||
|             continue; | ||||
|         } | ||||
|  | ||||
|         if (! owner->name()) | ||||
|             nestedNameSpecifier.prepend(QLatin1String("<anonymous>")); | ||||
|  | ||||
|         else { | ||||
|             const QString name = overview->prettyName(owner->name()); | ||||
|  | ||||
|             nestedNameSpecifier.prepend(name); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     nestedNameSpecifier.append(overview->prettyName(symbol->name())); | ||||
|  | ||||
|     return nestedNameSpecifier.join(QLatin1String("::")); | ||||
| } | ||||
|  | ||||
| TypePrettyPrinter::TypePrettyPrinter(const Overview *overview) | ||||
|     : _overview(overview), | ||||
|       _name(0) | ||||
| @@ -150,16 +182,26 @@ void TypePrettyPrinter::visit(Namespace *type) | ||||
|     applyPtrOperators(); | ||||
| } | ||||
|  | ||||
| void TypePrettyPrinter::visit(Class *type) | ||||
| void TypePrettyPrinter::visit(Class *classTy) | ||||
| { | ||||
|     _text += overview()->prettyName(type->name()); | ||||
|     if (overview()->showFullyQualifiedNames()) | ||||
|         _text += fullyQualifiedName(classTy, overview()); | ||||
|  | ||||
|     else | ||||
|         _text += overview()->prettyName(classTy->name()); | ||||
|  | ||||
|     applyPtrOperators(); | ||||
| } | ||||
|  | ||||
|  | ||||
| void TypePrettyPrinter::visit(Enum *type) | ||||
| { | ||||
|     _text += overview()->prettyName(type->name()); | ||||
|     if (overview()->showFullyQualifiedNames()) | ||||
|         _text += fullyQualifiedName(type, overview()); | ||||
|  | ||||
|     else | ||||
|         _text += overview()->prettyName(type->name()); | ||||
|  | ||||
|     applyPtrOperators(); | ||||
| } | ||||
|  | ||||
| @@ -259,11 +301,14 @@ void TypePrettyPrinter::visit(Function *type) | ||||
|     if (! _ptrOperators.isEmpty()) { | ||||
|         out(QLatin1Char('(')); | ||||
|         applyPtrOperators(false); | ||||
|  | ||||
|         if (! _name.isEmpty()) { | ||||
|             _text += _name; | ||||
|             _name.clear(); | ||||
|         } | ||||
|  | ||||
|         out(QLatin1Char(')')); | ||||
|  | ||||
|     } else if (! _name.isEmpty() && _overview->showFunctionSignatures()) { | ||||
|         space(); | ||||
|         out(_name); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user