diff options
author | Roberto Raggi <qtc-committer@nokia.com> | 2008-12-18 10:52:29 +0100 |
---|---|---|
committer | Roberto Raggi <qtc-committer@nokia.com> | 2008-12-18 10:53:56 +0100 |
commit | 3564c529d078584d7b5d0a30665d7ace7d012c71 (patch) | |
tree | 5f9fe9b460765437e5d3c8b047d88abebe359df2 /src | |
parent | 678c09c81318a8cd0aa864ddc1bff91405cb29ca (diff) | |
download | qt-creator-3564c529d078584d7b5d0a30665d7ace7d012c71.tar.gz |
Clean up the C++ hover handler.
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/cppeditor/cpphoverhandler.cpp | 106 |
1 files changed, 54 insertions, 52 deletions
diff --git a/src/plugins/cppeditor/cpphoverhandler.cpp b/src/plugins/cppeditor/cpphoverhandler.cpp index 3ffff7701d..f4060d0b60 100644 --- a/src/plugins/cppeditor/cpphoverhandler.cpp +++ b/src/plugins/cppeditor/cpphoverhandler.cpp @@ -53,6 +53,7 @@ #include <cplusplus/ExpressionUnderCursor.h> #include <cplusplus/Overview.h> #include <cplusplus/TypeOfExpression.h> +#include <cplusplus/SimpleLexer.h> #include <QtGui/QToolTip> #include <QtGui/QTextCursor> @@ -188,29 +189,36 @@ void CppHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, in if (!edit) return; + const Snapshot documents = m_modelManager->snapshot(); + const QString fileName = editor->file()->fileName(); + Document::Ptr doc = documents.value(fileName); + if (! doc) + return; // nothing to do + QTextCursor tc(edit->document()); tc.setPosition(pos); + const unsigned lineNumber = tc.block().blockNumber() + 1; - const Snapshot documents = m_modelManager->snapshot(); + // Find the last symbol up to the cursor position + int line = 0, column = 0; + editor->convertPosition(tc.position(), &line, &column); + Symbol *lastSymbol = doc->findSymbolAt(line, column); - const int lineNumber = tc.block().blockNumber() + 1; - const QString fileName = editor->file()->fileName(); - Document::Ptr doc = documents.value(fileName); - if (doc) { - foreach (Document::DiagnosticMessage m, doc->diagnosticMessages()) { - if (m.line() == lineNumber) { - m_toolTip = m.text(); - break; - } + TypeOfExpression typeOfExpression; + typeOfExpression.setSnapshot(documents); + + foreach (Document::DiagnosticMessage m, doc->diagnosticMessages()) { + if (m.line() == lineNumber) { + m_toolTip = m.text(); + break; } + } - if (m_toolTip.isEmpty()) { - unsigned lineno = tc.blockNumber() + 1; - foreach (const Document::Include &incl, doc->includes()) { - if (lineno == incl.line()) { - m_toolTip = incl.fileName(); - break; - } + if (m_toolTip.isEmpty()) { + foreach (const Document::Include &incl, doc->includes()) { + if (incl.line() == lineNumber) { + m_toolTip = incl.fileName(); + break; } } } @@ -233,43 +241,34 @@ void CppHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, in ExpressionUnderCursor expressionUnderCursor; const QString expression = expressionUnderCursor(tc); - if (doc) { - // Find the last symbol up to the cursor position - int line = 0, column = 0; - editor->convertPosition(tc.position(), &line, &column); - Symbol *lastSymbol = doc->findSymbolAt(line, column); - - TypeOfExpression typeOfExpression; - typeOfExpression.setSnapshot(documents); - QList<TypeOfExpression::Result> types = typeOfExpression(expression, doc, lastSymbol); - - if (!types.isEmpty()) { - FullySpecifiedType firstType = types.first().first; - FullySpecifiedType docType = firstType; - - if (const PointerType *pt = firstType->asPointerType()) { - docType = pt->elementType(); - } else if (const ReferenceType *rt = firstType->asReferenceType()) { - docType = rt->elementType(); - } - - - m_helpId = buildHelpId(docType, types.first().second); - QString displayName = buildHelpId(firstType, types.first().second); - - if (!firstType->isClass() && !firstType->isNamedType()) { - Overview overview; - overview.setShowArgumentNames(true); - overview.setShowReturnTypes(true); - m_toolTip = overview.prettyType(firstType, displayName); - } else { - m_toolTip = m_helpId; - } + const QList<TypeOfExpression::Result> types = + typeOfExpression(expression, doc, lastSymbol); + + if (!types.isEmpty()) { + FullySpecifiedType firstType = types.first().first; + FullySpecifiedType docType = firstType; + + if (const PointerType *pt = firstType->asPointerType()) { + docType = pt->elementType(); + } else if (const ReferenceType *rt = firstType->asReferenceType()) { + docType = rt->elementType(); + } + + m_helpId = buildHelpId(docType, types.first().second); + QString displayName = buildHelpId(firstType, types.first().second); + + if (!firstType->isClass() && !firstType->isNamedType()) { + Overview overview; + overview.setShowArgumentNames(true); + overview.setShowReturnTypes(true); + m_toolTip = overview.prettyType(firstType, displayName); + } else { + m_toolTip = m_helpId; } } } - if (doc && m_toolTip.isEmpty()) { + if (m_toolTip.isEmpty()) { foreach (const Document::MacroUse &use, doc->macroUses()) { if (use.contains(pos)) { m_toolTip = use.macro().toString(); @@ -285,12 +284,15 @@ void CppHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, in m_helpEngineNeedsSetup = false; } + if (! m_toolTip.isEmpty()) + m_toolTip = Qt::escape(m_toolTip); + if (!m_helpId.isEmpty() && !m_helpEngine->linksForIdentifier(m_helpId).isEmpty()) { m_toolTip = QString(QLatin1String("<table><tr><td valign=middle><nobr>%1</td>" "<td><img src=\":/cppeditor/images/f1.svg\"></td></tr></table>")) - .arg(Qt::escape(m_toolTip)); + .arg(m_toolTip); editor->setContextHelpId(m_helpId); } else if (!m_toolTip.isEmpty()) { - m_toolTip = QString(QLatin1String("<nobr>%1")).arg(Qt::escape(m_toolTip)); + m_toolTip = QString(QLatin1String("<nobr>%1")).arg(m_toolTip); } } |