diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2017-12-18 08:55:18 +0100 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2019-04-17 15:26:54 +0000 |
commit | 65314b6ce88cdbb28a22be0cab9856ec9bc9604b (patch) | |
tree | 6f9e794face29ede4b7501027af20a2fb37f2e4c /src/widgets | |
parent | 860bf13dbd2e9ad0a87b75defcab2cc3c9c771f3 (diff) |
Add QTextMarkdownImporter
This provides the ability to read from a Markdown string or file into
a QTextDocument, such that the formatting will be recognized and can be
rendered.
- Add QTextDocument::setMarkdown(QString)
- Add QTextEdit::setMarkdown(QString)
- Add TextFormat::MarkdownText
- QWidgetTextControl::setContent() calls QTextDocument::setMarkdown()
if that's the format
Fixes: QTBUG-72349
Change-Id: Ief2ad71bf840666c64145d58e9ca71d05fad5659
Reviewed-by: Lisandro Damián Nicanor Pérez Meyer <perezmeyer@gmail.com>
Reviewed-by: Gatis Paeglis <gatis.paeglis@qt.io>
Diffstat (limited to 'src/widgets')
-rw-r--r-- | src/widgets/widgets/qtextedit.cpp | 9 | ||||
-rw-r--r-- | src/widgets/widgets/qtextedit.h | 5 | ||||
-rw-r--r-- | src/widgets/widgets/qwidgettextcontrol.cpp | 15 | ||||
-rw-r--r-- | src/widgets/widgets/qwidgettextcontrol_p.h | 5 | ||||
-rw-r--r-- | src/widgets/widgets/qwidgettextcontrol_p_p.h | 2 |
5 files changed, 31 insertions, 5 deletions
diff --git a/src/widgets/widgets/qtextedit.cpp b/src/widgets/widgets/qtextedit.cpp index 920133d493..4a06f58b4a 100644 --- a/src/widgets/widgets/qtextedit.cpp +++ b/src/widgets/widgets/qtextedit.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2019 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtWidgets module of the Qt Toolkit. @@ -1202,6 +1202,13 @@ QString QTextEdit::toHtml() const } #endif +#if QT_CONFIG(textmarkdownreader) +void QTextEdit::setMarkdown(const QString &text) +{ + Q_D(const QTextEdit); + d->control->setMarkdown(text); +} +#endif /*! \reimp */ diff --git a/src/widgets/widgets/qtextedit.h b/src/widgets/widgets/qtextedit.h index 3aa23aaace..f20bd936c4 100644 --- a/src/widgets/widgets/qtextedit.h +++ b/src/widgets/widgets/qtextedit.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2019 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtWidgets module of the Qt Toolkit. @@ -238,6 +238,9 @@ public Q_SLOTS: #ifndef QT_NO_TEXTHTMLPARSER void setHtml(const QString &text); #endif +#if QT_CONFIG(textmarkdownreader) + void setMarkdown(const QString &text); +#endif void setText(const QString &text); #ifndef QT_NO_CLIPBOARD diff --git a/src/widgets/widgets/qwidgettextcontrol.cpp b/src/widgets/widgets/qwidgettextcontrol.cpp index 711c4bfd2a..5744d43cbf 100644 --- a/src/widgets/widgets/qwidgettextcontrol.cpp +++ b/src/widgets/widgets/qwidgettextcontrol.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2019 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtWidgets module of the Qt Toolkit. @@ -491,6 +491,11 @@ void QWidgetTextControlPrivate::setContent(Qt::TextFormat format, const QString formatCursor.select(QTextCursor::Document); formatCursor.setCharFormat(charFormatForInsertion); formatCursor.endEditBlock(); +#if QT_CONFIG(textmarkdownreader) + } else if (format == Qt::MarkdownText) { + doc->setMarkdown(text); + doc->setUndoRedoEnabled(false); +#endif } else { #ifndef QT_NO_TEXTHTMLPARSER doc->setHtml(text); @@ -1194,6 +1199,14 @@ void QWidgetTextControl::setPlainText(const QString &text) d->setContent(Qt::PlainText, text); } +#if QT_CONFIG(textmarkdownreader) +void QWidgetTextControl::setMarkdown(const QString &text) +{ + Q_D(QWidgetTextControl); + d->setContent(Qt::MarkdownText, text); +} +#endif + void QWidgetTextControl::setHtml(const QString &text) { Q_D(QWidgetTextControl); diff --git a/src/widgets/widgets/qwidgettextcontrol_p.h b/src/widgets/widgets/qwidgettextcontrol_p.h index 9c80d53728..4c9e47dfc9 100644 --- a/src/widgets/widgets/qwidgettextcontrol_p.h +++ b/src/widgets/widgets/qwidgettextcontrol_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2019 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtWidgets module of the Qt Toolkit. @@ -194,6 +194,9 @@ public: public Q_SLOTS: void setPlainText(const QString &text); +#if QT_CONFIG(textmarkdownreader) + void setMarkdown(const QString &text); +#endif void setHtml(const QString &text); #ifndef QT_NO_CLIPBOARD diff --git a/src/widgets/widgets/qwidgettextcontrol_p_p.h b/src/widgets/widgets/qwidgettextcontrol_p_p.h index 6a1ee564cd..6ccdfafe2b 100644 --- a/src/widgets/widgets/qwidgettextcontrol_p_p.h +++ b/src/widgets/widgets/qwidgettextcontrol_p_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2019 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtWidgets module of the Qt Toolkit. |