aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs/utils/outputformatter.h
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@qt.io>2020-03-19 16:00:37 +0100
committerChristian Kandeler <christian.kandeler@qt.io>2020-03-20 13:48:15 +0000
commit04a99c1de16e1d04bcc1908fec7464d15b421702 (patch)
tree1f298306aae0ae288bac75b0691c8968e6c72e6b /src/libs/utils/outputformatter.h
parent7158e676121767f43ac542cc3c958d8ed1279436 (diff)
Remove the limitation that output formatters have to be exclusive
Introduce an aggregating output formatter that forwards its input to a sub-formatter that feels responsible for it, or otherwise lets the base class handle it. Our output panes now use such an aggregating formatter. In particular, this means that in the future, we won't have to stuff all run control output formatting into the Qt output formatter anymore. Change-Id: I5498f200a61db10ccff3ec8974c6825da7f7072d Reviewed-by: hjk <hjk@qt.io>
Diffstat (limited to 'src/libs/utils/outputformatter.h')
-rw-r--r--src/libs/utils/outputformatter.h39
1 files changed, 32 insertions, 7 deletions
diff --git a/src/libs/utils/outputformatter.h b/src/libs/utils/outputformatter.h
index a5d9c4b331..0aaf880714 100644
--- a/src/libs/utils/outputformatter.h
+++ b/src/libs/utils/outputformatter.h
@@ -42,8 +42,11 @@ 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,26 +58,32 @@ public:
void appendMessage(const QString &text, OutputFormat format);
- virtual void handleLink(const QString &href);
+ virtual bool handleLink(const QString &href);
void clear();
void setBoldFontEnabled(bool enabled);
static QTextCharFormat linkFormat(const QTextCharFormat &inputFormat, const QString &href);
-protected:
- // text contains at most one line feed character, and if it does occur, it's the last character.
- // Either way, the input is to be considered "complete" for formatting purposes.
- virtual void doAppendMessage(const QString &text, OutputFormat format);
+ // For unit testing only
+ void overrideTextCharFormat(const QTextCharFormat &fmt);
- virtual void clearLastLine();
+protected:
+ enum class Status { Done, InProgress, NotHandled };
+ void appendMessageDefault(const QString &text, OutputFormat format);
+ void clearLastLine();
QTextCharFormat charFormat(OutputFormat format) const;
QList<FormattedText> parseAnsi(const QString &text, const QTextCharFormat &format);
QTextCursor &cursor() const;
private:
- void doAppendMessage(const QString &text, const QTextCharFormat &format);
+ // text contains at most one line feed character, and if it does occur, it's the last character.
+ // Either way, the input is to be considered "complete" for formatting purposes.
+ void doAppendMessage(const QString &text, OutputFormat format);
+
+ virtual Status handleMessage(const QString &text, OutputFormat format);
virtual void reset() {}
+ void doAppendMessage(const QString &text, const QTextCharFormat &format);
void append(const QString &text, const QTextCharFormat &format);
void initFormats();
void flushIncompleteLine();
@@ -83,4 +92,20 @@ 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:
+ Status handleMessage(const QString &text, OutputFormat format) override;
+
+ class Private;
+ Private * const d;
+};
+
} // namespace Utils