summaryrefslogtreecommitdiffstats
path: root/src/gui/text/qtextdocumentfragment.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/text/qtextdocumentfragment.cpp')
-rw-r--r--src/gui/text/qtextdocumentfragment.cpp40
1 files changed, 20 insertions, 20 deletions
diff --git a/src/gui/text/qtextdocumentfragment.cpp b/src/gui/text/qtextdocumentfragment.cpp
index 0bfcc976f1..1b6e76c201 100644
--- a/src/gui/text/qtextdocumentfragment.cpp
+++ b/src/gui/text/qtextdocumentfragment.cpp
@@ -84,7 +84,7 @@ int QTextCopyHelper::appendFragment(int pos, int endPos, int objectIndex)
}
QString txtToInsert(originalText.constData() + frag->stringPosition + inFragmentOffset, charsToCopy);
- if (txtToInsert.length() == 1
+ if (txtToInsert.size() == 1
&& (txtToInsert.at(0) == QChar::ParagraphSeparator
|| txtToInsert.at(0) == QTextBeginningOfFrame
|| txtToInsert.at(0) == QTextEndOfFrame
@@ -109,7 +109,7 @@ int QTextCopyHelper::appendFragment(int pos, int endPos, int objectIndex)
const int userState = nextBlock.userState();
if (userState != -1)
dst->blocksFind(insertPos).setUserState(userState);
- insertPos += txtToInsert.length();
+ insertPos += txtToInsert.size();
}
return charsToCopy;
@@ -239,8 +239,8 @@ void QTextDocumentFragmentPrivate::insert(QTextCursor &_cursor) const
static functions, fromPlainText() and fromHtml().
The contents of a document fragment can be obtained as raw text
- by using the toRawText() function, or it can be obtained as HTML
- with toHtml().
+ by using the toRawText() function, as ASCII with toPlainText(),
+ as HTML with toHtml(), or as Markdown with toMarkdown().
*/
/*!
@@ -337,8 +337,7 @@ bool QTextDocumentFragment::isEmpty() const
If you need the precise contents of the document, use toRawText()
instead.
-
- \sa toHtml(), toRawText()
+ \sa toHtml(), toMarkdown(), toRawText()
*/
QString QTextDocumentFragment::toPlainText() const
{
@@ -353,7 +352,7 @@ QString QTextDocumentFragment::toPlainText() const
formatting information).
\since 6.4
- \sa toHtml(), toPlainText()
+ \sa toHtml(), toMarkdown(), toPlainText()
*/
QString QTextDocumentFragment::toRawText() const
{
@@ -370,7 +369,7 @@ QString QTextDocumentFragment::toRawText() const
Returns the contents of the document fragment as HTML.
- \sa toPlainText(), QTextDocument::toHtml()
+ \sa toPlainText(), toMarkdown(), QTextDocument::toHtml()
*/
QString QTextDocumentFragment::toHtml() const
{
@@ -489,7 +488,8 @@ void QTextHtmlImporter::import()
* means there was a tag closing in the input html
*/
if (currentNodeIdx > 0 && (currentNode->parent != currentNodeIdx - 1)) {
- blockTagClosed = closeTag();
+ const bool lastBlockTagClosed = closeTag();
+ blockTagClosed = blockTagClosed || lastBlockTagClosed;
// visually collapse subsequent block tags, but if the element after the closed block tag
// is for example an inline element (!isBlock) we have to make sure we start a new paragraph by setting
// hasBlock to false.
@@ -541,6 +541,7 @@ void QTextHtmlImporter::import()
appendBlock(block, currentNode->charFormat);
+ blockTagClosed = false;
hasBlock = true;
}
@@ -576,14 +577,12 @@ bool QTextHtmlImporter::appendNodeText()
if (wsm == QTextHtmlParserNode::WhiteSpacePre || wsm == QTextHtmlParserNode::WhiteSpacePreWrap)
compressNextWhitespace = PreserveWhiteSpace;
- QString text = currentNode->text;
+ const QString text = currentNode->text;
QString textToInsert;
textToInsert.reserve(text.size());
- for (int i = 0; i < text.length(); ++i) {
- QChar ch = text.at(i);
-
+ for (QChar ch : text) {
if (ch.isSpace()
&& ch != QChar::Nbsp
&& ch != QChar::ParagraphSeparator) {
@@ -622,7 +621,7 @@ bool QTextHtmlImporter::appendNodeText()
|| ch == QChar::ParagraphSeparator) {
if (!textToInsert.isEmpty()) {
- if (wsm == QTextHtmlParserNode::WhiteSpacePreLine && textToInsert.at(textToInsert.length() - 1) == u' ')
+ if (wsm == QTextHtmlParserNode::WhiteSpacePreLine && textToInsert.at(textToInsert.size() - 1) == u' ')
textToInsert = textToInsert.chopped(1);
cursor.insertText(textToInsert, format);
textToInsert.clear();
@@ -700,6 +699,8 @@ QTextHtmlImporter::ProcessNodeResult QTextHtmlImporter::processSpecialNodes()
listFmt.setNumberPrefix(currentNode->textListNumberPrefix);
if (!currentNode->textListNumberSuffix.isNull())
listFmt.setNumberSuffix(currentNode->textListNumberSuffix);
+ if (currentNode->listStart != 1)
+ listFmt.setStart(currentNode->listStart);
++indent;
if (currentNode->hasCssListIndent)
@@ -907,7 +908,7 @@ QTextHtmlImporter::Table QTextHtmlImporter::scanTable(int tableNodeIdx)
int tableHeaderRowCount = 0;
QList<int> rowNodes;
- rowNodes.reserve(at(tableNodeIdx).children.count());
+ rowNodes.reserve(at(tableNodeIdx).children.size());
for (int row : at(tableNodeIdx).children) {
switch (at(row).id) {
case Html_tr:
@@ -932,7 +933,7 @@ QTextHtmlImporter::Table QTextHtmlImporter::scanTable(int tableNodeIdx)
QList<RowColSpanInfo> rowColSpanForColumn;
int effectiveRow = 0;
- for (int row : qAsConst(rowNodes)) {
+ for (int row : std::as_const(rowNodes)) {
int colsInRow = 0;
for (int cell : at(row).children) {
@@ -960,7 +961,7 @@ QTextHtmlImporter::Table QTextHtmlImporter::scanTable(int tableNodeIdx)
if (spanInfo.colSpan > 1 || spanInfo.rowSpan > 1)
rowColSpans.append(spanInfo);
- columnWidths.resize(qMax(columnWidths.count(), colsInRow));
+ columnWidths.resize(qMax(columnWidths.size(), colsInRow));
rowColSpanForColumn.resize(columnWidths.size());
for (int i = currentColumn; i < currentColumn + c.tableCellColSpan; ++i) {
if (columnWidths.at(i).type() == QTextLength::VariableLength) {
@@ -1042,7 +1043,7 @@ QTextHtmlImporter::Table QTextHtmlImporter::scanTable(int tableNodeIdx)
QTextTable *textTable = cursor.insertTable(table.rows, table.columns, fmt.toTableFormat());
table.frame = textTable;
- for (int i = 0; i < rowColSpans.count(); ++i) {
+ for (int i = 0; i < rowColSpans.size(); ++i) {
const RowColSpanInfo &nfo = rowColSpans.at(i);
textTable->mergeCells(nfo.row, nfo.col, nfo.rowSpan, nfo.colSpan);
}
@@ -1312,8 +1313,7 @@ QTextDocumentFragment QTextDocumentFragment::fromMarkdown(const QString &markdow
QTextDocumentFragment res;
res.d = new QTextDocumentFragmentPrivate;
- QTextMarkdownImporter importer(features);
- importer.import(res.d->doc, markdown);
+ QTextMarkdownImporter(res.d->doc, features).import(markdown);
return res;
}