Commit 728b9147 authored by hjk's avatar hjk Committed by hjk

CppEditor: Use full tooltip in ClangTextMark

Change-Id: I39cc64acbdbcd5e5156e1514acaf9674a91e81a4
Reviewed-by: Nikolai Kosjar's avatarNikolai Kosjar <nikolai.kosjar@qt.io>
parent fe3f288f
......@@ -28,6 +28,7 @@
#include "effects.h"
#include "reuse.h"
#include <utils/faketooltip.h>
#include <utils/hostosinfo.h>
#include <utils/qtcassert.h>
......@@ -85,6 +86,17 @@ void ToolTip::show(const QPoint &pos, QWidget *content, QWidget *w, const QStrin
instance()->showInternal(pos, QVariant::fromValue(content), WidgetContent, w, helpId, rect);
}
void ToolTip::show(const QPoint &pos, QLayout *content, QWidget *w, const QString &helpId, const QRect &rect)
{
if (content && content->count()) {
auto tooltipWidget = new FakeToolTip;
tooltipWidget->setLayout(content);
instance()->showInternal(pos, QVariant::fromValue(tooltipWidget), WidgetContent, w, helpId, rect);
} else {
instance()->hideTipWithDelay();
}
}
void ToolTip::move(const QPoint &pos, QWidget *w)
{
if (isVisible())
......
......@@ -45,6 +45,7 @@
QT_BEGIN_NAMESPACE
class QPoint;
class QVariant;
class QLayout;
class QWidget;
QT_END_NAMESPACE
......@@ -76,6 +77,8 @@ public:
const QString &helpId = QString(), const QRect &rect = QRect());
static void show(const QPoint &pos, QWidget *content, QWidget *w = 0,
const QString &helpId = QString(), const QRect &rect = QRect());
static void show(const QPoint &pos, QLayout *content, QWidget *w = 0,
const QString &helpId = QString(), const QRect &rect = QRect());
static void move(const QPoint &pos, QWidget *w);
static void hide();
static void hideImmediately();
......
......@@ -345,10 +345,7 @@ void ClangDiagnosticManager::addClangTextMarks(
const QVector<ClangBackEnd::DiagnosticContainer> &diagnostics)
{
for (const ClangBackEnd::DiagnosticContainer &diagnostic : diagnostics) {
auto textMark = new ClangTextMark(filePath(),
diagnostic.location().line(),
diagnostic.severity());
textMark->setToolTip(diagnostic.text());
auto textMark = new ClangTextMark(filePath(), diagnostic);
m_clangTextMarks.push_back(textMark);
m_textDocument->addMark(textMark);
}
......
......@@ -186,7 +186,7 @@ public:
void addChildrenToLayout(const QString &mainFilePath,
const QVector<ClangBackEnd::DiagnosticContainer>::const_iterator first,
const QVector<ClangBackEnd::DiagnosticContainer>::const_iterator last,
QBoxLayout &boxLayout)
QLayout &boxLayout)
{
for (auto it = first; it != last; ++it)
boxLayout.addWidget(createDiagnosticLabel(*it, mainFilePath, IndentDiagnostic));
......@@ -194,7 +194,7 @@ void addChildrenToLayout(const QString &mainFilePath,
void setupChildDiagnostics(const QString &mainFilePath,
const QVector<ClangBackEnd::DiagnosticContainer> &diagnostics,
QBoxLayout &boxLayout)
QLayout &boxLayout)
{
if (diagnostics.size() <= 10) {
addChildrenToLayout(mainFilePath, diagnostics.begin(), diagnostics.end(), boxLayout);
......@@ -214,22 +214,13 @@ void setupChildDiagnostics(const QString &mainFilePath,
namespace ClangCodeModel {
namespace Internal {
ClangDiagnosticToolTipWidget::ClangDiagnosticToolTipWidget(
const QVector<ClangBackEnd::DiagnosticContainer> &diagnostics,
QWidget *parent)
: Utils::FakeToolTip(parent)
void addToolTipToLayout(const ClangBackEnd::DiagnosticContainer &diagnostic, QLayout *target)
{
auto *mainLayout = createLayout<QVBoxLayout>();
// Set up header and text row for main diagnostic
target->addWidget(new MainDiagnosticWidget(diagnostic));
foreach (const auto &diagnostic, diagnostics) {
// Set up header and text row for main diagnostic
mainLayout->addWidget(new MainDiagnosticWidget(diagnostic));
// Set up child rows for notes
setupChildDiagnostics(diagnostic.location().filePath(), diagnostic.children(), *mainLayout);
}
setLayout(mainLayout);
// Set up child rows for notes
setupChildDiagnostics(diagnostic.location().filePath(), diagnostic.children(), *target);
}
} // namespace Internal
......
......@@ -27,19 +27,14 @@
#include <clangbackendipc/diagnosticcontainer.h>
#include <utils/faketooltip.h>
QT_BEGIN_NAMESPACE
class QLayout;
QT_END_NAMESPACE
namespace ClangCodeModel {
namespace Internal {
class ClangDiagnosticToolTipWidget : public Utils::FakeToolTip
{
Q_OBJECT
public:
explicit ClangDiagnosticToolTipWidget(
const QVector<ClangBackEnd::DiagnosticContainer> &diagnostics,
QWidget *parent = 0);
};
void addToolTipToLayout(const ClangBackEnd::DiagnosticContainer &diagnostic, QLayout *target);
} // namespace Internal
} // namespace ClangCodeModel
......@@ -54,7 +54,6 @@
#include <cplusplus/CppDocument.h>
#include <utils/qtcassert.h>
#include <utils/tooltip/tooltip.h>
#include <utils/runextensions.h>
#include <QTextBlock>
......@@ -244,16 +243,12 @@ bool ClangEditorDocumentProcessor::hasDiagnosticsAt(uint line, uint column) cons
return m_diagnosticManager.hasDiagnosticsAt(line, column);
}
void ClangEditorDocumentProcessor::showDiagnosticTooltip(const QPoint &point,
QWidget *parent,
uint line,
uint column) const
void ClangEditorDocumentProcessor::addDiagnosticToolTipToLayout(uint line,
uint column,
QLayout *target) const
{
const QVector<ClangBackEnd::DiagnosticContainer> diagnostics
= m_diagnosticManager.diagnosticsAt(line, column);
auto *tooltipWidget = new ClangDiagnosticToolTipWidget(diagnostics, parent);
::Utils::ToolTip::show(point, tooltipWidget, parent);
foreach (const auto &diagnostic, m_diagnosticManager.diagnosticsAt(line, column))
addToolTipToLayout(diagnostic, target);
}
ClangBackEnd::FileContainer ClangEditorDocumentProcessor::fileContainerWithArguments() const
......
......@@ -76,10 +76,7 @@ public:
extraRefactoringOperations(const TextEditor::AssistInterface &assistInterface) override;
bool hasDiagnosticsAt(uint line, uint column) const override;
void showDiagnosticTooltip(const QPoint &point,
QWidget *parent,
uint line,
uint column) const override;
void addDiagnosticToolTipToLayout(uint line, uint column, QLayout *target) const override;
ClangBackEnd::FileContainer fileContainerWithArguments() const;
......
......@@ -26,10 +26,12 @@
#include "clangtextmark.h"
#include "clangconstants.h"
#include "clangdiagnostictooltipwidget.h"
#include <utils/icon.h>
#include <utils/theme/theme.h>
#include <QLayout>
#include <QString>
namespace ClangCodeModel {
......@@ -57,11 +59,13 @@ Core::Id cartegoryForSeverity(ClangBackEnd::DiagnosticSeverity severity)
} // anonymous namespace
ClangTextMark::ClangTextMark(const QString &fileName, int lineNumber, ClangBackEnd::DiagnosticSeverity severity)
: TextEditor::TextMark(fileName, lineNumber, cartegoryForSeverity(severity))
ClangTextMark::ClangTextMark(const QString &fileName, const ClangBackEnd::DiagnosticContainer &diagnostic)
: TextEditor::TextMark(fileName, int(diagnostic.location().line()), cartegoryForSeverity(diagnostic.severity())),
m_diagnostic(diagnostic)
{
setPriority(TextEditor::TextMark::HighPriority);
setIcon(severity);
setIcon(diagnostic.severity());
}
void ClangTextMark::setIcon(ClangBackEnd::DiagnosticSeverity severity)
......@@ -79,5 +83,10 @@ void ClangTextMark::setIcon(ClangBackEnd::DiagnosticSeverity severity)
TextMark::setIcon(errorIcon);
}
void ClangTextMark::addToToolTipLayout(QLayout *target)
{
Internal::addToolTipToLayout(m_diagnostic, target);
}
} // namespace ClangCodeModel
......@@ -26,6 +26,7 @@
#pragma once
#include <clangbackendipc_global.h>
#include <clangbackendipc/diagnosticcontainer.h>
#include <texteditor/textmark.h>
......@@ -34,10 +35,13 @@ namespace ClangCodeModel {
class ClangTextMark : public TextEditor::TextMark
{
public:
ClangTextMark(const QString &fileName, int lineNumber, ClangBackEnd::DiagnosticSeverity severity);
ClangTextMark(const QString &fileName, const ClangBackEnd::DiagnosticContainer &diagnostic);
private:
void addToToolTipLayout(QLayout *target);
void setIcon(ClangBackEnd::DiagnosticSeverity severity);
ClangBackEnd::DiagnosticContainer m_diagnostic;
};
} // namespace ClangCodeModel
......@@ -36,9 +36,11 @@
#include <texteditor/texteditor.h>
#include <utils/qtcassert.h>
#include <utils/tooltip/tooltip.h>
#include <QTextCursor>
#include <QUrl>
#include <QVBoxLayout>
using namespace Core;
using namespace TextEditor;
......@@ -74,8 +76,13 @@ void processWithEditorDocumentProcessor(TextEditorWidget *editorWidget,
{
if (CppTools::BaseEditorDocumentProcessor *processor = editorDocumentProcessor(editorWidget)) {
int line, column;
if (Convenience::convertPosition(editorWidget->document(), position, &line, &column))
processor->showDiagnosticTooltip(point, editorWidget, line, column);
if (Convenience::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);
}
}
}
......
......@@ -63,7 +63,7 @@ bool BaseEditorDocumentProcessor::hasDiagnosticsAt(uint, uint) const
return false;
}
void BaseEditorDocumentProcessor::showDiagnosticTooltip(const QPoint &, QWidget *, uint, uint) const
void BaseEditorDocumentProcessor::addDiagnosticToolTipToLayout(uint, uint, QLayout *) const
{
}
......
......@@ -65,10 +65,7 @@ public:
extraRefactoringOperations(const TextEditor::AssistInterface &assistInterface);
virtual bool hasDiagnosticsAt(uint line, uint column) const;
virtual void showDiagnosticTooltip(const QPoint &point,
QWidget *parent,
uint line,
uint column) const;
virtual void addDiagnosticToolTipToLayout(uint line, uint column, QLayout *layout) const;
signals:
// Signal interface to implement
......
......@@ -111,6 +111,7 @@
#include <QTimeLine>
#include <QTimer>
#include <QToolBar>
#include <QVBoxLayout>
//#define DO_FOO
......@@ -5048,6 +5049,7 @@ void TextEditorWidget::showDefaultContextMenu(QContextMenuEvent *e, Id menuConte
void TextEditorWidget::extraAreaLeaveEvent(QEvent *)
{
d->extraAreaPreviousMarkTooltipRequestedLine = -1;
ToolTip::hide();
// fake missing mouse move event from Qt
QMouseEvent me(QEvent::MouseMove, QPoint(-1, -1), Qt::NoButton, 0, 0);
......@@ -5108,13 +5110,16 @@ void TextEditorWidget::extraAreaMouseEvent(QMouseEvent *e)
int line = cursor.blockNumber() + 1;
if (d->extraAreaPreviousMarkTooltipRequestedLine != line) {
if (auto data = static_cast<TextBlockUserData *>(cursor.block().userData())) {
QStringList toolTips;
foreach (TextMark *mark, data->marks()) {
QString toolTip = mark->toolTip();
if (!toolTip.isEmpty())
toolTips.append(toolTip);
if (data->marks().isEmpty()) {
ToolTip::hide();
} else {
auto layout = new QVBoxLayout;
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(2);
foreach (TextMark *mark, data->marks())
mark->addToToolTipLayout(layout);
ToolTip::show(mapToGlobal(e->pos()), layout, this);
}
ToolTip::show(mapToGlobal(e->pos()), toolTips.join('\n'), this);
}
}
d->extraAreaPreviousMarkTooltipRequestedLine = line;
......
......@@ -33,6 +33,8 @@
#include <coreplugin/documentmanager.h>
#include <utils/qtcassert.h>
#include <QLayout>
using namespace Core;
using namespace Utils;
using namespace TextEditor::Internal;
......@@ -188,6 +190,12 @@ void TextMark::dragToLine(int lineNumber)
Q_UNUSED(lineNumber);
}
void TextMark::addToToolTipLayout(QLayout *target)
{
if (!m_toolTip.isEmpty())
target->addWidget(new QLabel(m_toolTip));
}
TextDocument *TextMark::baseTextDocument() const
{
return m_baseTextDocument;
......
......@@ -33,6 +33,7 @@
#include <QIcon>
QT_BEGIN_NAMESPACE
class QLayout;
class QPainter;
class QRect;
class QTextBlock;
......@@ -73,6 +74,7 @@ public:
virtual void clicked();
virtual bool isDraggable() const;
virtual void dragToLine(int lineNumber);
virtual void addToToolTipLayout(QLayout *target);
static Utils::Theme::Color categoryColor(Core::Id category);
static bool categoryHasColor(Core::Id category);
......
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