forked from qt-creator/qt-creator
Utils: remove OptionalLineColumn
LineColumn already has a isValid() that is sufficient for the use case. Change-Id: I7f6e1d64b66a9af05d74ce0ef45717265dc28ed3 Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
@@ -39,8 +39,6 @@ public:
|
|||||||
int column = -1;
|
int column = -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
using OptionalLineColumn = std::optional<LineColumn>;
|
|
||||||
|
|
||||||
} // namespace Utils
|
} // namespace Utils
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(Utils::LineColumn)
|
Q_DECLARE_METATYPE(Utils::LineColumn)
|
||||||
|
|||||||
@@ -53,16 +53,13 @@ bool convertPosition(const QTextDocument *document, int pos, int *line, int *col
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
OptionalLineColumn convertPosition(const QTextDocument *document, int pos)
|
LineColumn convertPosition(const QTextDocument *document, int pos)
|
||||||
{
|
{
|
||||||
OptionalLineColumn optional;
|
const QTextBlock block = document->findBlock(pos);
|
||||||
|
|
||||||
QTextBlock block = document->findBlock(pos);
|
|
||||||
|
|
||||||
if (block.isValid())
|
if (block.isValid())
|
||||||
optional.emplace(block.blockNumber() + 1, pos - block.position());
|
return {block.blockNumber() + 1, pos - block.position()};
|
||||||
|
|
||||||
return optional;
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
int positionInText(const QTextDocument *textDocument, int line, int column)
|
int positionInText(const QTextDocument *textDocument, int line, int column)
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ QTCREATOR_UTILS_EXPORT bool convertPosition(const QTextDocument *document,
|
|||||||
int pos,
|
int pos,
|
||||||
int *line, int *column);
|
int *line, int *column);
|
||||||
QTCREATOR_UTILS_EXPORT
|
QTCREATOR_UTILS_EXPORT
|
||||||
OptionalLineColumn convertPosition(const QTextDocument *document, int pos);
|
LineColumn convertPosition(const QTextDocument *document, int pos);
|
||||||
|
|
||||||
// line and column are 1-based
|
// line and column are 1-based
|
||||||
QTCREATOR_UTILS_EXPORT int positionInText(const QTextDocument *textDocument, int line, int column);
|
QTCREATOR_UTILS_EXPORT int positionInText(const QTextDocument *textDocument, int line, int column);
|
||||||
|
|||||||
@@ -1052,12 +1052,12 @@ TextEditor::BaseTextEditor *jsonEditor()
|
|||||||
QJsonDocument::fromJson(content.toUtf8(), &error);
|
QJsonDocument::fromJson(content.toUtf8(), &error);
|
||||||
if (error.error == QJsonParseError::NoError)
|
if (error.error == QJsonParseError::NoError)
|
||||||
return;
|
return;
|
||||||
const Utils::OptionalLineColumn lineColumn
|
const Utils::LineColumn lineColumn
|
||||||
= Utils::Text::convertPosition(document->document(), error.offset);
|
= Utils::Text::convertPosition(document->document(), error.offset);
|
||||||
if (!lineColumn.has_value())
|
if (!lineColumn.isValid())
|
||||||
return;
|
return;
|
||||||
auto mark = new TextMark(Utils::FilePath(),
|
auto mark = new TextMark(Utils::FilePath(),
|
||||||
lineColumn->line,
|
lineColumn.line,
|
||||||
{::LanguageClient::Tr::tr("JSON Error"), jsonMarkId});
|
{::LanguageClient::Tr::tr("JSON Error"), jsonMarkId});
|
||||||
mark->setLineAnnotation(error.errorString());
|
mark->setLineAnnotation(error.errorString());
|
||||||
mark->setColor(Utils::Theme::CodeModel_Error_TextMarkColor);
|
mark->setColor(Utils::Theme::CodeModel_Error_TextMarkColor);
|
||||||
|
|||||||
Reference in New Issue
Block a user