aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/libs/utils/outputformatter.cpp104
-rw-r--r--src/libs/utils/outputformatter.h21
-rw-r--r--src/plugins/coreplugin/outputwindow.cpp4
3 files changed, 45 insertions, 84 deletions
diff --git a/src/libs/utils/outputformatter.cpp b/src/libs/utils/outputformatter.cpp
index 938030a87f..452ec5ae06 100644
--- a/src/libs/utils/outputformatter.cpp
+++ b/src/libs/utils/outputformatter.cpp
@@ -48,6 +48,8 @@ public:
AnsiEscapeCodeHandler escapeCodeHandler;
QPair<QString, OutputFormat> incompleteLine;
optional<QTextCharFormat> formatOverride;
+ QList<OutputFormatter *> formatters;
+ OutputFormatter *nextFormatter = nullptr;
bool boldFontEnabled = true;
bool prependCarriageReturn = false;
};
@@ -77,6 +79,14 @@ void OutputFormatter::setPlainTextEdit(QPlainTextEdit *plainText)
initFormats();
}
+void OutputFormatter::setFormatters(const QList<OutputFormatter *> &formatters)
+{
+ for (OutputFormatter * const f : formatters)
+ f->setPlainTextEdit(plainTextEdit());
+ d->formatters = formatters;
+ d->nextFormatter = nullptr;
+}
+
void OutputFormatter::doAppendMessage(const QString &text, OutputFormat format)
{
const QTextCharFormat charFmt = charFormat(format);
@@ -94,8 +104,33 @@ void OutputFormatter::doAppendMessage(const QString &text, OutputFormat format)
OutputFormatter::Result OutputFormatter::handleMessage(const QString &text, OutputFormat format)
{
- Q_UNUSED(text);
- Q_UNUSED(format);
+ if (d->nextFormatter) {
+ const Result res = d->nextFormatter->handleMessage(text, format);
+ switch (res.status) {
+ case Status::Done:
+ d->nextFormatter = nullptr;
+ return res;
+ case Status::InProgress:
+ return res;
+ case Status::NotHandled:
+ QTC_CHECK(false); // TODO: This case will be legal after the merge
+ d->nextFormatter = nullptr;
+ return res;
+ }
+ }
+ QTC_CHECK(!d->nextFormatter);
+ for (OutputFormatter * const formatter : qAsConst(d->formatters)) {
+ const Result res = formatter->handleMessage(text, format);
+ switch (res.status) {
+ case Status::Done:
+ return res;
+ case Status::InProgress:
+ d->nextFormatter = formatter;
+ return res;
+ case Status::NotHandled:
+ break;
+ }
+ }
return Status::NotHandled;
}
@@ -233,7 +268,10 @@ void OutputFormatter::dumpIncompleteLine(const QString &line, OutputFormat forma
bool OutputFormatter::handleLink(const QString &href)
{
- Q_UNUSED(href)
+ for (OutputFormatter * const f : qAsConst(d->formatters)) {
+ if (f->handleLink(href))
+ return true;
+ }
return false;
}
@@ -310,64 +348,4 @@ void OutputFormatter::appendMessage(const QString &text, OutputFormat format)
}
}
-class AggregatingOutputFormatter::Private
-{
-public:
- QList<OutputFormatter *> formatters;
- OutputFormatter *nextFormatter = nullptr;
-};
-
-AggregatingOutputFormatter::AggregatingOutputFormatter() : d(new Private) {}
-AggregatingOutputFormatter::~AggregatingOutputFormatter() { delete d; }
-
-void AggregatingOutputFormatter::setFormatters(const QList<OutputFormatter *> &formatters)
-{
- for (OutputFormatter * const f : formatters)
- f->setPlainTextEdit(plainTextEdit());
- d->formatters = formatters;
- d->nextFormatter = nullptr;
-}
-
-OutputFormatter::Result AggregatingOutputFormatter::handleMessage(const QString &text,
- OutputFormat format)
-{
- if (d->nextFormatter) {
- const Result res = d->nextFormatter->handleMessage(text, format);
- switch (res.status) {
- case Status::Done:
- d->nextFormatter = nullptr;
- return res;
- case Status::InProgress:
- return res;
- case Status::NotHandled:
- QTC_CHECK(false); // TODO: This case will be legal after the merge
- d->nextFormatter = nullptr;
- return res;
- }
- }
- QTC_CHECK(!d->nextFormatter);
- for (OutputFormatter * const formatter : qAsConst(d->formatters)) {
- const Result res = formatter->handleMessage(text, format);
- switch (res.status) {
- case Status::Done:
- return res;
- case Status::InProgress:
- d->nextFormatter = formatter;
- return res;
- case Status::NotHandled:
- break;
- }
- }
- return Status::NotHandled;
-}
-
-bool AggregatingOutputFormatter::handleLink(const QString &href)
-{
- for (OutputFormatter * const f : qAsConst(d->formatters)) {
- if (f->handleLink(href))
- return true;
- }
- return false;
-}
-
} // namespace Utils
diff --git a/src/libs/utils/outputformatter.h b/src/libs/utils/outputformatter.h
index a08ecd6863..d38d573d79 100644
--- a/src/libs/utils/outputformatter.h
+++ b/src/libs/utils/outputformatter.h
@@ -43,11 +43,8 @@ class FormattedText;
namespace Internal { class OutputFormatterPrivate; }
-class QTCREATOR_UTILS_EXPORT AggregatingOutputFormatter;
-
class QTCREATOR_UTILS_EXPORT OutputFormatter : public QObject
{
- friend class AggregatingOutputFormatter;
public:
OutputFormatter();
~OutputFormatter() override;
@@ -55,6 +52,8 @@ public:
QPlainTextEdit *plainTextEdit() const;
void setPlainTextEdit(QPlainTextEdit *plainText);
+ void setFormatters(const QList<OutputFormatter *> &formatters);
+
void flush();
void appendMessage(const QString &text, OutputFormat format);
@@ -109,20 +108,4 @@ private:
Internal::OutputFormatterPrivate *d;
};
-class QTCREATOR_UTILS_EXPORT AggregatingOutputFormatter : public OutputFormatter
-{
-public:
- AggregatingOutputFormatter();
- ~AggregatingOutputFormatter();
-
- void setFormatters(const QList<OutputFormatter *> &formatters);
- bool handleLink(const QString &href) override;
-
-private:
- Result handleMessage(const QString &text, OutputFormat format) override;
-
- class Private;
- Private * const d;
-};
-
} // namespace Utils
diff --git a/src/plugins/coreplugin/outputwindow.cpp b/src/plugins/coreplugin/outputwindow.cpp
index ed4423ae98..2cf6643c71 100644
--- a/src/plugins/coreplugin/outputwindow.cpp
+++ b/src/plugins/coreplugin/outputwindow.cpp
@@ -66,7 +66,7 @@ public:
IContext *outputWindowContext = nullptr;
QString settingsKey;
- AggregatingOutputFormatter formatter;
+ OutputFormatter formatter;
bool scrollToBottom = true;
bool linksActive = true;
@@ -568,7 +568,7 @@ void Internal::CorePlugin::testOutputFormatter()
"handled by B\n";
TestFormatterA formatterA;
TestFormatterB formatterB;
- AggregatingOutputFormatter formatter;
+ OutputFormatter formatter;
QPlainTextEdit textEdit;
formatter.setPlainTextEdit(&textEdit);
formatter.setFormatters({&formatterB, &formatterA});