OpenCoverage

qtextdocumentfragment.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/gui/text/qtextdocumentfragment.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5QTextCopyHelper::QTextCopyHelper(const QTextCursor &_source, const QTextCursor &_destination, bool forceCharFormat, const QTextCharFormat &fmt)-
6-
7-
8-
9 : formatCollection(*_destination.d->priv->formatCollection()), originalText(_source.d->priv->buffer())-
10-
11{-
12 src = _source.d->priv;-
13 dst = _destination.d->priv;-
14 insertPos = _destination.position();-
15 this->forceCharFormat = forceCharFormat;-
16 primaryCharFormatIndex = convertFormatIndex(fmt);-
17 cursor = _source;-
18}
never executed: end of block
0
19-
20int QTextCopyHelper::convertFormatIndex(const QTextFormat &oldFormat, int objectIndexToSet)-
21{-
22 QTextFormat fmt = oldFormat;-
23 if (objectIndexToSet != -1
objectIndexToSet != -1Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
24 fmt.setObjectIndex(objectIndexToSet);-
25 }
never executed: end of block
else if (fmt.objectIndex() != -1
fmt.objectIndex() != -1Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
26 int newObjectIndex = objectIndexMap.value(fmt.objectIndex(), -1);-
27 if (newObjectIndex == -1
newObjectIndex == -1Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
28 QTextFormat objFormat = src->formatCollection()->objectFormat(fmt.objectIndex());-
29 ((!(objFormat.objectIndex() == -1)) ? qt_assert("objFormat.objectIndex() == -1",__FILE__,77) : qt_noop());-
30 newObjectIndex = formatCollection.createObjectIndex(objFormat);-
31 objectIndexMap.insert(fmt.objectIndex(), newObjectIndex);-
32 }
never executed: end of block
0
33 fmt.setObjectIndex(newObjectIndex);-
34 }
never executed: end of block
0
35 int idx = formatCollection.indexForFormat(fmt);-
36 ((!(formatCollection.format(idx).type() == oldFormat.type())) ? qt_assert("formatCollection.format(idx).type() == oldFormat.type()",__FILE__,84) : qt_noop());-
37 return
never executed: return idx;
idx;
never executed: return idx;
0
38}-
39-
40int QTextCopyHelper::appendFragment(int pos, int endPos, int objectIndex)-
41{-
42 QTextDocumentPrivate::FragmentIterator fragIt = src->find(pos);-
43 const QTextFragmentData * const frag = fragIt.value();-
44-
45 ((!(objectIndex == -1 || (frag->size_array[0] == 1 && src->formatCollection()->format(frag->format).objectIndex() != -1))) ? qt_assert("objectIndex == -1 || (frag->size_array[0] == 1 && src->formatCollection()->format(frag->format).objectIndex() != -1)",-
46 __FILE__-
47 ,-
48 94-
49 ) : qt_noop())-
50 ;-
51-
52 int charFormatIndex;-
53 if (forceCharFormat
forceCharFormatDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
54 charFormatIndex = primaryCharFormatIndex;
never executed: charFormatIndex = primaryCharFormatIndex;
0
55 else-
56 charFormatIndex = convertFormatIndex(frag->format, objectIndex);
never executed: charFormatIndex = convertFormatIndex(frag->format, objectIndex);
0
57-
58 const int inFragmentOffset = qMax(0, pos - fragIt.position());-
59 int charsToCopy = qMin(int(frag->size_array[0] - inFragmentOffset), endPos - pos);-
60-
61 QTextBlock nextBlock = src->blocksFind(pos + 1);-
62-
63 int blockIdx = -2;-
64 if (nextBlock.position() == pos + 1
nextBlock.posi...n() == pos + 1Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
65 blockIdx = convertFormatIndex(nextBlock.blockFormat());-
66 }
never executed: end of block
else if (pos == 0
pos == 0Description
TRUEnever evaluated
FALSEnever evaluated
&& insertPos == 0
insertPos == 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
67 dst->setBlockFormat(dst->blocksBegin(), dst->blocksBegin(), convertFormat(src->blocksBegin().blockFormat()).toBlockFormat());-
68 dst->setCharFormat(-1, 1, convertFormat(src->blocksBegin().charFormat()).toCharFormat());-
69 }
never executed: end of block
0
70-
71 QString txtToInsert(originalText.constData() + frag->stringPosition + inFragmentOffset, charsToCopy);-
72 if (txtToInsert.length() == 1
txtToInsert.length() == 1Description
TRUEnever evaluated
FALSEnever evaluated
0
73 && (txtToInsert.at(0) == QChar::ParagraphSeparator
txtToInsert.at...graphSeparatorDescription
TRUEnever evaluated
FALSEnever evaluated
0
74 || txtToInsert.at(0) == QChar(0xfdd0)
txtToInsert.at... QChar(0xfdd0)Description
TRUEnever evaluated
FALSEnever evaluated
0
75 || txtToInsert.at(0) == QChar(0xfdd1)
txtToInsert.at... QChar(0xfdd1)Description
TRUEnever evaluated
FALSEnever evaluated
0
76 )-
77 ) {-
78 dst->insertBlock(txtToInsert.at(0), insertPos, blockIdx, charFormatIndex);-
79 ++insertPos;-
80 }
never executed: end of block
else {
0
81 if (nextBlock.textList()
nextBlock.textList()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
82 QTextBlock dstBlock = dst->blocksFind(insertPos);-
83 if (!dstBlock.textList()
!dstBlock.textList()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
84-
85-
86-
87 int listBlockFormatIndex = convertFormatIndex(nextBlock.blockFormat());-
88 int listCharFormatIndex = convertFormatIndex(nextBlock.charFormat());-
89 dst->insertBlock(insertPos, listBlockFormatIndex, listCharFormatIndex);-
90 ++insertPos;-
91 }
never executed: end of block
0
92 }
never executed: end of block
0
93 dst->insert(insertPos, txtToInsert, charFormatIndex);-
94 const int userState = nextBlock.userState();-
95 if (userState != -1
userState != -1Description
TRUEnever evaluated
FALSEnever evaluated
)
0
96 dst->blocksFind(insertPos).setUserState(userState);
never executed: dst->blocksFind(insertPos).setUserState(userState);
0
97 insertPos += txtToInsert.length();-
98 }
never executed: end of block
0
99-
100 return
never executed: return charsToCopy;
charsToCopy;
never executed: return charsToCopy;
0
101}-
102-
103void QTextCopyHelper::appendFragments(int pos, int endPos)-
104{-
105 ((!(pos < endPos)) ? qt_assert("pos < endPos",__FILE__,149) : qt_noop());-
106-
107 while (pos < endPos
pos < endPosDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
108 pos += appendFragment(pos, endPos);
never executed: pos += appendFragment(pos, endPos);
0
109}
never executed: end of block
0
110-
111void QTextCopyHelper::copy()-
112{-
113 if (cursor.hasComplexSelection()
cursor.hasComplexSelection()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
114 QTextTable *table = cursor.currentTable();-
115 int row_start, col_start, num_rows, num_cols;-
116 cursor.selectedTableCells(&row_start, &num_rows, &col_start, &num_cols);-
117-
118 QTextTableFormat tableFormat = table->format();-
119 tableFormat.setColumns(num_cols);-
120 tableFormat.clearColumnWidthConstraints();-
121 const int objectIndex = dst->formatCollection()->createObjectIndex(tableFormat);-
122-
123 ((!(row_start != -1)) ? qt_assert("row_start != -1",__FILE__,167) : qt_noop());-
124 for (int r = row_start; r < row_start + num_rows
r < row_start + num_rowsDescription
TRUEnever evaluated
FALSEnever evaluated
; ++r) {
0
125 for (int c = col_start; c < col_start + num_cols
c < col_start + num_colsDescription
TRUEnever evaluated
FALSEnever evaluated
; ++c) {
0
126 QTextTableCell cell = table->cellAt(r, c);-
127 const int rspan = cell.rowSpan();-
128 const int cspan = cell.columnSpan();-
129 if (rspan != 1
rspan != 1Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
130 int cr = cell.row();-
131 if (cr != r
cr != rDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
132 continue;
never executed: continue;
0
133 }
never executed: end of block
0
134 if (cspan != 1
cspan != 1Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
135 int cc = cell.column();-
136 if (cc != c
cc != cDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
137 continue;
never executed: continue;
0
138 }
never executed: end of block
0
139-
140-
141 QTextCharFormat cellFormat = cell.format();-
142 if (r + rspan >= row_start + num_rows
r + rspan >= r...art + num_rowsDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
143 cellFormat.setTableCellRowSpan(row_start + num_rows - r);-
144 }
never executed: end of block
0
145 if (c + cspan >= col_start + num_cols
c + cspan >= c...art + num_colsDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
146 cellFormat.setTableCellColumnSpan(col_start + num_cols - c);-
147 }
never executed: end of block
0
148 const int charFormatIndex = convertFormatIndex(cellFormat, objectIndex);-
149-
150 int blockIdx = -2;-
151 const int cellPos = cell.firstPosition();-
152 QTextBlock block = src->blocksFind(cellPos);-
153 if (block.position() == cellPos
block.position() == cellPosDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
154 blockIdx = convertFormatIndex(block.blockFormat());-
155 }
never executed: end of block
0
156-
157 dst->insertBlock(QChar(0xfdd0), insertPos, blockIdx, charFormatIndex);-
158 ++insertPos;-
159-
160-
161 if (cell.lastPosition() > cellPos
cell.lastPosition() > cellPosDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
162-
163 appendFragments(cellPos, cell.lastPosition());-
164 }
never executed: end of block
0
165 }
never executed: end of block
0
166 }
never executed: end of block
0
167-
168-
169 int end = table->lastPosition();-
170 appendFragment(end, end+1, objectIndex);-
171 }
never executed: end of block
else {
0
172 appendFragments(cursor.selectionStart(), cursor.selectionEnd());-
173 }
never executed: end of block
0
174}-
175-
176QTextDocumentFragmentPrivate::QTextDocumentFragmentPrivate(const QTextCursor &_cursor)-
177 : ref(1), doc(new QTextDocument), importedFromPlainText(false)-
178{-
179 doc->setUndoRedoEnabled(false);-
180-
181 if (!_cursor.hasSelection()
!_cursor.hasSelection()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
182 return;
never executed: return;
0
183-
184 doc->docHandle()->beginEditBlock();-
185 QTextCursor destCursor(doc);-
186 QTextCopyHelper(_cursor, destCursor).copy();-
187 doc->docHandle()->endEditBlock();-
188-
189 if (_cursor.d
_cursor.dDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
190 doc->docHandle()->mergeCachedResources(_cursor.d->priv);
never executed: doc->docHandle()->mergeCachedResources(_cursor.d->priv);
0
191}
never executed: end of block
0
192-
193void QTextDocumentFragmentPrivate::insert(QTextCursor &_cursor) const-
194{-
195 if (_cursor.isNull()
_cursor.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
196 return;
never executed: return;
0
197-
198 QTextDocumentPrivate *destPieceTable = _cursor.d->priv;-
199 destPieceTable->beginEditBlock();-
200-
201 QTextCursor sourceCursor(doc);-
202 sourceCursor.movePosition(QTextCursor::End, QTextCursor::KeepAnchor);-
203 QTextCopyHelper(sourceCursor, _cursor, importedFromPlainText, _cursor.charFormat()).copy();-
204-
205 destPieceTable->endEditBlock();-
206}
never executed: end of block
0
207QTextDocumentFragment::QTextDocumentFragment()-
208 : d(0)-
209{-
210}
never executed: end of block
0
211-
212-
213-
214-
215-
216-
217QTextDocumentFragment::QTextDocumentFragment(const QTextDocument *document)-
218 : d(0)-
219{-
220 if (!document
!documentDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
221 return;
never executed: return;
0
222-
223 QTextCursor cursor(const_cast<QTextDocument *>(document));-
224 cursor.movePosition(QTextCursor::End, QTextCursor::KeepAnchor);-
225 d = new QTextDocumentFragmentPrivate(cursor);-
226}
never executed: end of block
0
227-
228-
229-
230-
231-
232-
233-
234QTextDocumentFragment::QTextDocumentFragment(const QTextCursor &cursor)-
235 : d(0)-
236{-
237 if (!cursor.hasSelection()
!cursor.hasSelection()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
238 return;
never executed: return;
0
239-
240 d = new QTextDocumentFragmentPrivate(cursor);-
241}
never executed: end of block
0
242-
243-
244-
245-
246-
247-
248QTextDocumentFragment::QTextDocumentFragment(const QTextDocumentFragment &rhs)-
249 : d(rhs.d)-
250{-
251 if (d
dDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
252 d->ref.ref();
never executed: d->ref.ref();
0
253}
never executed: end of block
0
254-
255-
256-
257-
258-
259-
260QTextDocumentFragment &QTextDocumentFragment::operator=(const QTextDocumentFragment &rhs)-
261{-
262 if (rhs.d
rhs.dDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
263 rhs.d->ref.ref();
never executed: rhs.d->ref.ref();
0
264 if (d
dDescription
TRUEnever evaluated
FALSEnever evaluated
&& !d->ref.deref()
!d->ref.deref()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
265 delete d;
never executed: delete d;
0
266 d = rhs.d;-
267 return
never executed: return *this;
*this;
never executed: return *this;
0
268}-
269-
270-
271-
272-
273QTextDocumentFragment::~QTextDocumentFragment()-
274{-
275 if (d
dDescription
TRUEnever evaluated
FALSEnever evaluated
&& !d->ref.deref()
!d->ref.deref()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
276 delete d;
never executed: delete d;
0
277}
never executed: end of block
0
278-
279-
280-
281-
282bool QTextDocumentFragment::isEmpty() const-
283{-
284 return
never executed: return !d || !d->doc || d->doc->docHandle()->length() <= 1;
!d || !d->doc || d->doc->docHandle()->length() <= 1;
never executed: return !d || !d->doc || d->doc->docHandle()->length() <= 1;
0
285}-
286-
287-
288-
289-
290-
291-
292-
293QString QTextDocumentFragment::toPlainText() const-
294{-
295 if (!d
!dDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
296 return
never executed: return QString();
QString();
never executed: return QString();
0
297-
298 return
never executed: return d->doc->toPlainText();
d->doc->toPlainText();
never executed: return d->doc->toPlainText();
0
299}-
300QString QTextDocumentFragment::toHtml(const QByteArray &encoding) const-
301{-
302 if (!d
!dDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
303 return
never executed: return QString();
QString();
never executed: return QString();
0
304-
305 return
never executed: return QTextHtmlExporter(d->doc).toHtml(encoding, QTextHtmlExporter::ExportFragment);
QTextHtmlExporter(d->doc).toHtml(encoding, QTextHtmlExporter::ExportFragment);
never executed: return QTextHtmlExporter(d->doc).toHtml(encoding, QTextHtmlExporter::ExportFragment);
0
306}-
307QTextDocumentFragment QTextDocumentFragment::fromPlainText(const QString &plainText)-
308{-
309 QTextDocumentFragment res;-
310-
311 res.d = new QTextDocumentFragmentPrivate;-
312 res.d->importedFromPlainText = true;-
313 QTextCursor cursor(res.d->doc);-
314 cursor.insertText(plainText);-
315 return
never executed: return res;
res;
never executed: return res;
0
316}-
317-
318static QTextListFormat::Style nextListStyle(QTextListFormat::Style style)-
319{-
320 if (style == QTextListFormat::ListDisc
style == QText...rmat::ListDiscDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
321 return
never executed: return QTextListFormat::ListCircle;
QTextListFormat::ListCircle;
never executed: return QTextListFormat::ListCircle;
0
322 else if (style == QTextListFormat::ListCircle
style == QText...at::ListCircleDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
323 return
never executed: return QTextListFormat::ListSquare;
QTextListFormat::ListSquare;
never executed: return QTextListFormat::ListSquare;
0
324 return
never executed: return style;
style;
never executed: return style;
0
325}-
326-
327-
328-
329QTextHtmlImporter::QTextHtmlImporter(QTextDocument *_doc, const QString &_html, ImportMode mode, const QTextDocument *resourceProvider)-
330 : indent(0), compressNextWhitespace(PreserveWhiteSpace), doc(_doc), importMode(mode)-
331{-
332 cursor = QTextCursor(doc);-
333 wsm = QTextHtmlParserNode::WhiteSpaceNormal;-
334-
335 QString html = _html;-
336 const int startFragmentPos = html.indexOf(QLatin1String("<!--StartFragment-->"));-
337 if (startFragmentPos != -1
startFragmentPos != -1Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
338 const QLatin1String qt3RichTextHeader("<meta name=\"qrichtext\" content=\"1\" />");-
339-
340-
341 const bool hasQtRichtextMetaTag = html.contains(qt3RichTextHeader);-
342-
343 const int endFragmentPos = html.indexOf(QLatin1String("<!--EndFragment-->"));-
344 if (startFragmentPos < endFragmentPos
startFragmentP...endFragmentPosDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
345 html = html.mid(startFragmentPos, endFragmentPos - startFragmentPos);
never executed: html = html.mid(startFragmentPos, endFragmentPos - startFragmentPos);
0
346 else-
347 html = html.mid(startFragmentPos);
never executed: html = html.mid(startFragmentPos);
0
348-
349 if (hasQtRichtextMetaTag
hasQtRichtextMetaTagDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
350 html.prepend(qt3RichTextHeader);
never executed: html.prepend(qt3RichTextHeader);
0
351 }
never executed: end of block
0
352-
353 parse(html, resourceProvider ? resourceProvider : doc);-
354-
355}
never executed: end of block
0
356-
357void QTextHtmlImporter::import()-
358{-
359 cursor.beginEditBlock();-
360 hasBlock = true;-
361 forceBlockMerging = false;-
362 compressNextWhitespace = RemoveWhiteSpace;-
363 blockTagClosed = false;-
364 for (currentNodeIdx = 0; currentNodeIdx < count()
currentNodeIdx < count()Description
TRUEnever evaluated
FALSEnever evaluated
; ++currentNodeIdx) {
0
365 currentNode = &at(currentNodeIdx);-
366 wsm = textEditMode
textEditModeDescription
TRUEnever evaluated
FALSEnever evaluated
? QTextHtmlParserNode::WhiteSpacePreWrap : currentNode->wsm;
0
367 if (currentNodeIdx > 0
currentNodeIdx > 0Description
TRUEnever evaluated
FALSEnever evaluated
&& (
(currentNode->...ntNodeIdx - 1)Description
TRUEnever evaluated
FALSEnever evaluated
currentNode->parent != currentNodeIdx - 1)
(currentNode->...ntNodeIdx - 1)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
368 blockTagClosed = closeTag();-
369-
370-
371-
372 if (blockTagClosed
blockTagClosedDescription
TRUEnever evaluated
FALSEnever evaluated
0
373 && !currentNode->isBlock()
!currentNode->isBlock()Description
TRUEnever evaluated
FALSEnever evaluated
0
374 && currentNode->id != Html_unknown
currentNode->i...= Html_unknownDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
375 {-
376 hasBlock = false;-
377 }
never executed: end of block
else if (blockTagClosed
blockTagClosedDescription
TRUEnever evaluated
FALSEnever evaluated
&& hasBlock
hasBlockDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
378-
379 QTextBlockFormat blockFormat = currentNode->blockFormat;-
380 blockFormat.setIndent(indent);-
381-
382 QTextBlockFormat oldFormat = cursor.blockFormat();-
383 if (oldFormat.hasProperty(QTextFormat::PageBreakPolicy)
oldFormat.hasP...geBreakPolicy)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
384 QTextFormat::PageBreakFlags pageBreak = oldFormat.pageBreakPolicy();-
385 if (pageBreak == QTextFormat::PageBreak_AlwaysAfter
pageBreak == Q...ak_AlwaysAfterDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
386-
387-
388-
389-
390 pageBreak = QTextFormat::PageBreak_AlwaysBefore;
never executed: pageBreak = QTextFormat::PageBreak_AlwaysBefore;
0
391 blockFormat.setPageBreakPolicy(pageBreak);-
392 }
never executed: end of block
0
393-
394 cursor.setBlockFormat(blockFormat);-
395 }
never executed: end of block
0
396 }
never executed: end of block
0
397-
398 if (currentNode->displayMode == QTextHtmlElement::DisplayNone
currentNode->d...t::DisplayNoneDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
399 if (currentNode->id == Html_title
currentNode->id == Html_titleDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
400 doc->setMetaInformation(QTextDocument::DocumentTitle, currentNode->text);
never executed: doc->setMetaInformation(QTextDocument::DocumentTitle, currentNode->text);
0
401-
402 continue;
never executed: continue;
0
403 }-
404-
405 if (processSpecialNodes() == ContinueWithNextNode
processSpecial...ueWithNextNodeDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
406 continue;
never executed: continue;
0
407-
408-
409 if (blockTagClosed
blockTagClosedDescription
TRUEnever evaluated
FALSEnever evaluated
0
410 && !hasBlock
!hasBlockDescription
TRUEnever evaluated
FALSEnever evaluated
0
411 && !currentNode->isBlock()
!currentNode->isBlock()Description
TRUEnever evaluated
FALSEnever evaluated
0
412 && !currentNode->text.isEmpty()
!currentNode->text.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
&& !currentNode->hasOnlyWhitespace()
!currentNode->...lyWhitespace()Description
TRUEnever evaluated
FALSEnever evaluated
0
413 && currentNode->displayMode == QTextHtmlElement::DisplayInline
currentNode->d...:DisplayInlineDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
414-
415 QTextBlockFormat block = currentNode->blockFormat;-
416 block.setIndent(indent);-
417-
418 appendBlock(block, currentNode->charFormat);-
419-
420 hasBlock = true;-
421 }
never executed: end of block
0
422-
423 if (currentNode->isBlock()
currentNode->isBlock()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
424 QTextHtmlImporter::ProcessNodeResult result = processBlockNode();-
425 if (result == ContinueWithNextNode
result == ContinueWithNextNodeDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
426 continue;
never executed: continue;
0
427 } else if (result == ContinueWithNextSibling
result == Cont...ithNextSiblingDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
428 currentNodeIdx += currentNode->children.size();-
429 continue;
never executed: continue;
0
430 }-
431 }
never executed: end of block
0
432-
433 if (currentNode->charFormat.isAnchor()
currentNode->c...mat.isAnchor()Description
TRUEnever evaluated
FALSEnever evaluated
&& !currentNode->charFormat.anchorName().isEmpty()
!currentNode->...me().isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
434 namedAnchors.append(currentNode->charFormat.anchorName());-
435 }
never executed: end of block
0
436-
437 if (appendNodeText()
appendNodeText()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
438 hasBlock = false;
never executed: hasBlock = false;
0
439-
440 }
never executed: end of block
0
441-
442 cursor.endEditBlock();-
443}
never executed: end of block
0
444-
445bool QTextHtmlImporter::appendNodeText()-
446{-
447 const int initialCursorPosition = cursor.position();-
448 QTextCharFormat format = currentNode->charFormat;-
449-
450 if(wsm == QTextHtmlParserNode::WhiteSpacePre
wsm == QTextHt...:WhiteSpacePreDescription
TRUEnever evaluated
FALSEnever evaluated
|| wsm == QTextHtmlParserNode::WhiteSpacePreWrap
wsm == QTextHt...teSpacePreWrapDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
451 compressNextWhitespace = PreserveWhiteSpace;
never executed: compressNextWhitespace = PreserveWhiteSpace;
0
452-
453 QString text = currentNode->text;-
454-
455 QString textToInsert;-
456 textToInsert.reserve(text.size());-
457-
458 for (int i = 0; i < text.length()
i < text.length()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
459 QChar ch = text.at(i);-
460-
461 if (ch.isSpace()
ch.isSpace()Description
TRUEnever evaluated
FALSEnever evaluated
0
462 && ch != QChar::Nbsp
ch != QChar::NbspDescription
TRUEnever evaluated
FALSEnever evaluated
0
463 && ch != QChar::ParagraphSeparator
ch != QChar::P...graphSeparatorDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
464-
465 if (compressNextWhitespace == CollapseWhiteSpace
compressNextWh...apseWhiteSpaceDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
466 compressNextWhitespace = RemoveWhiteSpace;
never executed: compressNextWhitespace = RemoveWhiteSpace;
0
467 else if(compressNextWhitespace == RemoveWhiteSpace
compressNextWh...moveWhiteSpaceDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
468 continue;
never executed: continue;
0
469-
470 if (wsm == QTextHtmlParserNode::WhiteSpacePre
wsm == QTextHt...:WhiteSpacePreDescription
TRUEnever evaluated
FALSEnever evaluated
0
471 || textEditMode
textEditModeDescription
TRUEnever evaluated
FALSEnever evaluated
0
472 ) {-
473 if (ch == QLatin1Char('\n')
ch == QLatin1Char('\n')Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
474 if (textEditMode
textEditModeDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
475 continue;
never executed: continue;
0
476 }
never executed: end of block
else if (ch == QLatin1Char('\r')
ch == QLatin1Char('\r')Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
477 continue;
never executed: continue;
0
478 }-
479 }
never executed: end of block
else if (wsm != QTextHtmlParserNode::WhiteSpacePreWrap
wsm != QTextHt...teSpacePreWrapDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
480 compressNextWhitespace = RemoveWhiteSpace;-
481 if (wsm == QTextHtmlParserNode::WhiteSpaceNoWrap
wsm == QTextHt...iteSpaceNoWrapDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
482 ch = QChar::Nbsp;
never executed: ch = QChar::Nbsp;
0
483 else-
484 ch = QLatin1Char(' ');
never executed: ch = QLatin1Char(' ');
0
485 }-
486 }
never executed: end of block
else {
0
487 compressNextWhitespace = PreserveWhiteSpace;-
488 }
never executed: end of block
0
489-
490 if (ch == QLatin1Char('\n')
ch == QLatin1Char('\n')Description
TRUEnever evaluated
FALSEnever evaluated
0
491 || ch == QChar::ParagraphSeparator
ch == QChar::P...graphSeparatorDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
492-
493 if (!textToInsert.isEmpty()
!textToInsert.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
494 cursor.insertText(textToInsert, format);-
495 textToInsert.clear();-
496 }
never executed: end of block
0
497-
498 QTextBlockFormat fmt = cursor.blockFormat();-
499-
500 if (fmt.hasProperty(QTextFormat::BlockBottomMargin)
fmt.hasPropert...kBottomMargin)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
501 QTextBlockFormat tmp = fmt;-
502 tmp.clearProperty(QTextFormat::BlockBottomMargin);-
503 cursor.setBlockFormat(tmp);-
504 }
never executed: end of block
0
505-
506 fmt.clearProperty(QTextFormat::BlockTopMargin);-
507 appendBlock(fmt, cursor.charFormat());-
508 }
never executed: end of block
else {
0
509 if (!namedAnchors.isEmpty()
!namedAnchors.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
510 if (!textToInsert.isEmpty()
!textToInsert.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
511 cursor.insertText(textToInsert, format);-
512 textToInsert.clear();-
513 }
never executed: end of block
0
514-
515 format.setAnchor(true);-
516 format.setAnchorNames(namedAnchors);-
517 cursor.insertText(ch, format);-
518 namedAnchors.clear();-
519 format.clearProperty(QTextFormat::IsAnchor);-
520 format.clearProperty(QTextFormat::AnchorName);-
521 }
never executed: end of block
else {
0
522 textToInsert += ch;-
523 }
never executed: end of block
0
524 }-
525 }-
526-
527 if (!textToInsert.isEmpty()
!textToInsert.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
528 cursor.insertText(textToInsert, format);-
529 }
never executed: end of block
0
530-
531 return
never executed: return cursor.position() != initialCursorPosition;
cursor.position() != initialCursorPosition;
never executed: return cursor.position() != initialCursorPosition;
0
532}-
533-
534QTextHtmlImporter::ProcessNodeResult QTextHtmlImporter::processSpecialNodes()-
535{-
536 switch (currentNode->id) {-
537 case
never executed: case Html_body:
Html_body:
never executed: case Html_body:
0
538 if (currentNode->charFormat.background().style() != Qt::NoBrush
currentNode->c...!= Qt::NoBrushDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
539 QTextFrameFormat fmt = doc->rootFrame()->frameFormat();-
540 fmt.setBackground(currentNode->charFormat.background());-
541 doc->rootFrame()->setFrameFormat(fmt);-
542 const_cast<QTextHtmlParserNode *>(currentNode)->charFormat.clearProperty(QTextFormat::BackgroundBrush);-
543 }
never executed: end of block
0
544 compressNextWhitespace = RemoveWhiteSpace;-
545 break;
never executed: break;
0
546-
547 case
never executed: case Html_ol:
Html_ol:
never executed: case Html_ol:
0
548 case
never executed: case Html_ul:
Html_ul:
never executed: case Html_ul:
{
0
549 QTextListFormat::Style style = currentNode->listStyle;-
550-
551 if (currentNode->id == Html_ul
currentNode->id == Html_ulDescription
TRUEnever evaluated
FALSEnever evaluated
&& !currentNode->hasOwnListStyle
!currentNode->hasOwnListStyleDescription
TRUEnever evaluated
FALSEnever evaluated
&& currentNode->parent
currentNode->parentDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
552 const QTextHtmlParserNode *n = &at(currentNode->parent);-
553 while (n
nDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
554 if (n->id == Html_ul
n->id == Html_ulDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
555 style = nextListStyle(currentNode->listStyle);-
556 }
never executed: end of block
0
557 if (n->parent
n->parentDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
558 n = &at(n->parent);
never executed: n = &at(n->parent);
0
559 else-
560 n = 0;
never executed: n = 0;
0
561 }-
562 }
never executed: end of block
0
563-
564 QTextListFormat listFmt;-
565 listFmt.setStyle(style);-
566 if (!currentNode->textListNumberPrefix.isNull()
!currentNode->...refix.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
567 listFmt.setNumberPrefix(currentNode->textListNumberPrefix);
never executed: listFmt.setNumberPrefix(currentNode->textListNumberPrefix);
0
568 if (!currentNode->textListNumberSuffix.isNull()
!currentNode->...uffix.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
569 listFmt.setNumberSuffix(currentNode->textListNumberSuffix);
never executed: listFmt.setNumberSuffix(currentNode->textListNumberSuffix);
0
570-
571 ++indent;-
572 if (currentNode->hasCssListIndent
currentNode->hasCssListIndentDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
573 listFmt.setIndent(currentNode->cssListIndent);
never executed: listFmt.setIndent(currentNode->cssListIndent);
0
574 else-
575 listFmt.setIndent(indent);
never executed: listFmt.setIndent(indent);
0
576-
577 List l;-
578 l.format = listFmt;-
579 l.listNode = currentNodeIdx;-
580 lists.append(l);-
581 compressNextWhitespace = RemoveWhiteSpace;-
582-
583-
584 const QString simpl = currentNode->text.simplified();-
585 if (simpl.isEmpty()
simpl.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
|| simpl.at(0).isSpace()
simpl.at(0).isSpace()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
586 return
never executed: return ContinueWithNextNode;
ContinueWithNextNode;
never executed: return ContinueWithNextNode;
0
587 break;
never executed: break;
0
588 }-
589-
590 case
never executed: case Html_table:
Html_table:
never executed: case Html_table:
{
0
591 Table t = scanTable(currentNodeIdx);-
592 tables.append(t);-
593 hasBlock = false;-
594 compressNextWhitespace = RemoveWhiteSpace;-
595 return
never executed: return ContinueWithNextNode;
ContinueWithNextNode;
never executed: return ContinueWithNextNode;
0
596 }-
597-
598 case
never executed: case Html_tr:
Html_tr:
never executed: case Html_tr:
0
599 return
never executed: return ContinueWithNextNode;
ContinueWithNextNode;
never executed: return ContinueWithNextNode;
0
600-
601 case
never executed: case Html_img:
Html_img:
never executed: case Html_img:
{
0
602 QTextImageFormat fmt;-
603 fmt.setName(currentNode->imageName);-
604-
605 fmt.merge(currentNode->charFormat);-
606-
607 if (currentNode->imageWidth != -1
currentNode->imageWidth != -1Description
TRUEnever evaluated
FALSEnever evaluated
)
0
608 fmt.setWidth(currentNode->imageWidth);
never executed: fmt.setWidth(currentNode->imageWidth);
0
609 if (currentNode->imageHeight != -1
currentNode->imageHeight != -1Description
TRUEnever evaluated
FALSEnever evaluated
)
0
610 fmt.setHeight(currentNode->imageHeight);
never executed: fmt.setHeight(currentNode->imageHeight);
0
611-
612 cursor.insertImage(fmt, QTextFrameFormat::Position(currentNode->cssFloat));-
613-
614 cursor.movePosition(QTextCursor::Left, QTextCursor::KeepAnchor);-
615 cursor.mergeCharFormat(currentNode->charFormat);-
616 cursor.movePosition(QTextCursor::Right);-
617 compressNextWhitespace = CollapseWhiteSpace;-
618-
619 hasBlock = false;-
620 return
never executed: return ContinueWithNextNode;
ContinueWithNextNode;
never executed: return ContinueWithNextNode;
0
621 }-
622-
623 case
never executed: case Html_hr:
Html_hr:
never executed: case Html_hr:
{
0
624 QTextBlockFormat blockFormat = currentNode->blockFormat;-
625 blockFormat.setTopMargin(topMargin(currentNodeIdx));-
626 blockFormat.setBottomMargin(bottomMargin(currentNodeIdx));-
627 blockFormat.setProperty(QTextFormat::BlockTrailingHorizontalRulerWidth, currentNode->width);-
628 if (hasBlock
hasBlockDescription
TRUEnever evaluated
FALSEnever evaluated
&& importMode == ImportToDocument
importMode == ImportToDocumentDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
629 cursor.mergeBlockFormat(blockFormat);
never executed: cursor.mergeBlockFormat(blockFormat);
0
630 else-
631 appendBlock(blockFormat);
never executed: appendBlock(blockFormat);
0
632 hasBlock = false;-
633 compressNextWhitespace = RemoveWhiteSpace;-
634 return
never executed: return ContinueWithNextNode;
ContinueWithNextNode;
never executed: return ContinueWithNextNode;
0
635 }-
636-
637 default
never executed: default:
:
never executed: default:
break;
never executed: break;
0
638 }-
639 return
never executed: return ContinueWithCurrentNode;
ContinueWithCurrentNode;
never executed: return ContinueWithCurrentNode;
0
640}-
641-
642-
643bool QTextHtmlImporter::closeTag()-
644{-
645 const QTextHtmlParserNode *closedNode = &at(currentNodeIdx - 1);-
646 const int endDepth = depth(currentNodeIdx) - 1;-
647 int depth = this->depth(currentNodeIdx - 1);-
648 bool blockTagClosed = false;-
649-
650 while (depth > endDepth
depth > endDepthDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
651 Table *t = 0;-
652 if (!tables.isEmpty()
!tables.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
653 t = &tables.last();
never executed: t = &tables.last();
0
654-
655 switch (closedNode->id) {-
656 case
never executed: case Html_tr:
Html_tr:
never executed: case Html_tr:
0
657 if (t
tDescription
TRUEnever evaluated
FALSEnever evaluated
&& !t->isTextFrame
!t->isTextFrameDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
658 ++t->currentRow;-
659-
660-
661 while (!t->currentCell.atEnd()
!t->currentCell.atEnd()Description
TRUEnever evaluated
FALSEnever evaluated
&& t->currentCell.row < t->currentRow
t->currentCell... t->currentRowDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
662 ++
never executed: ++t->currentCell;
t->currentCell;
never executed: ++t->currentCell;
0
663 }
never executed: end of block
0
664-
665 blockTagClosed = true;-
666 break;
never executed: break;
0
667-
668 case
never executed: case Html_table:
Html_table:
never executed: case Html_table:
0
669 if (!t
!tDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
670 break;
never executed: break;
0
671 indent = t->lastIndent;-
672-
673 tables.resize(tables.size() - 1);-
674 t = 0;-
675-
676 if (tables.isEmpty()
tables.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
677 cursor = doc->rootFrame()->lastCursorPosition();-
678 }
never executed: end of block
else {
0
679 t = &tables.last();-
680 if (t->isTextFrame
t->isTextFrameDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
681 cursor = t->frame->lastCursorPosition();
never executed: cursor = t->frame->lastCursorPosition();
0
682 else if (!t->currentCell.atEnd()
!t->currentCell.atEnd()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
683 cursor = t->currentCell.cell().lastCursorPosition();
never executed: cursor = t->currentCell.cell().lastCursorPosition();
0
684 }
never executed: end of block
0
685-
686-
687-
688-
689 blockTagClosed = false;-
690 compressNextWhitespace = RemoveWhiteSpace;-
691 break;
never executed: break;
0
692-
693 case
never executed: case Html_th:
Html_th:
never executed: case Html_th:
0
694 case
never executed: case Html_td:
Html_td:
never executed: case Html_td:
0
695 if (t
tDescription
TRUEnever evaluated
FALSEnever evaluated
&& !t->isTextFrame
!t->isTextFrameDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
696 ++
never executed: ++t->currentCell;
t->currentCell;
never executed: ++t->currentCell;
0
697 blockTagClosed = true;-
698 compressNextWhitespace = RemoveWhiteSpace;-
699 break;
never executed: break;
0
700-
701 case
never executed: case Html_ol:
Html_ol:
never executed: case Html_ol:
0
702 case
never executed: case Html_ul:
Html_ul:
never executed: case Html_ul:
0
703 if (lists.isEmpty()
lists.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
704 break;
never executed: break;
0
705 lists.resize(lists.size() - 1);-
706 --indent;-
707 blockTagClosed = true;-
708 break;
never executed: break;
0
709-
710 case
never executed: case Html_br:
Html_br:
never executed: case Html_br:
0
711 compressNextWhitespace = RemoveWhiteSpace;-
712 break;
never executed: break;
0
713-
714 case
never executed: case Html_div:
Html_div:
never executed: case Html_div:
0
715 if (closedNode->children.isEmpty()
closedNode->children.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
716 break;
never executed: break;
0
717-
718 default
never executed: default:
:
never executed: default:
code before this statement never executed: default:
0
719 if (closedNode->isBlock()
closedNode->isBlock()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
720 blockTagClosed = true;
never executed: blockTagClosed = true;
0
721 break;
never executed: break;
0
722 }-
723-
724 closedNode = &at(closedNode->parent);-
725 --depth;-
726 }
never executed: end of block
0
727-
728 return
never executed: return blockTagClosed;
blockTagClosed;
never executed: return blockTagClosed;
0
729}-
730-
731QTextHtmlImporter::Table QTextHtmlImporter::scanTable(int tableNodeIdx)-
732{-
733 Table table;-
734 table.columns = 0;-
735-
736 QVector<QTextLength> columnWidths;-
737-
738 int tableHeaderRowCount = 0;-
739 QVector<int> rowNodes;-
740 rowNodes.reserve(at(tableNodeIdx).children.count());-
741 for (int row : at(tableNodeIdx).children) {-
742 switch (at(row).id) {-
743 case
never executed: case Html_tr:
Html_tr:
never executed: case Html_tr:
0
744 rowNodes += row;-
745 break;
never executed: break;
0
746 case
never executed: case Html_thead:
Html_thead:
never executed: case Html_thead:
0
747 case
never executed: case Html_tbody:
Html_tbody:
never executed: case Html_tbody:
0
748 case
never executed: case Html_tfoot:
Html_tfoot:
never executed: case Html_tfoot:
0
749 for (int potentialRow : at(row).children) {-
750 if (at(potentialRow).id == Html_tr
at(potentialRow).id == Html_trDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
751 rowNodes += potentialRow;-
752 if (at(row).id == Html_thead
at(row).id == Html_theadDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
753 ++
never executed: ++tableHeaderRowCount;
tableHeaderRowCount;
never executed: ++tableHeaderRowCount;
0
754 }
never executed: end of block
0
755 }
never executed: end of block
0
756 break;
never executed: break;
0
757 default
never executed: default:
:
never executed: default:
break;
never executed: break;
0
758 }-
759 }-
760-
761 QVector<RowColSpanInfo> rowColSpans;-
762 QVector<RowColSpanInfo> rowColSpanForColumn;-
763-
764 int effectiveRow = 0;-
765 for (int row : qAsConst(rowNodes)) {-
766 int colsInRow = 0;-
767-
768 for (int cell : at(row).children) {-
769 if (at(cell).isTableCell()
at(cell).isTableCell()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
770-
771 while (colsInRow < rowColSpanForColumn.size()
colsInRow < ro...rColumn.size()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
772 const RowColSpanInfo &spanInfo = rowColSpanForColumn.at(colsInRow);-
773-
774 if (spanInfo.row + spanInfo.rowSpan > effectiveRow
spanInfo.row +...> effectiveRowDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
775 ((!(spanInfo.col == colsInRow)) ? qt_assert("spanInfo.col == colsInRow",__FILE__,888) : qt_noop());-
776 colsInRow += spanInfo.colSpan;-
777 }
never executed: end of block
else
0
778 break;
never executed: break;
0
779 }-
780-
781 const QTextHtmlParserNode &c = at(cell);-
782 const int currentColumn = colsInRow;-
783 colsInRow += c.tableCellColSpan;-
784-
785 RowColSpanInfo spanInfo;-
786 spanInfo.row = effectiveRow;-
787 spanInfo.col = currentColumn;-
788 spanInfo.colSpan = c.tableCellColSpan;-
789 spanInfo.rowSpan = c.tableCellRowSpan;-
790 if (spanInfo.colSpan > 1
spanInfo.colSpan > 1Description
TRUEnever evaluated
FALSEnever evaluated
|| spanInfo.rowSpan > 1
spanInfo.rowSpan > 1Description
TRUEnever evaluated
FALSEnever evaluated
)
0
791 rowColSpans.append(spanInfo);
never executed: rowColSpans.append(spanInfo);
0
792-
793 columnWidths.resize(qMax(columnWidths.count(), colsInRow));-
794 rowColSpanForColumn.resize(columnWidths.size());-
795 for (int i = currentColumn; i < currentColumn + c.tableCellColSpan
i < currentCol...bleCellColSpanDescription
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
796 if (columnWidths.at(i).type() == QTextLength::VariableLength
columnWidths.a...VariableLengthDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
797 QTextLength w = c.width;-
798 if (c.tableCellColSpan > 1
c.tableCellColSpan > 1Description
TRUEnever evaluated
FALSEnever evaluated
&& w.type() != QTextLength::VariableLength
w.type() != QT...VariableLengthDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
799 w = QTextLength(w.type(), w.value(100.) / c.tableCellColSpan);
never executed: w = QTextLength(w.type(), w.value(100.) / c.tableCellColSpan);
0
800 columnWidths[i] = w;-
801 }
never executed: end of block
0
802 rowColSpanForColumn[i] = spanInfo;-
803 }
never executed: end of block
0
804 }
never executed: end of block
0
805 }
never executed: end of block
0
806-
807 table.columns = qMax(table.columns, colsInRow);-
808-
809 ++effectiveRow;-
810 }
never executed: end of block
0
811 table.rows = effectiveRow;-
812-
813 table.lastIndent = indent;-
814 indent = 0;-
815-
816 if (table.rows == 0
table.rows == 0Description
TRUEnever evaluated
FALSEnever evaluated
|| table.columns == 0
table.columns == 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
817 return
never executed: return table;
table;
never executed: return table;
0
818-
819 QTextFrameFormat fmt;-
820 const QTextHtmlParserNode &node = at(tableNodeIdx);-
821-
822 if (!node.isTextFrame
!node.isTextFrameDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
823 QTextTableFormat tableFmt;-
824 tableFmt.setCellSpacing(node.tableCellSpacing);-
825 tableFmt.setCellPadding(node.tableCellPadding);-
826 if (node.blockFormat.hasProperty(QTextFormat::BlockAlignment)
node.blockForm...lockAlignment)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
827 tableFmt.setAlignment(node.blockFormat.alignment());
never executed: tableFmt.setAlignment(node.blockFormat.alignment());
0
828 tableFmt.setColumns(table.columns);-
829 tableFmt.setColumnWidthConstraints(columnWidths);-
830 tableFmt.setHeaderRowCount(tableHeaderRowCount);-
831 fmt = tableFmt;-
832 }
never executed: end of block
0
833-
834 fmt.setTopMargin(topMargin(tableNodeIdx));-
835 fmt.setBottomMargin(bottomMargin(tableNodeIdx));-
836 fmt.setLeftMargin(leftMargin(tableNodeIdx)-
837 + table.lastIndent * 40-
838 );-
839 fmt.setRightMargin(rightMargin(tableNodeIdx));-
840-
841-
842 if (qFuzzyCompare(fmt.leftMargin(), fmt.rightMargin())
qFuzzyCompare(...rightMargin())Description
TRUEnever evaluated
FALSEnever evaluated
0
843 && qFuzzyCompare(fmt.leftMargin(), fmt.topMargin())
qFuzzyCompare(...t.topMargin())Description
TRUEnever evaluated
FALSEnever evaluated
0
844 && qFuzzyCompare(fmt.leftMargin(), fmt.bottomMargin())
qFuzzyCompare(...ottomMargin())Description
TRUEnever evaluated
FALSEnever evaluated
)
0
845 fmt.setProperty(QTextFormat::FrameMargin, fmt.leftMargin());
never executed: fmt.setProperty(QTextFormat::FrameMargin, fmt.leftMargin());
0
846-
847 fmt.setBorderStyle(node.borderStyle);-
848 fmt.setBorderBrush(node.borderBrush);-
849 fmt.setBorder(node.tableBorder);-
850 fmt.setWidth(node.width);-
851 fmt.setHeight(node.height);-
852 if (node.blockFormat.hasProperty(QTextFormat::PageBreakPolicy)
node.blockForm...geBreakPolicy)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
853 fmt.setPageBreakPolicy(node.blockFormat.pageBreakPolicy());
never executed: fmt.setPageBreakPolicy(node.blockFormat.pageBreakPolicy());
0
854-
855 if (node.blockFormat.hasProperty(QTextFormat::LayoutDirection)
node.blockForm...youtDirection)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
856 fmt.setLayoutDirection(node.blockFormat.layoutDirection());
never executed: fmt.setLayoutDirection(node.blockFormat.layoutDirection());
0
857 if (node.charFormat.background().style() != Qt::NoBrush
node.charForma...!= Qt::NoBrushDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
858 fmt.setBackground(node.charFormat.background());
never executed: fmt.setBackground(node.charFormat.background());
0
859 fmt.setPosition(QTextFrameFormat::Position(node.cssFloat));-
860-
861 if (node.isTextFrame
node.isTextFrameDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
862 if (node.isRootFrame
node.isRootFrameDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
863 table.frame = cursor.currentFrame();-
864 table.frame->setFrameFormat(fmt);-
865 }
never executed: end of block
else
0
866 table.frame = cursor.insertFrame(fmt);
never executed: table.frame = cursor.insertFrame(fmt);
0
867-
868 table.isTextFrame = true;-
869 }
never executed: end of block
else {
0
870 const int oldPos = cursor.position();-
871 QTextTable *textTable = cursor.insertTable(table.rows, table.columns, fmt.toTableFormat());-
872 table.frame = textTable;-
873-
874 for (int i = 0; i < rowColSpans.count()
i < rowColSpans.count()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
875 const RowColSpanInfo &nfo = rowColSpans.at(i);-
876 textTable->mergeCells(nfo.row, nfo.col, nfo.rowSpan, nfo.colSpan);-
877 }
never executed: end of block
0
878-
879 table.currentCell = TableCellIterator(textTable);-
880 cursor.setPosition(oldPos);-
881 }
never executed: end of block
0
882 return
never executed: return table;
table;
never executed: return table;
0
883}-
884-
885QTextHtmlImporter::ProcessNodeResult QTextHtmlImporter::processBlockNode()-
886{-
887 QTextBlockFormat block;-
888 QTextCharFormat charFmt;-
889 bool modifiedBlockFormat = true;-
890 bool modifiedCharFormat = true;-
891-
892 if (currentNode->isTableCell()
currentNode->isTableCell()Description
TRUEnever evaluated
FALSEnever evaluated
&& !tables.isEmpty()
!tables.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
893 Table &t = tables.last();-
894 if (!t.isTextFrame
!t.isTextFrameDescription
TRUEnever evaluated
FALSEnever evaluated
&& !t.currentCell.atEnd()
!t.currentCell.atEnd()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
895 QTextTableCell cell = t.currentCell.cell();-
896 if (cell.isValid()
cell.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
897 QTextTableCellFormat fmt = cell.format().toTableCellFormat();-
898 if (topPadding(currentNodeIdx) >= 0
topPadding(cur...tNodeIdx) >= 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
899 fmt.setTopPadding(topPadding(currentNodeIdx));
never executed: fmt.setTopPadding(topPadding(currentNodeIdx));
0
900 if (bottomPadding(currentNodeIdx) >= 0
bottomPadding(...tNodeIdx) >= 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
901 fmt.setBottomPadding(bottomPadding(currentNodeIdx));
never executed: fmt.setBottomPadding(bottomPadding(currentNodeIdx));
0
902 if (leftPadding(currentNodeIdx) >= 0
leftPadding(cu...tNodeIdx) >= 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
903 fmt.setLeftPadding(leftPadding(currentNodeIdx));
never executed: fmt.setLeftPadding(leftPadding(currentNodeIdx));
0
904 if (rightPadding(currentNodeIdx) >= 0
rightPadding(c...tNodeIdx) >= 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
905 fmt.setRightPadding(rightPadding(currentNodeIdx));
never executed: fmt.setRightPadding(rightPadding(currentNodeIdx));
0
906 cell.setFormat(fmt);-
907-
908 cursor.setPosition(cell.firstPosition());-
909 }
never executed: end of block
0
910 }
never executed: end of block
0
911 hasBlock = true;-
912 compressNextWhitespace = RemoveWhiteSpace;-
913-
914 if (currentNode->charFormat.background().style() != Qt::NoBrush
currentNode->c...!= Qt::NoBrushDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
915 charFmt.setBackground(currentNode->charFormat.background());-
916 cursor.mergeBlockCharFormat(charFmt);-
917 }
never executed: end of block
0
918 }
never executed: end of block
0
919-
920 if (hasBlock
hasBlockDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
921 block = cursor.blockFormat();-
922 charFmt = cursor.blockCharFormat();-
923 modifiedBlockFormat = false;-
924 modifiedCharFormat = false;-
925 }
never executed: end of block
0
926-
927-
928 {-
929 qreal tm = qreal(topMargin(currentNodeIdx));-
930 if (tm > block.topMargin()
tm > block.topMargin()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
931 block.setTopMargin(tm);-
932 modifiedBlockFormat = true;-
933 }
never executed: end of block
0
934 }-
935-
936 int bottomMargin = this->bottomMargin(currentNodeIdx);-
937-
938-
939-
940 const QTextHtmlParserNode *parentNode = currentNode->parent
currentNode->parentDescription
TRUEnever evaluated
FALSEnever evaluated
? &at(currentNode->parent) : 0;
0
941 if ((currentNode->id == Html_li
currentNode->id == Html_liDescription
TRUEnever evaluated
FALSEnever evaluated
|| currentNode->id == Html_dt
currentNode->id == Html_dtDescription
TRUEnever evaluated
FALSEnever evaluated
|| currentNode->id == Html_dd
currentNode->id == Html_ddDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
942 && parentNode
parentNodeDescription
TRUEnever evaluated
FALSEnever evaluated
0
943 && (parentNode->isListStart()
parentNode->isListStart()Description
TRUEnever evaluated
FALSEnever evaluated
|| parentNode->id == Html_dl
parentNode->id == Html_dlDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
944 && (
(parentNode->c...urrentNodeIdx)Description
TRUEnever evaluated
FALSEnever evaluated
parentNode->children.last() == currentNodeIdx)
(parentNode->c...urrentNodeIdx)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
945 bottomMargin = qMax(bottomMargin, this->bottomMargin(currentNode->parent));-
946 }
never executed: end of block
0
947-
948 if (block.bottomMargin() != bottomMargin
block.bottomMa...= bottomMarginDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
949 block.setBottomMargin(bottomMargin);-
950 modifiedBlockFormat = true;-
951 }
never executed: end of block
0
952-
953 {-
954 const qreal lm = leftMargin(currentNodeIdx);-
955 const qreal rm = rightMargin(currentNodeIdx);-
956-
957 if (block.leftMargin() != lm
block.leftMargin() != lmDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
958 block.setLeftMargin(lm);-
959 modifiedBlockFormat = true;-
960 }
never executed: end of block
0
961 if (block.rightMargin() != rm
block.rightMargin() != rmDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
962 block.setRightMargin(rm);-
963 modifiedBlockFormat = true;-
964 }
never executed: end of block
0
965 }-
966-
967 if (currentNode->id != Html_li
currentNode->id != Html_liDescription
TRUEnever evaluated
FALSEnever evaluated
0
968 && indent != 0
indent != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
969 && (lists.isEmpty()
lists.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
970 || !hasBlock
!hasBlockDescription
TRUEnever evaluated
FALSEnever evaluated
0
971 || !lists.constLast().list
!lists.constLast().listDescription
TRUEnever evaluated
FALSEnever evaluated
0
972 || lists.constLast().list->itemNumber(cursor.block()) == -1
lists.constLas...block()) == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
973 )-
974 ) {-
975 block.setIndent(indent);-
976 modifiedBlockFormat = true;-
977 }
never executed: end of block
0
978-
979 if (currentNode->blockFormat.propertyCount() > 0
currentNode->b...rtyCount() > 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
980 modifiedBlockFormat = true;-
981 block.merge(currentNode->blockFormat);-
982 }
never executed: end of block
0
983-
984 if (currentNode->charFormat.propertyCount() > 0
currentNode->c...rtyCount() > 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
985 modifiedCharFormat = true;-
986 charFmt.merge(currentNode->charFormat);-
987 }
never executed: end of block
0
988-
989-
990-
991-
992 if (wsm == QTextHtmlParserNode::WhiteSpacePre
wsm == QTextHt...:WhiteSpacePreDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
993 block.setNonBreakableLines(true);-
994 modifiedBlockFormat = true;-
995 }
never executed: end of block
0
996-
997 if (currentNode->charFormat.background().style() != Qt::NoBrush
currentNode->c...!= Qt::NoBrushDescription
TRUEnever evaluated
FALSEnever evaluated
&& !currentNode->isTableCell()
!currentNode->isTableCell()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
998 block.setBackground(currentNode->charFormat.background());-
999 modifiedBlockFormat = true;-
1000 }
never executed: end of block
0
1001-
1002 if (hasBlock
hasBlockDescription
TRUEnever evaluated
FALSEnever evaluated
&& (!currentNode->isEmptyParagraph
!currentNode->isEmptyParagraphDescription
TRUEnever evaluated
FALSEnever evaluated
|| forceBlockMerging
forceBlockMergingDescription
TRUEnever evaluated
FALSEnever evaluated
)) {
0
1003 if (modifiedBlockFormat
modifiedBlockFormatDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1004 cursor.setBlockFormat(block);
never executed: cursor.setBlockFormat(block);
0
1005 if (modifiedCharFormat
modifiedCharFormatDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1006 cursor.setBlockCharFormat(charFmt);
never executed: cursor.setBlockCharFormat(charFmt);
0
1007 }
never executed: end of block
else {
0
1008 if (currentNodeIdx == 1
currentNodeIdx == 1Description
TRUEnever evaluated
FALSEnever evaluated
&& cursor.position() == 0
cursor.position() == 0Description
TRUEnever evaluated
FALSEnever evaluated
&& currentNode->isEmptyParagraph
currentNode->isEmptyParagraphDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1009 cursor.setBlockFormat(block);-
1010 cursor.setBlockCharFormat(charFmt);-
1011 }
never executed: end of block
else {
0
1012 appendBlock(block, charFmt);-
1013 }
never executed: end of block
0
1014 }-
1015-
1016 if (currentNode->userState != -1
currentNode->userState != -1Description
TRUEnever evaluated
FALSEnever evaluated
)
0
1017 cursor.block().setUserState(currentNode->userState);
never executed: cursor.block().setUserState(currentNode->userState);
0
1018-
1019 if (currentNode->id == Html_li
currentNode->id == Html_liDescription
TRUEnever evaluated
FALSEnever evaluated
&& !lists.isEmpty()
!lists.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1020 List &l = lists.last();-
1021 if (l.list
l.listDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1022 l.list->add(cursor.block());-
1023 }
never executed: end of block
else {
0
1024 l.list = cursor.createList(l.format);-
1025 const qreal listTopMargin = topMargin(l.listNode);-
1026 if (listTopMargin > block.topMargin()
listTopMargin ...ck.topMargin()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1027 block.setTopMargin(listTopMargin);-
1028 cursor.mergeBlockFormat(block);-
1029 }
never executed: end of block
0
1030 }
never executed: end of block
0
1031 if (hasBlock
hasBlockDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1032 QTextBlockFormat fmt;-
1033 fmt.setIndent(currentNode->blockFormat.indent());-
1034 cursor.mergeBlockFormat(fmt);-
1035 }
never executed: end of block
0
1036 }
never executed: end of block
0
1037-
1038 forceBlockMerging = false;-
1039 if (currentNode->id == Html_body
currentNode->id == Html_bodyDescription
TRUEnever evaluated
FALSEnever evaluated
|| currentNode->id == Html_html
currentNode->id == Html_htmlDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1040 forceBlockMerging = true;
never executed: forceBlockMerging = true;
0
1041-
1042 if (currentNode->isEmptyParagraph
currentNode->isEmptyParagraphDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1043 hasBlock = false;-
1044 return
never executed: return ContinueWithNextSibling;
ContinueWithNextSibling;
never executed: return ContinueWithNextSibling;
0
1045 }-
1046-
1047 hasBlock = true;-
1048 blockTagClosed = false;-
1049 return
never executed: return ContinueWithCurrentNode;
ContinueWithCurrentNode;
never executed: return ContinueWithCurrentNode;
0
1050}-
1051-
1052void QTextHtmlImporter::appendBlock(const QTextBlockFormat &format, QTextCharFormat charFmt)-
1053{-
1054 if (!namedAnchors.isEmpty()
!namedAnchors.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1055 charFmt.setAnchor(true);-
1056 charFmt.setAnchorNames(namedAnchors);-
1057 namedAnchors.clear();-
1058 }
never executed: end of block
0
1059-
1060 cursor.insertBlock(format, charFmt);-
1061-
1062 if (wsm != QTextHtmlParserNode::WhiteSpacePre
wsm != QTextHt...:WhiteSpacePreDescription
TRUEnever evaluated
FALSEnever evaluated
&& wsm != QTextHtmlParserNode::WhiteSpacePreWrap
wsm != QTextHt...teSpacePreWrapDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1063 compressNextWhitespace = RemoveWhiteSpace;
never executed: compressNextWhitespace = RemoveWhiteSpace;
0
1064}
never executed: end of block
0
1065QTextDocumentFragment QTextDocumentFragment::fromHtml(const QString &html)-
1066{-
1067 return
never executed: return fromHtml(html, 0);
fromHtml(html, 0);
never executed: return fromHtml(html, 0);
0
1068}-
1069QTextDocumentFragment QTextDocumentFragment::fromHtml(const QString &html, const QTextDocument *resourceProvider)-
1070{-
1071 QTextDocumentFragment res;-
1072 res.d = new QTextDocumentFragmentPrivate;-
1073-
1074 QTextHtmlImporter importer(res.d->doc, html, QTextHtmlImporter::ImportToFragment, resourceProvider);-
1075 importer.import();-
1076 return
never executed: return res;
res;
never executed: return res;
0
1077}-
1078-
1079-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9