Commit 4a08f14c authored by Nikolai Kosjar's avatar Nikolai Kosjar
Browse files

Clang: Fix removing text marks on line deletion



Task-number: QTCREATORBUG-17270
Change-Id: I582015597a65141e420622dcdb50e82f9791b189
Reviewed-by: Christian Stenger's avatarChristian Stenger <christian.stenger@qt.io>
Reviewed-by: David Schulz's avatarDavid Schulz <david.schulz@qt.io>
parent c4d9f6ac
......@@ -346,7 +346,12 @@ void ClangDiagnosticManager::addClangTextMarks(
const QVector<ClangBackEnd::DiagnosticContainer> &diagnostics)
{
for (const ClangBackEnd::DiagnosticContainer &diagnostic : diagnostics) {
auto textMark = new ClangTextMark(filePath(), diagnostic);
const auto onMarkRemoved = [this](const ClangTextMark *mark) {
const auto it = std::remove(m_clangTextMarks.begin(), m_clangTextMarks.end(), mark);
m_clangTextMarks.erase(it, m_clangTextMarks.end());
delete mark;
};
auto textMark = new ClangTextMark(filePath(), diagnostic, onMarkRemoved);
m_clangTextMarks.push_back(textMark);
m_textDocument->addMark(textMark);
}
......
......@@ -29,6 +29,7 @@
#include "clangdiagnostictooltipwidget.h"
#include <utils/icon.h>
#include <utils/qtcassert.h>
#include <utils/theme/theme.h>
#include <QLayout>
......@@ -60,9 +61,14 @@ Core::Id cartegoryForSeverity(ClangBackEnd::DiagnosticSeverity severity)
} // anonymous namespace
ClangTextMark::ClangTextMark(const QString &fileName, const ClangBackEnd::DiagnosticContainer &diagnostic)
: TextEditor::TextMark(fileName, int(diagnostic.location().line()), cartegoryForSeverity(diagnostic.severity())),
m_diagnostic(diagnostic)
ClangTextMark::ClangTextMark(const QString &fileName,
const ClangBackEnd::DiagnosticContainer &diagnostic,
const RemovedFromEditorHandler &removedHandler)
: TextEditor::TextMark(fileName,
int(diagnostic.location().line()),
cartegoryForSeverity(diagnostic.severity()))
, m_diagnostic(diagnostic)
, m_removedFromEditorHandler(removedHandler)
{
setPriority(TextEditor::TextMark::HighPriority);
setIcon(diagnostic.severity());
......@@ -93,5 +99,11 @@ bool ClangTextMark::addToolTipContent(QLayout *target)
return true;
}
void ClangTextMark::removedFromEditor()
{
QTC_ASSERT(m_removedFromEditorHandler, return);
m_removedFromEditorHandler(this);
}
} // namespace ClangCodeModel
......@@ -30,18 +30,28 @@
#include <texteditor/textmark.h>
#include <functional>
namespace ClangCodeModel {
class ClangTextMark : public TextEditor::TextMark
{
public:
ClangTextMark(const QString &fileName, const ClangBackEnd::DiagnosticContainer &diagnostic);
using RemovedFromEditorHandler = std::function<void(ClangTextMark *)>;
ClangTextMark(const QString &fileName,
const ClangBackEnd::DiagnosticContainer &diagnostic,
const RemovedFromEditorHandler &removedHandler);
private:
bool addToolTipContent(QLayout *target);
void setIcon(ClangBackEnd::DiagnosticSeverity severity);
bool addToolTipContent(QLayout *target) override;
void removedFromEditor() override;
private:
ClangBackEnd::DiagnosticContainer m_diagnostic;
RemovedFromEditorHandler m_removedFromEditorHandler;
};
} // namespace ClangCodeModel
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