summaryrefslogtreecommitdiff
path: root/src/plugins/clangcodemodel/clanghoverhandler.cpp
diff options
context:
space:
mode:
authorNikolai Kosjar <nikolai.kosjar@qt.io>2019-01-31 13:16:44 +0100
committerNikolai Kosjar <nikolai.kosjar@qt.io>2019-02-05 11:22:27 +0000
commitc5e43d86d12ce51c9035159a8acd86800fdf69bc (patch)
tree90030cd07fa47a25705cf485c333d06a90462660 /src/plugins/clangcodemodel/clanghoverhandler.cpp
parent1a58a30685a7acb386989f8edbcd497d9472acf1 (diff)
downloadqt-creator-c5e43d86d12ce51c9035159a8acd86800fdf69bc.tar.gz
Clang: Make diagnostic tooltips consistent
Fix that triggering a diagnostic tooltip from the diagnostic location/range itself (underlined text) did not show the icon on the left and the actions/toolbuttons on the right in the tooltip. Instead of showing the tooltip content itself, request the tooltip for the corresponding text mark to get the extra decoration and actions. Change-Id: I5e94aca117a761f7a798d4f4b33db6e386e54d84 Reviewed-by: David Schulz <david.schulz@qt.io> Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
Diffstat (limited to 'src/plugins/clangcodemodel/clanghoverhandler.cpp')
-rw-r--r--src/plugins/clangcodemodel/clanghoverhandler.cpp42
1 files changed, 13 insertions, 29 deletions
diff --git a/src/plugins/clangcodemodel/clanghoverhandler.cpp b/src/plugins/clangcodemodel/clanghoverhandler.cpp
index da9f974adb..58f414d9f1 100644
--- a/src/plugins/clangcodemodel/clanghoverhandler.cpp
+++ b/src/plugins/clangcodemodel/clanghoverhandler.cpp
@@ -25,8 +25,9 @@
#include "clanghoverhandler.h"
+#include "clangeditordocumentprocessor.h"
+
#include <coreplugin/helpmanager.h>
-#include <cpptools/baseeditordocumentprocessor.h>
#include <cpptools/cppmodelmanager.h>
#include <cpptools/cpptoolsreuse.h>
#include <cpptools/editordocumenthandle.h>
@@ -61,32 +62,17 @@ static CppTools::BaseEditorDocumentProcessor *editorDocumentProcessor(TextEditor
return nullptr;
}
-static bool editorDocumentProcessorHasDiagnosticAt(TextEditorWidget *editorWidget, int pos)
+static TextMarks diagnosticTextMarksAt(TextEditorWidget *editorWidget, int position)
{
- if (CppTools::BaseEditorDocumentProcessor *processor = editorDocumentProcessor(editorWidget)) {
- int line, column;
- if (Utils::Text::convertPosition(editorWidget->document(), pos, &line, &column))
- return processor->hasDiagnosticsAt(line, column);
- }
+ const auto processor = qobject_cast<ClangEditorDocumentProcessor *>(
+ editorDocumentProcessor(editorWidget));
+ QTC_ASSERT(processor, return TextMarks());
- return false;
-}
+ int line, column;
+ const bool ok = Utils::Text::convertPosition(editorWidget->document(), position, &line, &column);
+ QTC_ASSERT(ok, return TextMarks());
-static void processWithEditorDocumentProcessor(TextEditorWidget *editorWidget,
- const QPoint &point,
- int position,
- const Core::HelpItem &helpItem)
-{
- if (CppTools::BaseEditorDocumentProcessor *processor = editorDocumentProcessor(editorWidget)) {
- int line, column;
- if (Utils::Text::convertPosition(editorWidget->document(), position, &line, &column)) {
- auto layout = new QVBoxLayout;
- layout->setContentsMargins(0, 0, 0, 0);
- layout->setSpacing(2);
- processor->addDiagnosticToolTipToLayout(line, column, layout);
- Utils::ToolTip::show(point, layout, editorWidget, qVariantFromValue(helpItem));
- }
- }
+ return processor->diagnosticTextMarksAt(line, column);
}
static QFuture<CppTools::ToolTipInfo> editorDocumentHandlesToolTipInfo(
@@ -189,7 +175,7 @@ void ClangHoverHandler::identifyMatch(TextEditorWidget *editorWidget,
m_cursorPosition = -1;
// Check for diagnostics (sync)
- if (!isContextHelpRequest() && editorDocumentProcessorHasDiagnosticAt(editorWidget, pos)) {
+ if (!isContextHelpRequest() && !diagnosticTextMarksAt(editorWidget, pos).isEmpty()) {
qCDebug(hoverLog) << "Checking for diagnostic at" << pos;
setPriority(Priority_Diagnostic);
m_cursorPosition = pos;
@@ -275,10 +261,8 @@ void ClangHoverHandler::operateTooltip(TextEditor::TextEditorWidget *editorWidge
const QPoint &point)
{
if (priority() == Priority_Diagnostic) {
- processWithEditorDocumentProcessor(editorWidget,
- point,
- m_cursorPosition,
- lastHelpItemIdentified());
+ const TextMarks textMarks = diagnosticTextMarksAt(editorWidget, m_cursorPosition);
+ editorWidget->showTextMarksToolTip(point, textMarks);
return;
}