forked from qt-creator/qt-creator
ClangTools: properly initialize diagnostic mark without document
After removing the delegating constructor the code in the body of the
called constructor was not executed anymore. Move that code into a
separate function and call it from every constructor to make sure that
the text mark is properly initialized.
Amends d7ed05ae14
.
Fixes: QTCREATORBUG-31153
Change-Id: Ic320d470d39a927c3f7027a0041e843cdea5aa9c
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -29,43 +29,15 @@ DiagnosticMark::DiagnosticMark(const Diagnostic &diagnostic, TextDocument *docum
|
||||
: TextMark(document, diagnostic.location.line, clangToolsCategory())
|
||||
, m_diagnostic(diagnostic)
|
||||
{
|
||||
setSettingsPage(Constants::SETTINGS_PAGE_ID);
|
||||
|
||||
const bool isError = diagnostic.type == "error" || diagnostic.type == "fatal";
|
||||
setColor(isError ? Theme::CodeModel_Error_TextMarkColor : Theme::CodeModel_Warning_TextMarkColor);
|
||||
setPriority(isError ? TextEditor::TextMark::HighPriority : TextEditor::TextMark::NormalPriority);
|
||||
QIcon markIcon = diagnostic.icon();
|
||||
setIcon(markIcon.isNull() ? Icons::CODEMODEL_WARNING.icon() : markIcon);
|
||||
setToolTip(createDiagnosticToolTipString(diagnostic, std::nullopt, true));
|
||||
setLineAnnotation(diagnostic.description);
|
||||
setActionsProvider([diagnostic] {
|
||||
// Copy to clipboard action
|
||||
QList<QAction *> actions;
|
||||
QAction *action = new QAction();
|
||||
action->setIcon(Icon::fromTheme("edit-copy"));
|
||||
action->setToolTip(Tr::tr("Copy to Clipboard"));
|
||||
QObject::connect(action, &QAction::triggered, [diagnostic] {
|
||||
const QString text = createFullLocationString(diagnostic.location)
|
||||
+ ": "
|
||||
+ diagnostic.description;
|
||||
setClipboardAndSelection(text);
|
||||
});
|
||||
actions << action;
|
||||
|
||||
// Disable diagnostic action
|
||||
action = new QAction();
|
||||
action->setIcon(Icons::BROKEN.icon());
|
||||
action->setToolTip(Tr::tr("Disable Diagnostic"));
|
||||
QObject::connect(action, &QAction::triggered, [diagnostic] { disableChecks({diagnostic}); });
|
||||
actions << action;
|
||||
return actions;
|
||||
});
|
||||
initialize();
|
||||
}
|
||||
|
||||
DiagnosticMark::DiagnosticMark(const Diagnostic &diagnostic)
|
||||
: TextMark(diagnostic.location.filePath, diagnostic.location.line, clangToolsCategory())
|
||||
, m_diagnostic(diagnostic)
|
||||
{}
|
||||
{
|
||||
initialize();
|
||||
}
|
||||
|
||||
void DiagnosticMark::disable()
|
||||
{
|
||||
@@ -89,6 +61,41 @@ Diagnostic DiagnosticMark::diagnostic() const
|
||||
return m_diagnostic;
|
||||
}
|
||||
|
||||
void DiagnosticMark::initialize()
|
||||
{
|
||||
setSettingsPage(Constants::SETTINGS_PAGE_ID);
|
||||
|
||||
const bool isError = m_diagnostic.type == "error" || m_diagnostic.type == "fatal";
|
||||
setColor(isError ? Theme::CodeModel_Error_TextMarkColor : Theme::CodeModel_Warning_TextMarkColor);
|
||||
setPriority(isError ? TextEditor::TextMark::HighPriority : TextEditor::TextMark::NormalPriority);
|
||||
QIcon markIcon = m_diagnostic.icon();
|
||||
setIcon(markIcon.isNull() ? Icons::CODEMODEL_WARNING.icon() : markIcon);
|
||||
setToolTip(createDiagnosticToolTipString(m_diagnostic, std::nullopt, true));
|
||||
setLineAnnotation(m_diagnostic.description);
|
||||
setActionsProvider([diagnostic = m_diagnostic] {
|
||||
// Copy to clipboard action
|
||||
QList<QAction *> actions;
|
||||
QAction *action = new QAction();
|
||||
action->setIcon(Icon::fromTheme("edit-copy"));
|
||||
action->setToolTip(Tr::tr("Copy to Clipboard"));
|
||||
QObject::connect(action, &QAction::triggered, [diagnostic] {
|
||||
const QString text = createFullLocationString(diagnostic.location)
|
||||
+ ": "
|
||||
+ diagnostic.description;
|
||||
setClipboardAndSelection(text);
|
||||
});
|
||||
actions << action;
|
||||
|
||||
// Disable diagnostic action
|
||||
action = new QAction();
|
||||
action->setIcon(Icons::BROKEN.icon());
|
||||
action->setToolTip(Tr::tr("Disable Diagnostic"));
|
||||
QObject::connect(action, &QAction::triggered, [diagnostic] { disableChecks({diagnostic}); });
|
||||
actions << action;
|
||||
return actions;
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace ClangTools
|
||||
|
||||
|
@@ -25,6 +25,7 @@ public:
|
||||
std::optional<CppEditor::ClangToolType> toolType;
|
||||
|
||||
private:
|
||||
void initialize();
|
||||
const Diagnostic m_diagnostic;
|
||||
bool m_enabled = true;
|
||||
};
|
||||
|
Reference in New Issue
Block a user