From ae6681673eb5c7768070cad61f483d2a5405dc9e Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Fri, 14 Oct 2016 15:54:13 +0200 Subject: Add QTextDocument::toRawText() function The QTextDocument::toPlainText() converts some characters in the text to ASCII, which can be problematic for use cases where you want to save the precise contents of the document, e.g. in Qt Creator. Since we don't want to change the behavior of toPlainText(), we introduce a new function which returns the raw text contents of the document instead, with no modifications. [ChangeLog][QtGui][Text] Added QTextDocument::toRawText() function. Task-number: QTBUG-56538 Change-Id: Ib6c48a16551c4c71c4c431760f993793d1af6806 Reviewed-by: Lars Knoll --- tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tests/auto/gui/text/qtextdocument') diff --git a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp index de5b2a8676..ef1ad76161 100644 --- a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp +++ b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp @@ -135,6 +135,7 @@ private slots: void setPlainText(); void toPlainText(); + void toRawText(); void deleteTextObjectsOnClear(); @@ -2396,6 +2397,16 @@ void tst_QTextDocument::toPlainText() QCOMPARE(doc->toPlainText(), QLatin1String("Hello World")); } +void tst_QTextDocument::toRawText() +{ + doc->setHtml(" "); + + QString rawText = doc->toRawText(); + QCOMPARE(rawText.size(), 1); + QCOMPARE(rawText.at(0).unicode(), ushort(QChar::Nbsp)); +} + + void tst_QTextDocument::deleteTextObjectsOnClear() { QPointer table = cursor.insertTable(2, 2); -- cgit v1.2.3