aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/items/qquicktextedit_p_p.h
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2024-01-11 22:57:58 -0700
committerShawn Rutledge <shawn.rutledge@qt.io>2024-02-21 23:20:22 -0700
commitfdbacf2d5c0a04925bcb3aecd7bf47da5fb69227 (patch)
treeb1ac6e3cde912ae99890119ba147873aba457a51 /src/quick/items/qquicktextedit_p_p.h
parent5a762ba09cdeb8df5cf54ce562bc60dfcc11c97f (diff)
Respect TextEdit.textFormat in TextDocument load(); detect format
Don't load rich text if TextEdit.textFormat is PlainText. Thus it should be possible to have two independent TextEdit instances with independent document instances, viewing the same source file: the raw syntax and the rich/WYSIWYG formatting visible at the same time. Also, after the QQuickTextDocument's QTextDocument has already loaded the declared source, don't let QQuickTextEdit::componentComplete() replace it with empty text from the (unbound) TextEdit.text property. That was happening only if textFormat was RichText or MarkdownText. In case the user transitions TextEdit.textFormat from AutoText to any other, the text property now holds the format that was loaded from TextDocument.source; QQuickTextDocumentPrivate remembers the format rather than the mime type (because QMimeType is an optional feature in Qt); and TextEdit functions such as getFormattedText(), insert() and append() behave as if the textFormat property had been appropriate for the loaded file type in the first place. We cannot algorithmically detect markdown text by looking at the text itself; but now, QQuickTextDocumentPrivate::load() can populate markdown or html text into the document by detecting the file's mime type, even if the textFormat is AutoText. After that, if the user changes the textFormat to PlainText, we assume that they want to see the raw markdown or HTML. Amends b46d6a75ac16089de1a29c773e7594a82ffea13e : it already seemed odd at the time that it was OK for QQuickTextDocumentPrivate::load() to load any text format, without first changing TextEdit.textFormat to match what's expected. The default is PlainText, so it didn't make sense to read e.g. a markdown file and have the result look like WYSIWYG rich text. Now you have to change textFormat to MarkdownText or AutoText beforehand if you want to see WYSIWYG; and tst_qquicktextdocument::sourceAndSave() needs to do that too. On the other hand, if you switch textFormat to PlainText, we convert the QTextDocument to plain text, using Qt-generated markup/markdown syntax. Maybe the user would prefer to have the original syntax as read from the file; but so far it has always been this way: we just parse it, we don't store it. We are quite incapable of incrementally modifying the original syntax anyway: we can only regenerate it wholesale. So it makes sense that the text property holds Qt-generated syntax after the parsing is done. Pick-to: 6.7 Fixes: QTBUG-120772 Change-Id: I7db533c714e14bb4eb36745996c732e5162fb9cf Reviewed-by: Oliver Eftevaag <oliver.eftevaag@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src/quick/items/qquicktextedit_p_p.h')
-rw-r--r--src/quick/items/qquicktextedit_p_p.h1
1 files changed, 1 insertions, 0 deletions
diff --git a/src/quick/items/qquicktextedit_p_p.h b/src/quick/items/qquicktextedit_p_p.h
index e0ffa97119..49c85b431e 100644
--- a/src/quick/items/qquicktextedit_p_p.h
+++ b/src/quick/items/qquicktextedit_p_p.h
@@ -113,6 +113,7 @@ public:
void resetInputMethod();
void updateDefaultTextOption();
+ void onDocumentStatusChanged();
void relayoutDocument();
bool determineHorizontalAlignment();
bool setHAlign(QQuickTextEdit::HAlignment, bool forceAlign = false);