forked from qt-creator/qt-creator
Clang: Fix removing text marks on line deletion
Task-number: QTCREATORBUG-17270 Change-Id: I582015597a65141e420622dcdb50e82f9791b189 Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -346,7 +346,12 @@ void ClangDiagnosticManager::addClangTextMarks(
|
|||||||
const QVector<ClangBackEnd::DiagnosticContainer> &diagnostics)
|
const QVector<ClangBackEnd::DiagnosticContainer> &diagnostics)
|
||||||
{
|
{
|
||||||
for (const ClangBackEnd::DiagnosticContainer &diagnostic : 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_clangTextMarks.push_back(textMark);
|
||||||
m_textDocument->addMark(textMark);
|
m_textDocument->addMark(textMark);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@
|
|||||||
#include "clangdiagnostictooltipwidget.h"
|
#include "clangdiagnostictooltipwidget.h"
|
||||||
|
|
||||||
#include <utils/icon.h>
|
#include <utils/icon.h>
|
||||||
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/theme/theme.h>
|
#include <utils/theme/theme.h>
|
||||||
|
|
||||||
#include <QLayout>
|
#include <QLayout>
|
||||||
@@ -60,9 +61,14 @@ Core::Id cartegoryForSeverity(ClangBackEnd::DiagnosticSeverity severity)
|
|||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
|
|
||||||
|
|
||||||
ClangTextMark::ClangTextMark(const QString &fileName, const ClangBackEnd::DiagnosticContainer &diagnostic)
|
ClangTextMark::ClangTextMark(const QString &fileName,
|
||||||
: TextEditor::TextMark(fileName, int(diagnostic.location().line()), cartegoryForSeverity(diagnostic.severity())),
|
const ClangBackEnd::DiagnosticContainer &diagnostic,
|
||||||
m_diagnostic(diagnostic)
|
const RemovedFromEditorHandler &removedHandler)
|
||||||
|
: TextEditor::TextMark(fileName,
|
||||||
|
int(diagnostic.location().line()),
|
||||||
|
cartegoryForSeverity(diagnostic.severity()))
|
||||||
|
, m_diagnostic(diagnostic)
|
||||||
|
, m_removedFromEditorHandler(removedHandler)
|
||||||
{
|
{
|
||||||
setPriority(TextEditor::TextMark::HighPriority);
|
setPriority(TextEditor::TextMark::HighPriority);
|
||||||
setIcon(diagnostic.severity());
|
setIcon(diagnostic.severity());
|
||||||
@@ -93,5 +99,11 @@ bool ClangTextMark::addToolTipContent(QLayout *target)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ClangTextMark::removedFromEditor()
|
||||||
|
{
|
||||||
|
QTC_ASSERT(m_removedFromEditorHandler, return);
|
||||||
|
m_removedFromEditorHandler(this);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace ClangCodeModel
|
} // namespace ClangCodeModel
|
||||||
|
|
||||||
|
|||||||
@@ -30,18 +30,28 @@
|
|||||||
|
|
||||||
#include <texteditor/textmark.h>
|
#include <texteditor/textmark.h>
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
namespace ClangCodeModel {
|
namespace ClangCodeModel {
|
||||||
|
|
||||||
class ClangTextMark : public TextEditor::TextMark
|
class ClangTextMark : public TextEditor::TextMark
|
||||||
{
|
{
|
||||||
public:
|
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:
|
private:
|
||||||
bool addToolTipContent(QLayout *target);
|
|
||||||
void setIcon(ClangBackEnd::DiagnosticSeverity severity);
|
void setIcon(ClangBackEnd::DiagnosticSeverity severity);
|
||||||
|
|
||||||
|
bool addToolTipContent(QLayout *target) override;
|
||||||
|
void removedFromEditor() override;
|
||||||
|
|
||||||
|
private:
|
||||||
ClangBackEnd::DiagnosticContainer m_diagnostic;
|
ClangBackEnd::DiagnosticContainer m_diagnostic;
|
||||||
|
RemovedFromEditorHandler m_removedFromEditorHandler;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ClangCodeModel
|
} // namespace ClangCodeModel
|
||||||
|
|||||||
Reference in New Issue
Block a user