forked from qt-creator/qt-creator
OutputFormatter: Do all formatting centrally
Instead of working directly on the text edit, the specialized OutputFormatter classes now simply ask the base class to do it for them. In practice, the request currently always is "turn this part of the text into a link", but the interface can be extended to other types of formatting, should that ever be required. This is a win/win situation: Derived classes no longer have to fiddle with QTextCursor & friends (nor do they have to call any base class functions), while the base class can make strong assumptions about what the derived class does to the text edit (i.e.: nothing). Change-Id: Icc4bc52d4001b0359247563e39a206fa274833d7 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -71,30 +71,24 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
Status handleMessage(const QString &text, OutputFormat format) final
|
||||
Result handleMessage(const QString &text, OutputFormat format) final
|
||||
{
|
||||
if (!m_inTraceBack) {
|
||||
m_inTraceBack = format == StdErrFormat
|
||||
&& text.startsWith("Traceback (most recent call last):");
|
||||
if (m_inTraceBack) {
|
||||
OutputFormatter::appendMessageDefault(text, format);
|
||||
if (m_inTraceBack)
|
||||
return Status::InProgress;
|
||||
}
|
||||
return Status::NotHandled;
|
||||
}
|
||||
|
||||
const Core::Id category(PythonErrorTaskCategory);
|
||||
const QRegularExpressionMatch match = filePattern.match(text);
|
||||
if (match.hasMatch()) {
|
||||
QTextCursor tc = plainTextEdit()->textCursor();
|
||||
tc.movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
|
||||
tc.insertText(match.captured(1));
|
||||
tc.insertText(match.captured(2), linkFormat(charFormat(format), match.captured(2)));
|
||||
|
||||
const LinkSpec link(match.capturedStart(2), match.capturedLength(2), match.captured(2));
|
||||
const auto fileName = FilePath::fromString(match.captured(3));
|
||||
const int lineNumber = match.capturedRef(4).toInt();
|
||||
m_tasks.append({Task::Warning, QString(), fileName, lineNumber, category});
|
||||
return Status::InProgress;
|
||||
return {Status::InProgress, {link}};
|
||||
}
|
||||
|
||||
Status status = Status::InProgress;
|
||||
@@ -118,7 +112,6 @@ private:
|
||||
m_inTraceBack = false;
|
||||
status = Status::Done;
|
||||
}
|
||||
OutputFormatter::appendMessageDefault(text, format);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user