From 3e104ce405281fb23ff2ffab24321d07ea7aa0f4 Mon Sep 17 00:00:00 2001 From: Leandro Melo Date: Fri, 1 Oct 2010 11:15:28 +0200 Subject: [PATCH] Tooltips: Do not show -qtnamespace (if any) in the tips. This is basically for consistency with the docs and with the html extraction mechanism. Reviewed-by: Roberto Raggi --- src/plugins/cppeditor/cppelementevaluator.cpp | 36 ++++++++++++++++----------- src/plugins/cppeditor/cpphoverhandler.cpp | 22 ++++++++++++---- 2 files changed, 39 insertions(+), 19 deletions(-) diff --git a/src/plugins/cppeditor/cppelementevaluator.cpp b/src/plugins/cppeditor/cppelementevaluator.cpp index 19f768fd29..cfb1fd77f5 100644 --- a/src/plugins/cppeditor/cppelementevaluator.cpp +++ b/src/plugins/cppeditor/cppelementevaluator.cpp @@ -66,6 +66,18 @@ namespace { ch = doc->characterAt(tc->position()); } } + + QStringList stripName(const QString &name) { + QStringList all; + all << name; + int colonColon = 0; + const int size = name.size(); + while ((colonColon = name.indexOf(QLatin1String("::"), colonColon)) != -1) { + all << name.right(size - colonColon - 2); + colonColon += 2; + } + return all; + } } CppElementEvaluator::CppElementEvaluator(CPPEditor *editor) : @@ -314,16 +326,7 @@ CppDeclarableElement::CppDeclarableElement(Symbol *declaration) : CppElement() declaration->enclosingScope()->isNamespace() || declaration->enclosingScope()->isEnum()) { m_qualifiedName = overview.prettyName(LookupContext::fullyQualifiedName(declaration)); - - QStringList helpIds; - helpIds << m_qualifiedName; - int colonColon = 0; - const int size = m_qualifiedName.size(); - while ((colonColon = m_qualifiedName.indexOf(QLatin1String("::"), colonColon)) != -1) { - helpIds << m_qualifiedName.right(size - colonColon - 2); - colonColon += 2; - } - setHelpIdCandidates(helpIds); + setHelpIdCandidates(stripName(m_qualifiedName)); } else { m_qualifiedName = m_name; setHelpIdCandidates(QStringList(m_name)); @@ -489,10 +492,15 @@ CppVariable::CppVariable(Symbol *declaration, const LookupContext &context, Scop Symbol *symbol = clazz->symbols().at(0); const QString &name = overview.prettyName(LookupContext::fullyQualifiedName(symbol)); - setTooltip(name); - setHelpCategory(TextEditor::HelpItem::ClassOrNamespace); - setHelpMark(name); - setHelpIdCandidates(QStringList(name)); + if (!name.isEmpty()) { + setTooltip(name); + setHelpCategory(TextEditor::HelpItem::ClassOrNamespace); + const QStringList &allNames = stripName(name); + if (!allNames.isEmpty()) { + setHelpMark(allNames.last()); + setHelpIdCandidates(allNames); + } + } } } } diff --git a/src/plugins/cppeditor/cpphoverhandler.cpp b/src/plugins/cppeditor/cpphoverhandler.cpp index 2168bc9e2d..c8d1a9ffad 100644 --- a/src/plugins/cppeditor/cpphoverhandler.cpp +++ b/src/plugins/cppeditor/cpphoverhandler.cpp @@ -114,14 +114,26 @@ void CppHoverHandler::decorateToolTip() const TextEditor::HelpItem &help = lastHelpItemIdentified(); if (help.isValid()) { + // If Qt is built with a namespace, we still show the tip without it, as + // it is in the docs and for consistency with the doc extraction mechanism. + const TextEditor::HelpItem::Category category = help.category(); const QString &contents = help.extractContent(false); if (!contents.isEmpty()) { - if (help.category() == TextEditor::HelpItem::ClassOrNamespace) { - setToolTip(Qt::escape(toolTip())); - appendToolTip(contents); - } else { + if (category == TextEditor::HelpItem::ClassOrNamespace) + setToolTip(help.helpId() + contents); + else setToolTip(contents); - } + } else if (category == TextEditor::HelpItem::Typedef || + category == TextEditor::HelpItem::Enum || + category == TextEditor::HelpItem::ClassOrNamespace) { + // This approach is a bit limited since it cannot be used for functions + // because the help id doesn't really help in that case. + QString prefix; + if (category == TextEditor::HelpItem::Typedef) + prefix = QLatin1String("typedef "); + else if (category == TextEditor::HelpItem::Enum) + prefix = QLatin1String("enum "); + setToolTip(prefix + help.helpId()); } addF1ToToolTip(); } -- 2.11.0