OutputFormatter: Take ownership of the line parsers

For symmetry with IOutputParser.

Task-number: QTCREATORBUG-22665
Change-Id: I92e93b32e87ff4f3fa163a2d2fe13768e56bfa24
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Christian Kandeler
2020-04-15 09:31:51 +02:00
parent c1dc36011f
commit d42920d372
8 changed files with 15 additions and 27 deletions

View File

@@ -67,6 +67,7 @@ OutputFormatter::OutputFormatter()
OutputFormatter::~OutputFormatter() OutputFormatter::~OutputFormatter()
{ {
qDeleteAll(d->lineParsers);
delete d; delete d;
} }
@@ -85,6 +86,8 @@ void OutputFormatter::setPlainTextEdit(QPlainTextEdit *plainText)
void OutputFormatter::setLineParsers(const QList<OutputLineParser *> &parsers) void OutputFormatter::setLineParsers(const QList<OutputLineParser *> &parsers)
{ {
flush();
qDeleteAll(d->lineParsers);
d->lineParsers = parsers; d->lineParsers = parsers;
d->nextParser = nullptr; d->nextParser = nullptr;
} }

View File

@@ -86,7 +86,7 @@ public:
QPlainTextEdit *plainTextEdit() const; QPlainTextEdit *plainTextEdit() const;
void setPlainTextEdit(QPlainTextEdit *plainText); void setPlainTextEdit(QPlainTextEdit *plainText);
void setLineParsers(const QList<OutputLineParser *> &parsers); void setLineParsers(const QList<OutputLineParser *> &parsers); // Takes ownership
void appendMessage(const QString &text, OutputFormat format); void appendMessage(const QString &text, OutputFormat format);
void flush(); void flush();

View File

@@ -566,12 +566,10 @@ void Internal::CorePlugin::testOutputFormatter()
" A trick\n" " A trick\n"
" embedded carriage return\n" " embedded carriage return\n"
"handled by B\n"; "handled by B\n";
TestFormatterA formatterA;
TestFormatterB formatterB;
OutputFormatter formatter; OutputFormatter formatter;
QPlainTextEdit textEdit; QPlainTextEdit textEdit;
formatter.setPlainTextEdit(&textEdit); formatter.setPlainTextEdit(&textEdit);
formatter.setLineParsers({&formatterB, &formatterA}); formatter.setLineParsers({new TestFormatterB, new TestFormatterA});
// Stress-test the implementation by providing the input in chunks, splitting at all possible // Stress-test the implementation by providing the input in chunks, splitting at all possible
// offsets. // offsets.

View File

@@ -154,7 +154,7 @@ AppOutputPane::RunControlTab::RunControlTab(RunControl *runControl, Core::Output
runControl(runControl), window(w) runControl(runControl), window(w)
{ {
if (runControl && w) if (runControl && w)
w->setLineParsers(runControl->outputParsers()); w->setLineParsers(runControl->createOutputParsers());
} }
AppOutputPane::AppOutputPane() : AppOutputPane::AppOutputPane() :
@@ -404,7 +404,7 @@ void AppOutputPane::createNewOutputWindow(RunControl *rc)
if (tab.runControl) if (tab.runControl)
tab.runControl->initiateFinish(); tab.runControl->initiateFinish();
tab.runControl = rc; tab.runControl = rc;
tab.window->setLineParsers(rc->outputParsers()); tab.window->setLineParsers(rc->createOutputParsers());
handleOldOutput(tab.window); handleOldOutput(tab.window);

View File

@@ -288,7 +288,6 @@ public:
q = nullptr; q = nullptr;
qDeleteAll(m_workers); qDeleteAll(m_workers);
m_workers.clear(); m_workers.clear();
qDeleteAll(outputParsers);
} }
Q_ENUM(RunControlState) Q_ENUM(RunControlState)
@@ -333,7 +332,6 @@ public:
Kit *kit = nullptr; // Not owned. Kit *kit = nullptr; // Not owned.
QPointer<Target> target; // Not owned. QPointer<Target> target; // Not owned.
QPointer<Project> project; // Not owned. QPointer<Project> project; // Not owned.
QList<Utils::OutputLineParser *> outputParsers;
std::function<bool(bool*)> promptToStop; std::function<bool(bool*)> promptToStop;
std::vector<RunWorkerFactory> m_factories; std::vector<RunWorkerFactory> m_factories;
@@ -384,9 +382,6 @@ void RunControl::setTarget(Target *target)
d->buildEnvironment = bc->environment(); d->buildEnvironment = bc->environment();
} }
QTC_CHECK(d->outputParsers.isEmpty());
d->outputParsers = OutputFormatterFactory::createFormatters(target);
setKit(target->kit()); setKit(target->kit());
d->project = target->project(); d->project = target->project();
} }
@@ -828,9 +823,9 @@ void RunControlPrivate::showError(const QString &msg)
q->appendMessage(msg + '\n', ErrorMessageFormat); q->appendMessage(msg + '\n', ErrorMessageFormat);
} }
QList<Utils::OutputLineParser *> RunControl::outputParsers() const QList<Utils::OutputLineParser *> RunControl::createOutputParsers() const
{ {
return d->outputParsers; return OutputFormatterFactory::createFormatters(target());
} }
Core::Id RunControl::runMode() const Core::Id RunControl::runMode() const

View File

@@ -238,7 +238,7 @@ public:
Utils::FilePath targetFilePath() const; Utils::FilePath targetFilePath() const;
Utils::FilePath projectFilePath() const; Utils::FilePath projectFilePath() const;
QList<Utils::OutputLineParser *> outputParsers() const; QList<Utils::OutputLineParser *> createOutputParsers() const;
Core::Id runMode() const; Core::Id runMode() const;
const Runnable &runnable() const; const Runnable &runnable() const;

View File

@@ -289,18 +289,9 @@ public:
class TestQtOutputFormatter : public OutputFormatter class TestQtOutputFormatter : public OutputFormatter
{ {
public: public:
TestQtOutputFormatter() : m_parser(new TestQtOutputLineParser) TestQtOutputFormatter() { setLineParsers({new TestQtOutputLineParser}); }
{
setLineParsers({m_parser});
}
~TestQtOutputFormatter() { delete m_parser; }
private:
OutputLineParser * const m_parser;
}; };
void QtSupportPlugin::testQtOutputFormatter_data() void QtSupportPlugin::testQtOutputFormatter_data()
{ {
QTest::addColumn<QString>("input"); QTest::addColumn<QString>("input");

View File

@@ -112,7 +112,7 @@ private:
Utils::OutputFormat m_format; Utils::OutputFormat m_format;
Utils::OutputFormatter m_formatter; Utils::OutputFormatter m_formatter;
VcsOutputLineParser m_parser; VcsOutputLineParser *m_parser = nullptr;
}; };
OutputWindowPlainTextEdit::OutputWindowPlainTextEdit(QWidget *parent) : OutputWindowPlainTextEdit::OutputWindowPlainTextEdit(QWidget *parent) :
@@ -122,7 +122,8 @@ OutputWindowPlainTextEdit::OutputWindowPlainTextEdit(QWidget *parent) :
setUndoRedoEnabled(false); setUndoRedoEnabled(false);
setFrameStyle(QFrame::NoFrame); setFrameStyle(QFrame::NoFrame);
m_formatter.setBoldFontEnabled(false); m_formatter.setBoldFontEnabled(false);
setLineParsers({&m_parser}); m_parser = new VcsOutputLineParser;
setLineParsers({m_parser});
auto agg = new Aggregation::Aggregate; auto agg = new Aggregation::Aggregate;
agg->add(this); agg->add(this);
agg->add(new Core::BaseTextFind(this)); agg->add(new Core::BaseTextFind(this));
@@ -251,7 +252,7 @@ void OutputWindowPlainTextEdit::appendLinesWithStyle(const QString &s,
VcsOutputLineParser *OutputWindowPlainTextEdit::parser() VcsOutputLineParser *OutputWindowPlainTextEdit::parser()
{ {
return &m_parser; return m_parser;
} }
void OutputWindowPlainTextEdit::setFormat(VcsOutputWindow::MessageStyle style) void OutputWindowPlainTextEdit::setFormat(VcsOutputWindow::MessageStyle style)