forked from qt-creator/qt-creator
TextEditor: Enable tooltips for textmarks
Adjust bookmark code, add tooltips for clang diagnostics. Change-Id: I489d499f5431fcb29f27611d4350298acb30baac Reviewed-by: Alessandro Portale <alessandro.portale@qt.io> Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
@@ -78,7 +78,7 @@ void Bookmark::updateFileName(const QString &fileName)
|
||||
|
||||
void Bookmark::setNote(const QString ¬e)
|
||||
{
|
||||
m_note = note;
|
||||
setToolTip(note);
|
||||
}
|
||||
|
||||
void Bookmark::updateNote(const QString ¬e)
|
||||
@@ -94,5 +94,5 @@ QString Bookmark::lineText() const
|
||||
|
||||
QString Bookmark::note() const
|
||||
{
|
||||
return m_note;
|
||||
return toolTip();
|
||||
}
|
||||
|
||||
@@ -37,13 +37,14 @@ class Bookmark : public TextEditor::TextMark
|
||||
public:
|
||||
Bookmark(int lineNumber, BookmarkManager *manager);
|
||||
|
||||
void updateLineNumber(int lineNumber);
|
||||
void move(int line);
|
||||
void updateBlock(const QTextBlock &block);
|
||||
void updateFileName(const QString &fileName);
|
||||
void updateLineNumber(int lineNumber) override;
|
||||
void move(int line) override;
|
||||
void updateBlock(const QTextBlock &block) override;
|
||||
void updateFileName(const QString &fileName) override;
|
||||
void removedFromEditor() override;
|
||||
|
||||
void setNote(const QString ¬e);
|
||||
void updateNote(const QString ¬e);
|
||||
void removedFromEditor();
|
||||
|
||||
QString lineText() const;
|
||||
QString note() const;
|
||||
@@ -51,7 +52,6 @@ public:
|
||||
private:
|
||||
BookmarkManager *m_manager;
|
||||
QString m_lineText;
|
||||
QString m_note;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
@@ -38,7 +38,6 @@
|
||||
#include <projectexplorer/session.h>
|
||||
#include <texteditor/texteditor.h>
|
||||
#include <utils/icon.h>
|
||||
#include <utils/tooltip/tooltip.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/checkablemessagebox.h>
|
||||
#include <utils/theme/theme.h>
|
||||
@@ -845,17 +844,6 @@ void BookmarkManager::saveBookmarks()
|
||||
SessionManager::setValue(QLatin1String("Bookmarks"), list);
|
||||
}
|
||||
|
||||
void BookmarkManager::operateTooltip(QWidget *widget, const QPoint &pos, Bookmark *mark)
|
||||
{
|
||||
if (!mark)
|
||||
return;
|
||||
|
||||
if (mark->note().isEmpty())
|
||||
ToolTip::hide();
|
||||
else
|
||||
ToolTip::show(pos, mark->note(), widget);
|
||||
}
|
||||
|
||||
/* Loads the bookmarks from the session settings. */
|
||||
void BookmarkManager::loadBookmarks()
|
||||
{
|
||||
@@ -867,12 +855,6 @@ void BookmarkManager::loadBookmarks()
|
||||
updateActionStatus();
|
||||
}
|
||||
|
||||
void BookmarkManager::handleBookmarkTooltipRequest(IEditor *editor, const QPoint &pos, int line)
|
||||
{
|
||||
Bookmark *mark = findBookmark(editor->document()->filePath().toString(), line);
|
||||
operateTooltip(editor->widget(), pos, mark);
|
||||
}
|
||||
|
||||
// BookmarkViewFactory
|
||||
|
||||
BookmarkViewFactory::BookmarkViewFactory(BookmarkManager *bm)
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <utils/itemviews.h>
|
||||
#include <coreplugin/editormanager/ieditor.h>
|
||||
#include <coreplugin/inavigationwidgetfactory.h>
|
||||
|
||||
#include <QAbstractItemModel>
|
||||
@@ -36,6 +35,8 @@
|
||||
#include <QPixmap>
|
||||
#include <QStyledItemDelegate>
|
||||
|
||||
namespace Core { class IContext; }
|
||||
|
||||
namespace Bookmarks {
|
||||
namespace Internal {
|
||||
|
||||
@@ -87,8 +88,6 @@ public:
|
||||
Note = Qt::UserRole + 4
|
||||
};
|
||||
|
||||
void handleBookmarkTooltipRequest(Core::IEditor *editor, const QPoint &pos, int line);
|
||||
|
||||
void toggleBookmark(const QString &fileName, int lineNumber);
|
||||
void nextInDocument();
|
||||
void prevInDocument();
|
||||
@@ -117,7 +116,6 @@ private:
|
||||
bool removeBookmarkFromMap(Bookmark *bookmark, const QString &fileName = QString());
|
||||
static QString bookmarkToString(const Bookmark *b);
|
||||
void saveBookmarks();
|
||||
void operateTooltip(QWidget *widget, const QPoint &pos, Bookmark *mark);
|
||||
|
||||
typedef QMultiMap<QString, Bookmark *> FileNameBookmarksMap;
|
||||
typedef QMap<QString, FileNameBookmarksMap *> DirectoryFileBookmarksMap;
|
||||
|
||||
@@ -170,13 +170,6 @@ void BookmarksPlugin::editorOpened(IEditor *editor)
|
||||
m_bookmarkManager->toggleBookmark(editor->document()->filePath().toString(), line);
|
||||
});
|
||||
|
||||
|
||||
connect(widget, &TextEditorWidget::markTooltipRequested, m_bookmarkManager,
|
||||
[this, editor](TextEditorWidget *, const QPoint &pos, int line) {
|
||||
if (editor->document())
|
||||
m_bookmarkManager->handleBookmarkTooltipRequest(editor, pos, line);
|
||||
});
|
||||
|
||||
connect(widget, &TextEditorWidget::markContextMenuRequested,
|
||||
this, &BookmarksPlugin::requestContextMenu);
|
||||
}
|
||||
|
||||
@@ -243,11 +243,23 @@ ClangDiagnosticManager::ClangDiagnosticManager(TextEditor::TextDocument *textDoc
|
||||
{
|
||||
}
|
||||
|
||||
ClangDiagnosticManager::~ClangDiagnosticManager()
|
||||
{
|
||||
cleanMarks();
|
||||
}
|
||||
|
||||
void ClangDiagnosticManager::cleanMarks()
|
||||
{
|
||||
for (ClangTextMark *textMark : m_clangTextMarks) {
|
||||
m_textDocument->removeMark(textMark);
|
||||
delete textMark;
|
||||
}
|
||||
m_clangTextMarks.clear();
|
||||
}
|
||||
void ClangDiagnosticManager::generateTextMarks()
|
||||
{
|
||||
m_clangTextMarks.clear();
|
||||
cleanMarks();
|
||||
m_clangTextMarks.reserve(m_warningDiagnostics.size() + m_errorDiagnostics.size());
|
||||
|
||||
addClangTextMarks(m_warningDiagnostics);
|
||||
addClangTextMarks(m_errorDiagnostics);
|
||||
}
|
||||
@@ -332,18 +344,13 @@ ClangDiagnosticManager::diagnosticsWithFixIts() const
|
||||
void ClangDiagnosticManager::addClangTextMarks(
|
||||
const QVector<ClangBackEnd::DiagnosticContainer> &diagnostics)
|
||||
{
|
||||
QTC_ASSERT(m_clangTextMarks.size() + diagnostics.size() <= m_clangTextMarks.capacity(), return);
|
||||
|
||||
for (auto &&diagnostic : diagnostics) {
|
||||
m_clangTextMarks.emplace_back(filePath(),
|
||||
diagnostic.location().line(),
|
||||
diagnostic.severity());
|
||||
|
||||
ClangTextMark &textMark = m_clangTextMarks.back();
|
||||
|
||||
textMark.setBaseTextDocument(m_textDocument);
|
||||
|
||||
m_textDocument->addMark(&textMark);
|
||||
for (const ClangBackEnd::DiagnosticContainer &diagnostic : diagnostics) {
|
||||
auto textMark = new ClangTextMark(filePath(),
|
||||
diagnostic.location().line(),
|
||||
diagnostic.severity());
|
||||
textMark->setToolTip(diagnostic.text());
|
||||
m_clangTextMarks.push_back(textMark);
|
||||
m_textDocument->addMark(textMark);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -47,6 +47,7 @@ class ClangDiagnosticManager
|
||||
{
|
||||
public:
|
||||
ClangDiagnosticManager(TextEditor::TextDocument *textDocument);
|
||||
~ClangDiagnosticManager();
|
||||
|
||||
void processNewDiagnostics(const QVector<ClangBackEnd::DiagnosticContainer> &allDiagnostics);
|
||||
|
||||
@@ -60,6 +61,7 @@ public:
|
||||
void clearDiagnosticsWithFixIts();
|
||||
|
||||
private:
|
||||
void cleanMarks();
|
||||
QString filePath() const;
|
||||
void filterDiagnostics(const QVector<ClangBackEnd::DiagnosticContainer> &diagnostics);
|
||||
void generateEditorSelections();
|
||||
@@ -77,7 +79,7 @@ private:
|
||||
QVector<ClangBackEnd::DiagnosticContainer> m_fixItdiagnostics;
|
||||
QList<QTextEdit::ExtraSelection> m_extraSelections;
|
||||
TextEditor::RefactorMarkers m_fixItAvailableMarkers;
|
||||
std::vector<ClangTextMark> m_clangTextMarks;
|
||||
std::vector<ClangTextMark *> m_clangTextMarks;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
@@ -79,10 +79,5 @@ void ClangTextMark::setIcon(ClangBackEnd::DiagnosticSeverity severity)
|
||||
TextMark::setIcon(errorIcon);
|
||||
}
|
||||
|
||||
ClangTextMark::ClangTextMark(ClangTextMark &&other) Q_DECL_NOEXCEPT
|
||||
: TextMark(std::move(other))
|
||||
{
|
||||
}
|
||||
|
||||
} // namespace ClangCodeModel
|
||||
|
||||
|
||||
@@ -36,11 +36,6 @@ class ClangTextMark : public TextEditor::TextMark
|
||||
public:
|
||||
ClangTextMark(const QString &fileName, int lineNumber, ClangBackEnd::DiagnosticSeverity severity);
|
||||
|
||||
ClangTextMark(ClangTextMark &&other) Q_DECL_NOEXCEPT;
|
||||
|
||||
ClangTextMark(ClangTextMark &other) = delete;
|
||||
ClangTextMark &operator=(ClangTextMark &other) = delete;
|
||||
|
||||
private:
|
||||
void setIcon(ClangBackEnd::DiagnosticSeverity severity);
|
||||
};
|
||||
|
||||
@@ -5105,10 +5105,18 @@ void TextEditorWidget::extraAreaMouseEvent(QMouseEvent *e)
|
||||
// Set whether the mouse cursor is a hand or normal arrow
|
||||
if (e->type() == QEvent::MouseMove) {
|
||||
if (inMarkArea) {
|
||||
//Find line by cursor position
|
||||
int line = cursor.blockNumber() + 1;
|
||||
if (d->extraAreaPreviousMarkTooltipRequestedLine != line)
|
||||
emit markTooltipRequested(this, mapToGlobal(e->pos()), line);
|
||||
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);
|
||||
}
|
||||
ToolTip::show(mapToGlobal(e->pos()), toolTips.join('\n'), this);
|
||||
}
|
||||
}
|
||||
d->extraAreaPreviousMarkTooltipRequestedLine = line;
|
||||
}
|
||||
|
||||
|
||||
@@ -583,8 +583,6 @@ signals:
|
||||
void tooltipOverrideRequested(TextEditor::TextEditorWidget *widget,
|
||||
const QPoint &globalPos, int position, bool *handled);
|
||||
void tooltipRequested(const QPoint &globalPos, int position);
|
||||
void markTooltipRequested(TextEditor::TextEditorWidget *widget,
|
||||
const QPoint &globalPos, int line);
|
||||
void activateEditor();
|
||||
|
||||
protected slots:
|
||||
|
||||
@@ -60,20 +60,6 @@ TextMark::~TextMark()
|
||||
m_baseTextDocument = 0;
|
||||
}
|
||||
|
||||
TextMark::TextMark(TextMark &&other) Q_DECL_NOEXCEPT
|
||||
: m_baseTextDocument(std::move(other.m_baseTextDocument)),
|
||||
m_fileName(std::move(other.m_fileName)),
|
||||
m_lineNumber(std::move(other.m_lineNumber)),
|
||||
m_priority(std::move(other.m_priority)),
|
||||
m_visible(std::move(other.m_visible)),
|
||||
m_icon(std::move(other.m_icon)),
|
||||
m_color(std::move(other.m_color)),
|
||||
m_category(std::move(other.m_category)),
|
||||
m_widthFactor(std::move(other.m_widthFactor))
|
||||
{
|
||||
other.m_baseTextDocument = nullptr;
|
||||
}
|
||||
|
||||
QString TextMark::fileName() const
|
||||
{
|
||||
return m_fileName;
|
||||
@@ -212,6 +198,15 @@ void TextMark::setBaseTextDocument(TextDocument *baseTextDocument)
|
||||
m_baseTextDocument = baseTextDocument;
|
||||
}
|
||||
|
||||
QString TextMark::toolTip() const
|
||||
{
|
||||
return m_toolTip;
|
||||
}
|
||||
|
||||
void TextMark::setToolTip(const QString &toolTip)
|
||||
{
|
||||
m_toolTip = toolTip;
|
||||
}
|
||||
|
||||
TextMarkRegistry::TextMarkRegistry(QObject *parent)
|
||||
: QObject(parent)
|
||||
|
||||
@@ -51,8 +51,6 @@ public:
|
||||
TextMark(const QString &fileName, int lineNumber, Core::Id category);
|
||||
virtual ~TextMark();
|
||||
|
||||
TextMark(TextMark &&other) Q_DECL_NOEXCEPT;
|
||||
|
||||
// determine order on markers on the same line.
|
||||
enum Priority
|
||||
{
|
||||
@@ -93,6 +91,9 @@ public:
|
||||
TextDocument *baseTextDocument() const;
|
||||
void setBaseTextDocument(TextDocument *baseTextDocument);
|
||||
|
||||
QString toolTip() const;
|
||||
void setToolTip(const QString &toolTip);
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(TextMark)
|
||||
friend class Internal::TextMarkRegistry;
|
||||
@@ -106,6 +107,7 @@ private:
|
||||
QColor m_color;
|
||||
Core::Id m_category;
|
||||
double m_widthFactor;
|
||||
QString m_toolTip;
|
||||
};
|
||||
|
||||
} // namespace TextEditor
|
||||
|
||||
Reference in New Issue
Block a user