Add QTextDocumentFragment::toRawText()
Like QTextDocument::toRawText(), QTextDocumentFragment::toRawText() does allow access to the raw string without normalizing nbsp, line separator, paragraph separator unicode characters. [ChangeLog][QtGui][Text] Added QTextDocumentFragment::toRawText() function. Task-number: QTBUG-99572 Change-Id: Ia74150a3870ea0e6326fdcda4d9d0410019124ae Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
This commit is contained in:
parent
f19ce3898e
commit
93c1f481ab
@ -266,12 +266,11 @@ void QTextDocumentFragmentPrivate::insert(QTextCursor &_cursor) const
|
|||||||
document fragment. Document fragments can also be created by the
|
document fragment. Document fragments can also be created by the
|
||||||
static functions, fromPlainText() and fromHtml().
|
static functions, fromPlainText() and fromHtml().
|
||||||
|
|
||||||
The contents of a document fragment can be obtained as plain text
|
The contents of a document fragment can be obtained as raw text
|
||||||
by using the toPlainText() function, or it can be obtained as HTML
|
by using the toRawText() function, or it can be obtained as HTML
|
||||||
with toHtml().
|
with toHtml().
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Constructs an empty QTextDocumentFragment.
|
Constructs an empty QTextDocumentFragment.
|
||||||
|
|
||||||
@ -358,10 +357,16 @@ bool QTextDocumentFragment::isEmpty() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Returns the document fragment's text as plain text (i.e. with no
|
This function returns the same as toRawText(), but will replace
|
||||||
formatting information).
|
some unicode characters with ASCII alternatives.
|
||||||
|
In particular, no-break space (U+00A0) is replaced by a regular
|
||||||
|
space (U+0020), and both paragraph (U+2029) and line (U+2028)
|
||||||
|
separators are replaced by line feed (U+000A).
|
||||||
|
If you need the precise contents of the document, use toRawText()
|
||||||
|
instead.
|
||||||
|
|
||||||
\sa toHtml()
|
|
||||||
|
\sa toHtml(), toRawText()
|
||||||
*/
|
*/
|
||||||
QString QTextDocumentFragment::toPlainText() const
|
QString QTextDocumentFragment::toPlainText() const
|
||||||
{
|
{
|
||||||
@ -371,6 +376,21 @@ QString QTextDocumentFragment::toPlainText() const
|
|||||||
return d->doc->toPlainText();
|
return d->doc->toPlainText();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Returns the document fragment's text as raw text (i.e. with no
|
||||||
|
formatting information).
|
||||||
|
|
||||||
|
\since 6.4
|
||||||
|
\sa toHtml(), toPlainText()
|
||||||
|
*/
|
||||||
|
QString QTextDocumentFragment::toRawText() const
|
||||||
|
{
|
||||||
|
if (!d)
|
||||||
|
return QString();
|
||||||
|
|
||||||
|
return d->doc->toRawText();
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef QT_NO_TEXTHTMLPARSER
|
#ifndef QT_NO_TEXTHTMLPARSER
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -64,6 +64,7 @@ public:
|
|||||||
bool isEmpty() const;
|
bool isEmpty() const;
|
||||||
|
|
||||||
QString toPlainText() const;
|
QString toPlainText() const;
|
||||||
|
QString toRawText() const;
|
||||||
#ifndef QT_NO_TEXTHTMLPARSER
|
#ifndef QT_NO_TEXTHTMLPARSER
|
||||||
QString toHtml() const;
|
QString toHtml() const;
|
||||||
#endif // QT_NO_TEXTHTMLPARSER
|
#endif // QT_NO_TEXTHTMLPARSER
|
||||||
|
@ -100,6 +100,7 @@ private slots:
|
|||||||
void inheritAlignment();
|
void inheritAlignment();
|
||||||
void dontEmitEmptyNodeWhenEmptyTagIsFollowedByCloseTag();
|
void dontEmitEmptyNodeWhenEmptyTagIsFollowedByCloseTag();
|
||||||
void toPlainText();
|
void toPlainText();
|
||||||
|
void toRawText();
|
||||||
void copyTableRow();
|
void copyTableRow();
|
||||||
void copyTableColumn();
|
void copyTableColumn();
|
||||||
void copySubTable();
|
void copySubTable();
|
||||||
@ -1094,6 +1095,14 @@ void tst_QTextDocumentFragment::toPlainText()
|
|||||||
QCOMPARE(doc->blockCount(), 3);
|
QCOMPARE(doc->blockCount(), 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_QTextDocumentFragment::toRawText()
|
||||||
|
{
|
||||||
|
// Make sure nbsp, line separator, paragraph separator is preserved
|
||||||
|
doc->setPlainText("Hello\u0A00\u2028\u2029World");
|
||||||
|
|
||||||
|
QCOMPARE(QTextDocumentFragment(doc).toRawText(), "Hello\u0A00\u2028\u2029World");
|
||||||
|
}
|
||||||
|
|
||||||
void tst_QTextDocumentFragment::copyTableRow()
|
void tst_QTextDocumentFragment::copyTableRow()
|
||||||
{
|
{
|
||||||
QTextDocumentFragment frag;
|
QTextDocumentFragment frag;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user