forked from qt-creator/qt-creator
Utils: Split up OutputFormatter class
An OutputFormatter takes some string and prints it into a text edit. In addition, it can ask any number of registered OutputLineParsers whether they think any special formatting should be applied to the current line. This mechanism is now properly modeled by our class design, rather than being hidden in a monolithic class where everything had the same type, no matter what its purpose was. Prospective contributors can now simply be pointed to the OutputLineParser class and will see at one glance what they have to do. Change-Id: I9844499f062c94fb038ce73fd6f26576910148c2 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -60,10 +60,10 @@ using namespace Utils;
|
||||
namespace Python {
|
||||
namespace Internal {
|
||||
|
||||
class PythonOutputFormatter : public OutputFormatter
|
||||
class PythonOutputLineParser : public OutputLineParser
|
||||
{
|
||||
public:
|
||||
PythonOutputFormatter()
|
||||
PythonOutputLineParser()
|
||||
// Note that moc dislikes raw string literals.
|
||||
: filePattern("^(\\s*)(File \"([^\"]+)\", line (\\d+), .*$)")
|
||||
{
|
||||
@@ -71,7 +71,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
Result handleMessage(const QString &text, OutputFormat format) final
|
||||
Result handleLine(const QString &text, OutputFormat format) final
|
||||
{
|
||||
if (!m_inTraceBack) {
|
||||
m_inTraceBack = format == StdErrFormat
|
||||
@@ -337,9 +337,9 @@ PythonRunConfigurationFactory::PythonRunConfigurationFactory()
|
||||
|
||||
PythonOutputFormatterFactory::PythonOutputFormatterFactory()
|
||||
{
|
||||
setFormatterCreator([](Target *t) -> OutputFormatter * {
|
||||
setFormatterCreator([](Target *t) -> OutputLineParser * {
|
||||
if (t->project()->mimeType() == Constants::C_PY_MIMETYPE)
|
||||
return new PythonOutputFormatter;
|
||||
return new PythonOutputLineParser;
|
||||
return nullptr;
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user