| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/gui/text/qtextdocumentfragment.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||||||||
| 2 | - | |||||||||||||||||||
| 3 | - | |||||||||||||||||||
| 4 | - | |||||||||||||||||||
| 5 | QTextCopyHelper::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 | - | |||||||||||||||||||
| 20 | int QTextCopyHelper::convertFormatIndex(const QTextFormat &oldFormat, int objectIndexToSet) | - | ||||||||||||||||||
| 21 | { | - | ||||||||||||||||||
| 22 | QTextFormat fmt = oldFormat; | - | ||||||||||||||||||
| 23 | if (objectIndexToSet != -1
| 0 | ||||||||||||||||||
| 24 | fmt.setObjectIndex(objectIndexToSet); | - | ||||||||||||||||||
| 25 | } never executed: else if (fmt.objectIndex() != -1end of block
| 0 | ||||||||||||||||||
| 26 | int newObjectIndex = objectIndexMap.value(fmt.objectIndex(), -1); | - | ||||||||||||||||||
| 27 | if (newObjectIndex == -1
| 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: idx;return idx;never executed: return idx; | 0 | ||||||||||||||||||
| 38 | } | - | ||||||||||||||||||
| 39 | - | |||||||||||||||||||
| 40 | int 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
| 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
| 0 | ||||||||||||||||||
| 65 | blockIdx = convertFormatIndex(nextBlock.blockFormat()); | - | ||||||||||||||||||
| 66 | } never executed: else if (pos == 0end of block
| 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
| 0 | ||||||||||||||||||
| 73 | && (txtToInsert.at(0) == QChar::ParagraphSeparator
| 0 | ||||||||||||||||||
| 74 | || txtToInsert.at(0) == QChar(0xfdd0)
| 0 | ||||||||||||||||||
| 75 | || txtToInsert.at(0) == QChar(0xfdd1)
| 0 | ||||||||||||||||||
| 76 | ) | - | ||||||||||||||||||
| 77 | ) { | - | ||||||||||||||||||
| 78 | dst->insertBlock(txtToInsert.at(0), insertPos, blockIdx, charFormatIndex); | - | ||||||||||||||||||
| 79 | ++insertPos; | - | ||||||||||||||||||
| 80 | } never executed: else {end of block | 0 | ||||||||||||||||||
| 81 | if (nextBlock.textList()
| 0 | ||||||||||||||||||
| 82 | QTextBlock dstBlock = dst->blocksFind(insertPos); | - | ||||||||||||||||||
| 83 | if (!dstBlock.textList()
| 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
| 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: charsToCopy;return charsToCopy;never executed: return charsToCopy; | 0 | ||||||||||||||||||
| 101 | } | - | ||||||||||||||||||
| 102 | - | |||||||||||||||||||
| 103 | void QTextCopyHelper::appendFragments(int pos, int endPos) | - | ||||||||||||||||||
| 104 | { | - | ||||||||||||||||||
| 105 | ((!(pos < endPos)) ? qt_assert("pos < endPos",__FILE__,149) : qt_noop()); | - | ||||||||||||||||||
| 106 | - | |||||||||||||||||||
| 107 | while (pos < endPos
| 0 | ||||||||||||||||||
| 108 | pos += appendFragment(pos, endPos); never executed: pos += appendFragment(pos, endPos); | 0 | ||||||||||||||||||
| 109 | } never executed: end of block | 0 | ||||||||||||||||||
| 110 | - | |||||||||||||||||||
| 111 | void QTextCopyHelper::copy() | - | ||||||||||||||||||
| 112 | { | - | ||||||||||||||||||
| 113 | if (cursor.hasComplexSelection()
| 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
| 0 | ||||||||||||||||||
| 125 | for (int c = col_start; c < col_start + num_cols
| 0 | ||||||||||||||||||
| 126 | QTextTableCell cell = table->cellAt(r, c); | - | ||||||||||||||||||
| 127 | const int rspan = cell.rowSpan(); | - | ||||||||||||||||||
| 128 | const int cspan = cell.columnSpan(); | - | ||||||||||||||||||
| 129 | if (rspan != 1
| 0 | ||||||||||||||||||
| 130 | int cr = cell.row(); | - | ||||||||||||||||||
| 131 | if (cr != r
| 0 | ||||||||||||||||||
| 132 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 133 | } never executed: end of block | 0 | ||||||||||||||||||
| 134 | if (cspan != 1
| 0 | ||||||||||||||||||
| 135 | int cc = cell.column(); | - | ||||||||||||||||||
| 136 | if (cc != c
| 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
| 0 | ||||||||||||||||||
| 143 | cellFormat.setTableCellRowSpan(row_start + num_rows - r); | - | ||||||||||||||||||
| 144 | } never executed: end of block | 0 | ||||||||||||||||||
| 145 | if (c + cspan >= col_start + num_cols
| 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
| 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
| 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: else {end of block | 0 | ||||||||||||||||||
| 172 | appendFragments(cursor.selectionStart(), cursor.selectionEnd()); | - | ||||||||||||||||||
| 173 | } never executed: end of block | 0 | ||||||||||||||||||
| 174 | } | - | ||||||||||||||||||
| 175 | - | |||||||||||||||||||
| 176 | QTextDocumentFragmentPrivate::QTextDocumentFragmentPrivate(const QTextCursor &_cursor) | - | ||||||||||||||||||
| 177 | : ref(1), doc(new QTextDocument), importedFromPlainText(false) | - | ||||||||||||||||||
| 178 | { | - | ||||||||||||||||||
| 179 | doc->setUndoRedoEnabled(false); | - | ||||||||||||||||||
| 180 | - | |||||||||||||||||||
| 181 | if (!_cursor.hasSelection()
| 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
| 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 | - | |||||||||||||||||||
| 193 | void QTextDocumentFragmentPrivate::insert(QTextCursor &_cursor) const | - | ||||||||||||||||||
| 194 | { | - | ||||||||||||||||||
| 195 | if (_cursor.isNull()
| 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 | ||||||||||||||||||
| 207 | QTextDocumentFragment::QTextDocumentFragment() | - | ||||||||||||||||||
| 208 | : d(0) | - | ||||||||||||||||||
| 209 | { | - | ||||||||||||||||||
| 210 | } never executed: end of block | 0 | ||||||||||||||||||
| 211 | - | |||||||||||||||||||
| 212 | - | |||||||||||||||||||
| 213 | - | |||||||||||||||||||
| 214 | - | |||||||||||||||||||
| 215 | - | |||||||||||||||||||
| 216 | - | |||||||||||||||||||
| 217 | QTextDocumentFragment::QTextDocumentFragment(const QTextDocument *document) | - | ||||||||||||||||||
| 218 | : d(0) | - | ||||||||||||||||||
| 219 | { | - | ||||||||||||||||||
| 220 | if (!document
| 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 | - | |||||||||||||||||||
| 234 | QTextDocumentFragment::QTextDocumentFragment(const QTextCursor &cursor) | - | ||||||||||||||||||
| 235 | : d(0) | - | ||||||||||||||||||
| 236 | { | - | ||||||||||||||||||
| 237 | if (!cursor.hasSelection()
| 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 | - | |||||||||||||||||||
| 248 | QTextDocumentFragment::QTextDocumentFragment(const QTextDocumentFragment &rhs) | - | ||||||||||||||||||
| 249 | : d(rhs.d) | - | ||||||||||||||||||
| 250 | { | - | ||||||||||||||||||
| 251 | if (d
| 0 | ||||||||||||||||||
| 252 | d->ref.ref(); never executed: d->ref.ref(); | 0 | ||||||||||||||||||
| 253 | } never executed: end of block | 0 | ||||||||||||||||||
| 254 | - | |||||||||||||||||||
| 255 | - | |||||||||||||||||||
| 256 | - | |||||||||||||||||||
| 257 | - | |||||||||||||||||||
| 258 | - | |||||||||||||||||||
| 259 | - | |||||||||||||||||||
| 260 | QTextDocumentFragment &QTextDocumentFragment::operator=(const QTextDocumentFragment &rhs) | - | ||||||||||||||||||
| 261 | { | - | ||||||||||||||||||
| 262 | if (rhs.d
| 0 | ||||||||||||||||||
| 263 | rhs.d->ref.ref(); never executed: rhs.d->ref.ref(); | 0 | ||||||||||||||||||
| 264 | if (d
| 0 | ||||||||||||||||||
| 265 | delete d; never executed: delete d; | 0 | ||||||||||||||||||
| 266 | d = rhs.d; | - | ||||||||||||||||||
| 267 | return never executed: *this;return *this;never executed: return *this; | 0 | ||||||||||||||||||
| 268 | } | - | ||||||||||||||||||
| 269 | - | |||||||||||||||||||
| 270 | - | |||||||||||||||||||
| 271 | - | |||||||||||||||||||
| 272 | - | |||||||||||||||||||
| 273 | QTextDocumentFragment::~QTextDocumentFragment() | - | ||||||||||||||||||
| 274 | { | - | ||||||||||||||||||
| 275 | if (d
| 0 | ||||||||||||||||||
| 276 | delete d; never executed: delete d; | 0 | ||||||||||||||||||
| 277 | } never executed: end of block | 0 | ||||||||||||||||||
| 278 | - | |||||||||||||||||||
| 279 | - | |||||||||||||||||||
| 280 | - | |||||||||||||||||||
| 281 | - | |||||||||||||||||||
| 282 | bool QTextDocumentFragment::isEmpty() const | - | ||||||||||||||||||
| 283 | { | - | ||||||||||||||||||
| 284 | return never executed: !d || !d->doc || d->doc->docHandle()->length() <= 1;return !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 | - | |||||||||||||||||||
| 293 | QString QTextDocumentFragment::toPlainText() const | - | ||||||||||||||||||
| 294 | { | - | ||||||||||||||||||
| 295 | if (!d
| 0 | ||||||||||||||||||
| 296 | return never executed: QString();return QString();never executed: return QString(); | 0 | ||||||||||||||||||
| 297 | - | |||||||||||||||||||
| 298 | return never executed: d->doc->toPlainText();return d->doc->toPlainText();never executed: return d->doc->toPlainText(); | 0 | ||||||||||||||||||
| 299 | } | - | ||||||||||||||||||
| 300 | QString QTextDocumentFragment::toHtml(const QByteArray &encoding) const | - | ||||||||||||||||||
| 301 | { | - | ||||||||||||||||||
| 302 | if (!d
| 0 | ||||||||||||||||||
| 303 | return never executed: QString();return QString();never executed: return QString(); | 0 | ||||||||||||||||||
| 304 | - | |||||||||||||||||||
| 305 | return never executed: QTextHtmlExporter(d->doc).toHtml(encoding, QTextHtmlExporter::ExportFragment);return QTextHtmlExporter(d->doc).toHtml(encoding, QTextHtmlExporter::ExportFragment);never executed: return QTextHtmlExporter(d->doc).toHtml(encoding, QTextHtmlExporter::ExportFragment); | 0 | ||||||||||||||||||
| 306 | } | - | ||||||||||||||||||
| 307 | QTextDocumentFragment 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: res;return res;never executed: return res; | 0 | ||||||||||||||||||
| 316 | } | - | ||||||||||||||||||
| 317 | - | |||||||||||||||||||
| 318 | static QTextListFormat::Style nextListStyle(QTextListFormat::Style style) | - | ||||||||||||||||||
| 319 | { | - | ||||||||||||||||||
| 320 | if (style == QTextListFormat::ListDisc
| 0 | ||||||||||||||||||
| 321 | return never executed: QTextListFormat::ListCircle;return QTextListFormat::ListCircle;never executed: return QTextListFormat::ListCircle; | 0 | ||||||||||||||||||
| 322 | else if (style == QTextListFormat::ListCircle
| 0 | ||||||||||||||||||
| 323 | return never executed: QTextListFormat::ListSquare;return QTextListFormat::ListSquare;never executed: return QTextListFormat::ListSquare; | 0 | ||||||||||||||||||
| 324 | return never executed: style;return style;never executed: return style; | 0 | ||||||||||||||||||
| 325 | } | - | ||||||||||||||||||
| 326 | - | |||||||||||||||||||
| 327 | - | |||||||||||||||||||
| 328 | - | |||||||||||||||||||
| 329 | QTextHtmlImporter::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
| 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
| 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
| 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 | - | |||||||||||||||||||
| 357 | void QTextHtmlImporter::import() | - | ||||||||||||||||||
| 358 | { | - | ||||||||||||||||||
| 359 | cursor.beginEditBlock(); | - | ||||||||||||||||||
| 360 | hasBlock = true; | - | ||||||||||||||||||
| 361 | forceBlockMerging = false; | - | ||||||||||||||||||
| 362 | compressNextWhitespace = RemoveWhiteSpace; | - | ||||||||||||||||||
| 363 | blockTagClosed = false; | - | ||||||||||||||||||
| 364 | for (currentNodeIdx = 0; currentNodeIdx < count()
| 0 | ||||||||||||||||||
| 365 | currentNode = &at(currentNodeIdx); | - | ||||||||||||||||||
| 366 | wsm = textEditMode
| 0 | ||||||||||||||||||
| 367 | if (currentNodeIdx > 0
| 0 | ||||||||||||||||||
| 368 | blockTagClosed = closeTag(); | - | ||||||||||||||||||
| 369 | - | |||||||||||||||||||
| 370 | - | |||||||||||||||||||
| 371 | - | |||||||||||||||||||
| 372 | if (blockTagClosed
| 0 | ||||||||||||||||||
| 373 | && !currentNode->isBlock()
| 0 | ||||||||||||||||||
| 374 | && currentNode->id != Html_unknown
| 0 | ||||||||||||||||||
| 375 | { | - | ||||||||||||||||||
| 376 | hasBlock = false; | - | ||||||||||||||||||
| 377 | } never executed: else if (blockTagClosedend of block
| 0 | ||||||||||||||||||
| 378 | - | |||||||||||||||||||
| 379 | QTextBlockFormat blockFormat = currentNode->blockFormat; | - | ||||||||||||||||||
| 380 | blockFormat.setIndent(indent); | - | ||||||||||||||||||
| 381 | - | |||||||||||||||||||
| 382 | QTextBlockFormat oldFormat = cursor.blockFormat(); | - | ||||||||||||||||||
| 383 | if (oldFormat.hasProperty(QTextFormat::PageBreakPolicy)
| 0 | ||||||||||||||||||
| 384 | QTextFormat::PageBreakFlags pageBreak = oldFormat.pageBreakPolicy(); | - | ||||||||||||||||||
| 385 | if (pageBreak == QTextFormat::PageBreak_AlwaysAfter
| 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
| 0 | ||||||||||||||||||
| 399 | if (currentNode->id == Html_title
| 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
| 0 | ||||||||||||||||||
| 406 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 407 | - | |||||||||||||||||||
| 408 | - | |||||||||||||||||||
| 409 | if (blockTagClosed
| 0 | ||||||||||||||||||
| 410 | && !hasBlock
| 0 | ||||||||||||||||||
| 411 | && !currentNode->isBlock()
| 0 | ||||||||||||||||||
| 412 | && !currentNode->text.isEmpty()
| 0 | ||||||||||||||||||
| 413 | && currentNode->displayMode == QTextHtmlElement::DisplayInline
| 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()
| 0 | ||||||||||||||||||
| 424 | QTextHtmlImporter::ProcessNodeResult result = processBlockNode(); | - | ||||||||||||||||||
| 425 | if (result == ContinueWithNextNode
| 0 | ||||||||||||||||||
| 426 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 427 | } else if (result == ContinueWithNextSibling
| 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()
| 0 | ||||||||||||||||||
| 434 | namedAnchors.append(currentNode->charFormat.anchorName()); | - | ||||||||||||||||||
| 435 | } never executed: end of block | 0 | ||||||||||||||||||
| 436 | - | |||||||||||||||||||
| 437 | if (appendNodeText()
| 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 | - | |||||||||||||||||||
| 445 | bool QTextHtmlImporter::appendNodeText() | - | ||||||||||||||||||
| 446 | { | - | ||||||||||||||||||
| 447 | const int initialCursorPosition = cursor.position(); | - | ||||||||||||||||||
| 448 | QTextCharFormat format = currentNode->charFormat; | - | ||||||||||||||||||
| 449 | - | |||||||||||||||||||
| 450 | if(wsm == QTextHtmlParserNode::WhiteSpacePre
| 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()
| 0 | ||||||||||||||||||
| 459 | QChar ch = text.at(i); | - | ||||||||||||||||||
| 460 | - | |||||||||||||||||||
| 461 | if (ch.isSpace()
| 0 | ||||||||||||||||||
| 462 | && ch != QChar::Nbsp
| 0 | ||||||||||||||||||
| 463 | && ch != QChar::ParagraphSeparator
| 0 | ||||||||||||||||||
| 464 | - | |||||||||||||||||||
| 465 | if (compressNextWhitespace == CollapseWhiteSpace
| 0 | ||||||||||||||||||
| 466 | compressNextWhitespace = RemoveWhiteSpace; never executed: compressNextWhitespace = RemoveWhiteSpace; | 0 | ||||||||||||||||||
| 467 | else if(compressNextWhitespace == RemoveWhiteSpace
| 0 | ||||||||||||||||||
| 468 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 469 | - | |||||||||||||||||||
| 470 | if (wsm == QTextHtmlParserNode::WhiteSpacePre
| 0 | ||||||||||||||||||
| 471 | || textEditMode
| 0 | ||||||||||||||||||
| 472 | ) { | - | ||||||||||||||||||
| 473 | if (ch == QLatin1Char('\n')
| 0 | ||||||||||||||||||
| 474 | if (textEditMode
| 0 | ||||||||||||||||||
| 475 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 476 | } never executed: else if (ch == QLatin1Char('\r')end of block
| 0 | ||||||||||||||||||
| 477 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 478 | } | - | ||||||||||||||||||
| 479 | } never executed: else if (wsm != QTextHtmlParserNode::WhiteSpacePreWrapend of block
| 0 | ||||||||||||||||||
| 480 | compressNextWhitespace = RemoveWhiteSpace; | - | ||||||||||||||||||
| 481 | if (wsm == QTextHtmlParserNode::WhiteSpaceNoWrap
| 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: else {end of block | 0 | ||||||||||||||||||
| 487 | compressNextWhitespace = PreserveWhiteSpace; | - | ||||||||||||||||||
| 488 | } never executed: end of block | 0 | ||||||||||||||||||
| 489 | - | |||||||||||||||||||
| 490 | if (ch == QLatin1Char('\n')
| 0 | ||||||||||||||||||
| 491 | || ch == QChar::ParagraphSeparator
| 0 | ||||||||||||||||||
| 492 | - | |||||||||||||||||||
| 493 | if (!textToInsert.isEmpty()
| 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)
| 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: else {end of block | 0 | ||||||||||||||||||
| 509 | if (!namedAnchors.isEmpty()
| 0 | ||||||||||||||||||
| 510 | if (!textToInsert.isEmpty()
| 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: else {end of block | 0 | ||||||||||||||||||
| 522 | textToInsert += ch; | - | ||||||||||||||||||
| 523 | } never executed: end of block | 0 | ||||||||||||||||||
| 524 | } | - | ||||||||||||||||||
| 525 | } | - | ||||||||||||||||||
| 526 | - | |||||||||||||||||||
| 527 | if (!textToInsert.isEmpty()
| 0 | ||||||||||||||||||
| 528 | cursor.insertText(textToInsert, format); | - | ||||||||||||||||||
| 529 | } never executed: end of block | 0 | ||||||||||||||||||
| 530 | - | |||||||||||||||||||
| 531 | return never executed: cursor.position() != initialCursorPosition;return cursor.position() != initialCursorPosition;never executed: return cursor.position() != initialCursorPosition; | 0 | ||||||||||||||||||
| 532 | } | - | ||||||||||||||||||
| 533 | - | |||||||||||||||||||
| 534 | QTextHtmlImporter::ProcessNodeResult QTextHtmlImporter::processSpecialNodes() | - | ||||||||||||||||||
| 535 | { | - | ||||||||||||||||||
| 536 | switch (currentNode->id) { | - | ||||||||||||||||||
| 537 | case never executed: Html_body:case Html_body:never executed: case Html_body: | 0 | ||||||||||||||||||
| 538 | if (currentNode->charFormat.background().style() != Qt::NoBrush
| 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: Html_ol:case Html_ol:never executed: case Html_ol: | 0 | ||||||||||||||||||
| 548 | case never executed: Html_ul:case Html_ul:never executed: {case Html_ul: | 0 | ||||||||||||||||||
| 549 | QTextListFormat::Style style = currentNode->listStyle; | - | ||||||||||||||||||
| 550 | - | |||||||||||||||||||
| 551 | if (currentNode->id == Html_ul
| 0 | ||||||||||||||||||
| 552 | const QTextHtmlParserNode *n = &at(currentNode->parent); | - | ||||||||||||||||||
| 553 | while (n
| 0 | ||||||||||||||||||
| 554 | if (n->id == Html_ul
| 0 | ||||||||||||||||||
| 555 | style = nextListStyle(currentNode->listStyle); | - | ||||||||||||||||||
| 556 | } never executed: end of block | 0 | ||||||||||||||||||
| 557 | if (n->parent
| 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()
| 0 | ||||||||||||||||||
| 567 | listFmt.setNumberPrefix(currentNode->textListNumberPrefix); never executed: listFmt.setNumberPrefix(currentNode->textListNumberPrefix); | 0 | ||||||||||||||||||
| 568 | if (!currentNode->textListNumberSuffix.isNull()
| 0 | ||||||||||||||||||
| 569 | listFmt.setNumberSuffix(currentNode->textListNumberSuffix); never executed: listFmt.setNumberSuffix(currentNode->textListNumberSuffix); | 0 | ||||||||||||||||||
| 570 | - | |||||||||||||||||||
| 571 | ++indent; | - | ||||||||||||||||||
| 572 | if (currentNode->hasCssListIndent
| 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()
| 0 | ||||||||||||||||||
| 586 | return never executed: ContinueWithNextNode;return ContinueWithNextNode;never executed: return ContinueWithNextNode; | 0 | ||||||||||||||||||
| 587 | break; never executed: break; | 0 | ||||||||||||||||||
| 588 | } | - | ||||||||||||||||||
| 589 | - | |||||||||||||||||||
| 590 | case never executed: Html_table:case 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: ContinueWithNextNode;return ContinueWithNextNode;never executed: return ContinueWithNextNode; | 0 | ||||||||||||||||||
| 596 | } | - | ||||||||||||||||||
| 597 | - | |||||||||||||||||||
| 598 | case never executed: Html_tr:case Html_tr:never executed: case Html_tr: | 0 | ||||||||||||||||||
| 599 | return never executed: ContinueWithNextNode;return ContinueWithNextNode;never executed: return ContinueWithNextNode; | 0 | ||||||||||||||||||
| 600 | - | |||||||||||||||||||
| 601 | case never executed: Html_img:case 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
| 0 | ||||||||||||||||||
| 608 | fmt.setWidth(currentNode->imageWidth); never executed: fmt.setWidth(currentNode->imageWidth); | 0 | ||||||||||||||||||
| 609 | if (currentNode->imageHeight != -1
| 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: ContinueWithNextNode;return ContinueWithNextNode;never executed: return ContinueWithNextNode; | 0 | ||||||||||||||||||
| 621 | } | - | ||||||||||||||||||
| 622 | - | |||||||||||||||||||
| 623 | case never executed: Html_hr:case 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
| 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: ContinueWithNextNode;return ContinueWithNextNode;never executed: return ContinueWithNextNode; | 0 | ||||||||||||||||||
| 635 | } | - | ||||||||||||||||||
| 636 | - | |||||||||||||||||||
| 637 | default never executed: :default:never executed: break;default:never executed: break; | 0 | ||||||||||||||||||
| 638 | } | - | ||||||||||||||||||
| 639 | return never executed: ContinueWithCurrentNode;return ContinueWithCurrentNode;never executed: return ContinueWithCurrentNode; | 0 | ||||||||||||||||||
| 640 | } | - | ||||||||||||||||||
| 641 | - | |||||||||||||||||||
| 642 | - | |||||||||||||||||||
| 643 | bool 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
| 0 | ||||||||||||||||||
| 651 | Table *t = 0; | - | ||||||||||||||||||
| 652 | if (!tables.isEmpty()
| 0 | ||||||||||||||||||
| 653 | t = &tables.last(); never executed: t = &tables.last(); | 0 | ||||||||||||||||||
| 654 | - | |||||||||||||||||||
| 655 | switch (closedNode->id) { | - | ||||||||||||||||||
| 656 | case never executed: Html_tr:case Html_tr:never executed: case Html_tr: | 0 | ||||||||||||||||||
| 657 | if (t
| 0 | ||||||||||||||||||
| 658 | ++t->currentRow; | - | ||||||||||||||||||
| 659 | - | |||||||||||||||||||
| 660 | - | |||||||||||||||||||
| 661 | while (!t->currentCell.atEnd()
| 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: Html_table:case Html_table:never executed: case Html_table: | 0 | ||||||||||||||||||
| 669 | if (!t
| 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()
| 0 | ||||||||||||||||||
| 677 | cursor = doc->rootFrame()->lastCursorPosition(); | - | ||||||||||||||||||
| 678 | } never executed: else {end of block | 0 | ||||||||||||||||||
| 679 | t = &tables.last(); | - | ||||||||||||||||||
| 680 | if (t->isTextFrame
| 0 | ||||||||||||||||||
| 681 | cursor = t->frame->lastCursorPosition(); never executed: cursor = t->frame->lastCursorPosition(); | 0 | ||||||||||||||||||
| 682 | else if (!t->currentCell.atEnd()
| 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: Html_th:case Html_th:never executed: case Html_th: | 0 | ||||||||||||||||||
| 694 | case never executed: Html_td:case Html_td:never executed: case Html_td: | 0 | ||||||||||||||||||
| 695 | if (t
| 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: Html_ol:case Html_ol:never executed: case Html_ol: | 0 | ||||||||||||||||||
| 702 | case never executed: Html_ul:case Html_ul:never executed: case Html_ul: | 0 | ||||||||||||||||||
| 703 | if (lists.isEmpty()
| 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: Html_br:case Html_br:never executed: case Html_br: | 0 | ||||||||||||||||||
| 711 | compressNextWhitespace = RemoveWhiteSpace; | - | ||||||||||||||||||
| 712 | break; never executed: break; | 0 | ||||||||||||||||||
| 713 | - | |||||||||||||||||||
| 714 | case never executed: Html_div:case Html_div:never executed: case Html_div: | 0 | ||||||||||||||||||
| 715 | if (closedNode->children.isEmpty()
| 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()
| 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: blockTagClosed;return blockTagClosed;never executed: return blockTagClosed; | 0 | ||||||||||||||||||
| 729 | } | - | ||||||||||||||||||
| 730 | - | |||||||||||||||||||
| 731 | QTextHtmlImporter::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: Html_tr:case Html_tr:never executed: case Html_tr: | 0 | ||||||||||||||||||
| 744 | rowNodes += row; | - | ||||||||||||||||||
| 745 | break; never executed: break; | 0 | ||||||||||||||||||
| 746 | case never executed: Html_thead:case Html_thead:never executed: case Html_thead: | 0 | ||||||||||||||||||
| 747 | case never executed: Html_tbody:case Html_tbody:never executed: case Html_tbody: | 0 | ||||||||||||||||||
| 748 | case never executed: Html_tfoot:case Html_tfoot:never executed: case Html_tfoot: | 0 | ||||||||||||||||||
| 749 | for (int potentialRow : at(row).children) { | - | ||||||||||||||||||
| 750 | if (at(potentialRow).id == Html_tr
| 0 | ||||||||||||||||||
| 751 | rowNodes += potentialRow; | - | ||||||||||||||||||
| 752 | if (at(row).id == Html_thead
| 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: break;default: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()
| 0 | ||||||||||||||||||
| 770 | - | |||||||||||||||||||
| 771 | while (colsInRow < rowColSpanForColumn.size()
| 0 | ||||||||||||||||||
| 772 | const RowColSpanInfo &spanInfo = rowColSpanForColumn.at(colsInRow); | - | ||||||||||||||||||
| 773 | - | |||||||||||||||||||
| 774 | if (spanInfo.row + spanInfo.rowSpan > effectiveRow
| 0 | ||||||||||||||||||
| 775 | ((!(spanInfo.col == colsInRow)) ? qt_assert("spanInfo.col == colsInRow",__FILE__,888) : qt_noop()); | - | ||||||||||||||||||
| 776 | colsInRow += spanInfo.colSpan; | - | ||||||||||||||||||
| 777 | } never executed: elseend of block | 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
| 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
| 0 | ||||||||||||||||||
| 796 | if (columnWidths.at(i).type() == QTextLength::VariableLength
| 0 | ||||||||||||||||||
| 797 | QTextLength w = c.width; | - | ||||||||||||||||||
| 798 | if (c.tableCellColSpan > 1
| 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
| 0 | ||||||||||||||||||
| 817 | return never executed: table;return table;never executed: return table; | 0 | ||||||||||||||||||
| 818 | - | |||||||||||||||||||
| 819 | QTextFrameFormat fmt; | - | ||||||||||||||||||
| 820 | const QTextHtmlParserNode &node = at(tableNodeIdx); | - | ||||||||||||||||||
| 821 | - | |||||||||||||||||||
| 822 | if (!node.isTextFrame
| 0 | ||||||||||||||||||
| 823 | QTextTableFormat tableFmt; | - | ||||||||||||||||||
| 824 | tableFmt.setCellSpacing(node.tableCellSpacing); | - | ||||||||||||||||||
| 825 | tableFmt.setCellPadding(node.tableCellPadding); | - | ||||||||||||||||||
| 826 | if (node.blockFormat.hasProperty(QTextFormat::BlockAlignment)
| 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())
| 0 | ||||||||||||||||||
| 843 | && qFuzzyCompare(fmt.leftMargin(), fmt.topMargin())
| 0 | ||||||||||||||||||
| 844 | && qFuzzyCompare(fmt.leftMargin(), fmt.bottomMargin())
| 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)
| 0 | ||||||||||||||||||
| 853 | fmt.setPageBreakPolicy(node.blockFormat.pageBreakPolicy()); never executed: fmt.setPageBreakPolicy(node.blockFormat.pageBreakPolicy()); | 0 | ||||||||||||||||||
| 854 | - | |||||||||||||||||||
| 855 | if (node.blockFormat.hasProperty(QTextFormat::LayoutDirection)
| 0 | ||||||||||||||||||
| 856 | fmt.setLayoutDirection(node.blockFormat.layoutDirection()); never executed: fmt.setLayoutDirection(node.blockFormat.layoutDirection()); | 0 | ||||||||||||||||||
| 857 | if (node.charFormat.background().style() != Qt::NoBrush
| 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
| 0 | ||||||||||||||||||
| 862 | if (node.isRootFrame
| 0 | ||||||||||||||||||
| 863 | table.frame = cursor.currentFrame(); | - | ||||||||||||||||||
| 864 | table.frame->setFrameFormat(fmt); | - | ||||||||||||||||||
| 865 | } never executed: elseend of block | 0 | ||||||||||||||||||
| 866 | table.frame = cursor.insertFrame(fmt); never executed: table.frame = cursor.insertFrame(fmt); | 0 | ||||||||||||||||||
| 867 | - | |||||||||||||||||||
| 868 | table.isTextFrame = true; | - | ||||||||||||||||||
| 869 | } never executed: else {end of block | 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()
| 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: table;return table;never executed: return table; | 0 | ||||||||||||||||||
| 883 | } | - | ||||||||||||||||||
| 884 | - | |||||||||||||||||||
| 885 | QTextHtmlImporter::ProcessNodeResult QTextHtmlImporter::processBlockNode() | - | ||||||||||||||||||
| 886 | { | - | ||||||||||||||||||
| 887 | QTextBlockFormat block; | - | ||||||||||||||||||
| 888 | QTextCharFormat charFmt; | - | ||||||||||||||||||
| 889 | bool modifiedBlockFormat = true; | - | ||||||||||||||||||
| 890 | bool modifiedCharFormat = true; | - | ||||||||||||||||||
| 891 | - | |||||||||||||||||||
| 892 | if (currentNode->isTableCell()
| 0 | ||||||||||||||||||
| 893 | Table &t = tables.last(); | - | ||||||||||||||||||
| 894 | if (!t.isTextFrame
| 0 | ||||||||||||||||||
| 895 | QTextTableCell cell = t.currentCell.cell(); | - | ||||||||||||||||||
| 896 | if (cell.isValid()
| 0 | ||||||||||||||||||
| 897 | QTextTableCellFormat fmt = cell.format().toTableCellFormat(); | - | ||||||||||||||||||
| 898 | if (topPadding(currentNodeIdx) >= 0
| 0 | ||||||||||||||||||
| 899 | fmt.setTopPadding(topPadding(currentNodeIdx)); never executed: fmt.setTopPadding(topPadding(currentNodeIdx)); | 0 | ||||||||||||||||||
| 900 | if (bottomPadding(currentNodeIdx) >= 0
| 0 | ||||||||||||||||||
| 901 | fmt.setBottomPadding(bottomPadding(currentNodeIdx)); never executed: fmt.setBottomPadding(bottomPadding(currentNodeIdx)); | 0 | ||||||||||||||||||
| 902 | if (leftPadding(currentNodeIdx) >= 0
| 0 | ||||||||||||||||||
| 903 | fmt.setLeftPadding(leftPadding(currentNodeIdx)); never executed: fmt.setLeftPadding(leftPadding(currentNodeIdx)); | 0 | ||||||||||||||||||
| 904 | if (rightPadding(currentNodeIdx) >= 0
| 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
| 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
| 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()
| 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
| 0 | ||||||||||||||||||
| 941 | if ((currentNode->id == Html_li
| 0 | ||||||||||||||||||
| 942 | && parentNode
| 0 | ||||||||||||||||||
| 943 | && (parentNode->isListStart()
| 0 | ||||||||||||||||||
| 944 | && (
| 0 | ||||||||||||||||||
| 945 | bottomMargin = qMax(bottomMargin, this->bottomMargin(currentNode->parent)); | - | ||||||||||||||||||
| 946 | } never executed: end of block | 0 | ||||||||||||||||||
| 947 | - | |||||||||||||||||||
| 948 | if (block.bottomMargin() != bottomMargin
| 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
| 0 | ||||||||||||||||||
| 958 | block.setLeftMargin(lm); | - | ||||||||||||||||||
| 959 | modifiedBlockFormat = true; | - | ||||||||||||||||||
| 960 | } never executed: end of block | 0 | ||||||||||||||||||
| 961 | if (block.rightMargin() != rm
| 0 | ||||||||||||||||||
| 962 | block.setRightMargin(rm); | - | ||||||||||||||||||
| 963 | modifiedBlockFormat = true; | - | ||||||||||||||||||
| 964 | } never executed: end of block | 0 | ||||||||||||||||||
| 965 | } | - | ||||||||||||||||||
| 966 | - | |||||||||||||||||||
| 967 | if (currentNode->id != Html_li
| 0 | ||||||||||||||||||
| 968 | && indent != 0
| 0 | ||||||||||||||||||
| 969 | && (lists.isEmpty()
| 0 | ||||||||||||||||||
| 970 | || !hasBlock
| 0 | ||||||||||||||||||
| 971 | || !lists.constLast().list
| 0 | ||||||||||||||||||
| 972 | || lists.constLast().list->itemNumber(cursor.block()) == -1
| 0 | ||||||||||||||||||
| 973 | ) | - | ||||||||||||||||||
| 974 | ) { | - | ||||||||||||||||||
| 975 | block.setIndent(indent); | - | ||||||||||||||||||
| 976 | modifiedBlockFormat = true; | - | ||||||||||||||||||
| 977 | } never executed: end of block | 0 | ||||||||||||||||||
| 978 | - | |||||||||||||||||||
| 979 | if (currentNode->blockFormat.propertyCount() > 0
| 0 | ||||||||||||||||||
| 980 | modifiedBlockFormat = true; | - | ||||||||||||||||||
| 981 | block.merge(currentNode->blockFormat); | - | ||||||||||||||||||
| 982 | } never executed: end of block | 0 | ||||||||||||||||||
| 983 | - | |||||||||||||||||||
| 984 | if (currentNode->charFormat.propertyCount() > 0
| 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
| 0 | ||||||||||||||||||
| 993 | block.setNonBreakableLines(true); | - | ||||||||||||||||||
| 994 | modifiedBlockFormat = true; | - | ||||||||||||||||||
| 995 | } never executed: end of block | 0 | ||||||||||||||||||
| 996 | - | |||||||||||||||||||
| 997 | if (currentNode->charFormat.background().style() != Qt::NoBrush
| 0 | ||||||||||||||||||
| 998 | block.setBackground(currentNode->charFormat.background()); | - | ||||||||||||||||||
| 999 | modifiedBlockFormat = true; | - | ||||||||||||||||||
| 1000 | } never executed: end of block | 0 | ||||||||||||||||||
| 1001 | - | |||||||||||||||||||
| 1002 | if (hasBlock
| 0 | ||||||||||||||||||
| 1003 | if (modifiedBlockFormat
| 0 | ||||||||||||||||||
| 1004 | cursor.setBlockFormat(block); never executed: cursor.setBlockFormat(block); | 0 | ||||||||||||||||||
| 1005 | if (modifiedCharFormat
| 0 | ||||||||||||||||||
| 1006 | cursor.setBlockCharFormat(charFmt); never executed: cursor.setBlockCharFormat(charFmt); | 0 | ||||||||||||||||||
| 1007 | } never executed: else {end of block | 0 | ||||||||||||||||||
| 1008 | if (currentNodeIdx == 1
| 0 | ||||||||||||||||||
| 1009 | cursor.setBlockFormat(block); | - | ||||||||||||||||||
| 1010 | cursor.setBlockCharFormat(charFmt); | - | ||||||||||||||||||
| 1011 | } never executed: else {end of block | 0 | ||||||||||||||||||
| 1012 | appendBlock(block, charFmt); | - | ||||||||||||||||||
| 1013 | } never executed: end of block | 0 | ||||||||||||||||||
| 1014 | } | - | ||||||||||||||||||
| 1015 | - | |||||||||||||||||||
| 1016 | if (currentNode->userState != -1
| 0 | ||||||||||||||||||
| 1017 | cursor.block().setUserState(currentNode->userState); never executed: cursor.block().setUserState(currentNode->userState); | 0 | ||||||||||||||||||
| 1018 | - | |||||||||||||||||||
| 1019 | if (currentNode->id == Html_li
| 0 | ||||||||||||||||||
| 1020 | List &l = lists.last(); | - | ||||||||||||||||||
| 1021 | if (l.list
| 0 | ||||||||||||||||||
| 1022 | l.list->add(cursor.block()); | - | ||||||||||||||||||
| 1023 | } never executed: else {end of block | 0 | ||||||||||||||||||
| 1024 | l.list = cursor.createList(l.format); | - | ||||||||||||||||||
| 1025 | const qreal listTopMargin = topMargin(l.listNode); | - | ||||||||||||||||||
| 1026 | if (listTopMargin > block.topMargin()
| 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
| 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
| 0 | ||||||||||||||||||
| 1040 | forceBlockMerging = true; never executed: forceBlockMerging = true; | 0 | ||||||||||||||||||
| 1041 | - | |||||||||||||||||||
| 1042 | if (currentNode->isEmptyParagraph
| 0 | ||||||||||||||||||
| 1043 | hasBlock = false; | - | ||||||||||||||||||
| 1044 | return never executed: ContinueWithNextSibling;return ContinueWithNextSibling;never executed: return ContinueWithNextSibling; | 0 | ||||||||||||||||||
| 1045 | } | - | ||||||||||||||||||
| 1046 | - | |||||||||||||||||||
| 1047 | hasBlock = true; | - | ||||||||||||||||||
| 1048 | blockTagClosed = false; | - | ||||||||||||||||||
| 1049 | return never executed: ContinueWithCurrentNode;return ContinueWithCurrentNode;never executed: return ContinueWithCurrentNode; | 0 | ||||||||||||||||||
| 1050 | } | - | ||||||||||||||||||
| 1051 | - | |||||||||||||||||||
| 1052 | void QTextHtmlImporter::appendBlock(const QTextBlockFormat &format, QTextCharFormat charFmt) | - | ||||||||||||||||||
| 1053 | { | - | ||||||||||||||||||
| 1054 | if (!namedAnchors.isEmpty()
| 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
| 0 | ||||||||||||||||||
| 1063 | compressNextWhitespace = RemoveWhiteSpace; never executed: compressNextWhitespace = RemoveWhiteSpace; | 0 | ||||||||||||||||||
| 1064 | } never executed: end of block | 0 | ||||||||||||||||||
| 1065 | QTextDocumentFragment QTextDocumentFragment::fromHtml(const QString &html) | - | ||||||||||||||||||
| 1066 | { | - | ||||||||||||||||||
| 1067 | return never executed: fromHtml(html, 0);return fromHtml(html, 0);never executed: return fromHtml(html, 0); | 0 | ||||||||||||||||||
| 1068 | } | - | ||||||||||||||||||
| 1069 | QTextDocumentFragment 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: res;return res;never executed: return res; | 0 | ||||||||||||||||||
| 1077 | } | - | ||||||||||||||||||
| 1078 | - | |||||||||||||||||||
| 1079 | - | |||||||||||||||||||
| Switch to Source code | Preprocessed file |