forked from qt-creator/qt-creator
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:
@@ -67,6 +67,7 @@ OutputFormatter::OutputFormatter()
|
||||
|
||||
OutputFormatter::~OutputFormatter()
|
||||
{
|
||||
qDeleteAll(d->lineParsers);
|
||||
delete d;
|
||||
}
|
||||
|
||||
@@ -85,6 +86,8 @@ void OutputFormatter::setPlainTextEdit(QPlainTextEdit *plainText)
|
||||
|
||||
void OutputFormatter::setLineParsers(const QList<OutputLineParser *> &parsers)
|
||||
{
|
||||
flush();
|
||||
qDeleteAll(d->lineParsers);
|
||||
d->lineParsers = parsers;
|
||||
d->nextParser = nullptr;
|
||||
}
|
||||
|
@@ -86,7 +86,7 @@ public:
|
||||
QPlainTextEdit *plainTextEdit() const;
|
||||
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 flush();
|
||||
|
@@ -566,12 +566,10 @@ void Internal::CorePlugin::testOutputFormatter()
|
||||
" A trick\n"
|
||||
" embedded carriage return\n"
|
||||
"handled by B\n";
|
||||
TestFormatterA formatterA;
|
||||
TestFormatterB formatterB;
|
||||
OutputFormatter formatter;
|
||||
QPlainTextEdit 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
|
||||
// offsets.
|
||||
|
@@ -154,7 +154,7 @@ AppOutputPane::RunControlTab::RunControlTab(RunControl *runControl, Core::Output
|
||||
runControl(runControl), window(w)
|
||||
{
|
||||
if (runControl && w)
|
||||
w->setLineParsers(runControl->outputParsers());
|
||||
w->setLineParsers(runControl->createOutputParsers());
|
||||
}
|
||||
|
||||
AppOutputPane::AppOutputPane() :
|
||||
@@ -404,7 +404,7 @@ void AppOutputPane::createNewOutputWindow(RunControl *rc)
|
||||
if (tab.runControl)
|
||||
tab.runControl->initiateFinish();
|
||||
tab.runControl = rc;
|
||||
tab.window->setLineParsers(rc->outputParsers());
|
||||
tab.window->setLineParsers(rc->createOutputParsers());
|
||||
|
||||
handleOldOutput(tab.window);
|
||||
|
||||
|
@@ -288,7 +288,6 @@ public:
|
||||
q = nullptr;
|
||||
qDeleteAll(m_workers);
|
||||
m_workers.clear();
|
||||
qDeleteAll(outputParsers);
|
||||
}
|
||||
|
||||
Q_ENUM(RunControlState)
|
||||
@@ -333,7 +332,6 @@ public:
|
||||
Kit *kit = nullptr; // Not owned.
|
||||
QPointer<Target> target; // Not owned.
|
||||
QPointer<Project> project; // Not owned.
|
||||
QList<Utils::OutputLineParser *> outputParsers;
|
||||
std::function<bool(bool*)> promptToStop;
|
||||
std::vector<RunWorkerFactory> m_factories;
|
||||
|
||||
@@ -384,9 +382,6 @@ void RunControl::setTarget(Target *target)
|
||||
d->buildEnvironment = bc->environment();
|
||||
}
|
||||
|
||||
QTC_CHECK(d->outputParsers.isEmpty());
|
||||
d->outputParsers = OutputFormatterFactory::createFormatters(target);
|
||||
|
||||
setKit(target->kit());
|
||||
d->project = target->project();
|
||||
}
|
||||
@@ -828,9 +823,9 @@ void RunControlPrivate::showError(const QString &msg)
|
||||
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
|
||||
|
@@ -238,7 +238,7 @@ public:
|
||||
Utils::FilePath targetFilePath() const;
|
||||
Utils::FilePath projectFilePath() const;
|
||||
|
||||
QList<Utils::OutputLineParser *> outputParsers() const;
|
||||
QList<Utils::OutputLineParser *> createOutputParsers() const;
|
||||
Core::Id runMode() const;
|
||||
|
||||
const Runnable &runnable() const;
|
||||
|
@@ -289,18 +289,9 @@ public:
|
||||
class TestQtOutputFormatter : public OutputFormatter
|
||||
{
|
||||
public:
|
||||
TestQtOutputFormatter() : m_parser(new TestQtOutputLineParser)
|
||||
{
|
||||
setLineParsers({m_parser});
|
||||
}
|
||||
|
||||
~TestQtOutputFormatter() { delete m_parser; }
|
||||
|
||||
private:
|
||||
OutputLineParser * const m_parser;
|
||||
TestQtOutputFormatter() { setLineParsers({new TestQtOutputLineParser}); }
|
||||
};
|
||||
|
||||
|
||||
void QtSupportPlugin::testQtOutputFormatter_data()
|
||||
{
|
||||
QTest::addColumn<QString>("input");
|
||||
|
@@ -112,7 +112,7 @@ private:
|
||||
|
||||
Utils::OutputFormat m_format;
|
||||
Utils::OutputFormatter m_formatter;
|
||||
VcsOutputLineParser m_parser;
|
||||
VcsOutputLineParser *m_parser = nullptr;
|
||||
};
|
||||
|
||||
OutputWindowPlainTextEdit::OutputWindowPlainTextEdit(QWidget *parent) :
|
||||
@@ -122,7 +122,8 @@ OutputWindowPlainTextEdit::OutputWindowPlainTextEdit(QWidget *parent) :
|
||||
setUndoRedoEnabled(false);
|
||||
setFrameStyle(QFrame::NoFrame);
|
||||
m_formatter.setBoldFontEnabled(false);
|
||||
setLineParsers({&m_parser});
|
||||
m_parser = new VcsOutputLineParser;
|
||||
setLineParsers({m_parser});
|
||||
auto agg = new Aggregation::Aggregate;
|
||||
agg->add(this);
|
||||
agg->add(new Core::BaseTextFind(this));
|
||||
@@ -251,7 +252,7 @@ void OutputWindowPlainTextEdit::appendLinesWithStyle(const QString &s,
|
||||
|
||||
VcsOutputLineParser *OutputWindowPlainTextEdit::parser()
|
||||
{
|
||||
return &m_parser;
|
||||
return m_parser;
|
||||
}
|
||||
|
||||
void OutputWindowPlainTextEdit::setFormat(VcsOutputWindow::MessageStyle style)
|
||||
|
Reference in New Issue
Block a user