forked from qt-creator/qt-creator
Clang: Use fontsettings in diagnostics
Change-Id: I8438293a37a53532927520106d4ee5346237ebfe Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
This commit is contained in:
@@ -31,7 +31,9 @@
|
|||||||
#include "clangdiagnosticfilter.h"
|
#include "clangdiagnosticfilter.h"
|
||||||
#include "clangdiagnosticmanager.h"
|
#include "clangdiagnosticmanager.h"
|
||||||
|
|
||||||
|
#include <texteditor/fontsettings.h>
|
||||||
#include <texteditor/textdocument.h>
|
#include <texteditor/textdocument.h>
|
||||||
|
#include <texteditor/texteditorsettings.h>
|
||||||
|
|
||||||
#include <utils/fileutils.h>
|
#include <utils/fileutils.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
@@ -53,7 +55,7 @@ QTextEdit::ExtraSelection createExtraSelections(const QTextCharFormat &mainforma
|
|||||||
|
|
||||||
void addRangeSelections(const ClangBackEnd::DiagnosticContainer &diagnostic,
|
void addRangeSelections(const ClangBackEnd::DiagnosticContainer &diagnostic,
|
||||||
QTextDocument *textDocument,
|
QTextDocument *textDocument,
|
||||||
const QTextCharFormat &rangeFormat,
|
const QTextCharFormat &contextFormat,
|
||||||
const QString &diagnosticText,
|
const QString &diagnosticText,
|
||||||
QList<QTextEdit::ExtraSelection> &extraSelections)
|
QList<QTextEdit::ExtraSelection> &extraSelections)
|
||||||
{
|
{
|
||||||
@@ -62,7 +64,7 @@ void addRangeSelections(const ClangBackEnd::DiagnosticContainer &diagnostic,
|
|||||||
cursor.setPosition(int(range.start().offset()));
|
cursor.setPosition(int(range.start().offset()));
|
||||||
cursor.setPosition(int(range.end().offset()), QTextCursor::KeepAnchor);
|
cursor.setPosition(int(range.end().offset()), QTextCursor::KeepAnchor);
|
||||||
|
|
||||||
auto extraSelection = createExtraSelections(rangeFormat, cursor, diagnosticText);
|
auto extraSelection = createExtraSelections(contextFormat, cursor, diagnosticText);
|
||||||
|
|
||||||
extraSelections.push_back(std::move(extraSelection));
|
extraSelections.push_back(std::move(extraSelection));
|
||||||
}
|
}
|
||||||
@@ -116,7 +118,7 @@ QString diagnosticText(const ClangBackEnd::DiagnosticContainer &diagnostic)
|
|||||||
void addSelections(const QVector<ClangBackEnd::DiagnosticContainer> &diagnostics,
|
void addSelections(const QVector<ClangBackEnd::DiagnosticContainer> &diagnostics,
|
||||||
QTextDocument *textDocument,
|
QTextDocument *textDocument,
|
||||||
const QTextCharFormat &mainFormat,
|
const QTextCharFormat &mainFormat,
|
||||||
const QTextCharFormat &rangeFormat,
|
const QTextCharFormat &contextFormat,
|
||||||
QList<QTextEdit::ExtraSelection> &extraSelections)
|
QList<QTextEdit::ExtraSelection> &extraSelections)
|
||||||
{
|
{
|
||||||
for (auto &&diagnostic : diagnostics) {
|
for (auto &&diagnostic : diagnostics) {
|
||||||
@@ -125,7 +127,7 @@ void addSelections(const QVector<ClangBackEnd::DiagnosticContainer> &diagnostics
|
|||||||
auto text = diagnosticText(diagnostic);
|
auto text = diagnosticText(diagnostic);
|
||||||
auto extraSelection = createExtraSelections(mainFormat, cursor, text);
|
auto extraSelection = createExtraSelections(mainFormat, cursor, text);
|
||||||
|
|
||||||
addRangeSelections(diagnostic, textDocument, rangeFormat, text, extraSelections);
|
addRangeSelections(diagnostic, textDocument, contextFormat, text, extraSelections);
|
||||||
|
|
||||||
extraSelections.push_back(std::move(extraSelection));
|
extraSelections.push_back(std::move(extraSelection));
|
||||||
}
|
}
|
||||||
@@ -135,30 +137,25 @@ void addWarningSelections(const QVector<ClangBackEnd::DiagnosticContainer> &diag
|
|||||||
QTextDocument *textDocument,
|
QTextDocument *textDocument,
|
||||||
QList<QTextEdit::ExtraSelection> &extraSelections)
|
QList<QTextEdit::ExtraSelection> &extraSelections)
|
||||||
{
|
{
|
||||||
QTextCharFormat warningFormat;
|
const auto fontSettings = TextEditor::TextEditorSettings::instance()->fontSettings();
|
||||||
warningFormat.setUnderlineStyle(QTextCharFormat::SingleUnderline);
|
|
||||||
warningFormat.setUnderlineColor(QColor(180, 180, 0, 255));
|
|
||||||
|
|
||||||
QTextCharFormat warningRangeFormat;
|
QTextCharFormat warningFormat = fontSettings.toTextCharFormat(TextEditor::C_WARNING);
|
||||||
warningRangeFormat.setUnderlineStyle(QTextCharFormat::DotLine);
|
|
||||||
warningRangeFormat.setUnderlineColor(QColor(180, 180, 0, 255));
|
|
||||||
|
|
||||||
addSelections(diagnostics, textDocument, warningFormat, warningRangeFormat, extraSelections);
|
QTextCharFormat warningContextFormat = fontSettings.toTextCharFormat(TextEditor::C_WARNING_CONTEXT);
|
||||||
|
|
||||||
|
addSelections(diagnostics, textDocument, warningFormat, warningContextFormat, extraSelections);
|
||||||
}
|
}
|
||||||
|
|
||||||
void addErrorSelections(const QVector<ClangBackEnd::DiagnosticContainer> &diagnostics,
|
void addErrorSelections(const QVector<ClangBackEnd::DiagnosticContainer> &diagnostics,
|
||||||
QTextDocument *textDocument,
|
QTextDocument *textDocument,
|
||||||
QList<QTextEdit::ExtraSelection> &extraSelections)
|
QList<QTextEdit::ExtraSelection> &extraSelections)
|
||||||
{
|
{
|
||||||
QTextCharFormat errorFormat;
|
const auto fontSettings = TextEditor::TextEditorSettings::instance()->fontSettings();
|
||||||
errorFormat.setUnderlineStyle(QTextCharFormat::SingleUnderline);
|
|
||||||
errorFormat.setUnderlineColor(QColor(255, 0, 0, 255));
|
|
||||||
|
|
||||||
QTextCharFormat errorRangeFormat;
|
QTextCharFormat errorFormat = fontSettings.toTextCharFormat(TextEditor::C_ERROR);
|
||||||
errorRangeFormat.setUnderlineStyle(QTextCharFormat::DotLine);
|
QTextCharFormat errorContextFormat = fontSettings.toTextCharFormat(TextEditor::C_ERROR_CONTEXT);
|
||||||
errorRangeFormat.setUnderlineColor(QColor(255, 0, 0, 255));
|
|
||||||
|
|
||||||
addSelections(diagnostics, textDocument, errorFormat, errorRangeFormat, extraSelections);
|
addSelections(diagnostics, textDocument, errorFormat, errorContextFormat, extraSelections);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // anonymous
|
} // anonymous
|
||||||
|
Reference in New Issue
Block a user