Qt 4.8
qtextdocumentfragment.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qtextdocumentfragment.h"
44 #include "qtextcursor_p.h"
45 #include "qtextlist.h"
46 
47 #include <qdebug.h>
48 #include <qtextcodec.h>
49 #include <qbytearray.h>
50 #include <qdatastream.h>
51 #include <qdatetime.h>
52 
54 
55 QTextCopyHelper::QTextCopyHelper(const QTextCursor &_source, const QTextCursor &_destination, bool forceCharFormat, const QTextCharFormat &fmt)
56 #if defined(Q_CC_DIAB) // compiler bug
57  : formatCollection(*_destination.d->priv->formatCollection()), originalText((const QString)_source.d->priv->buffer())
58 #else
59  : formatCollection(*_destination.d->priv->formatCollection()), originalText(_source.d->priv->buffer())
60 #endif
61 {
62  src = _source.d->priv;
63  dst = _destination.d->priv;
64  insertPos = _destination.position();
65  this->forceCharFormat = forceCharFormat;
66  primaryCharFormatIndex = convertFormatIndex(fmt);
67  cursor = _source;
68 }
69 
70 int QTextCopyHelper::convertFormatIndex(const QTextFormat &oldFormat, int objectIndexToSet)
71 {
72  QTextFormat fmt = oldFormat;
73  if (objectIndexToSet != -1) {
74  fmt.setObjectIndex(objectIndexToSet);
75  } else if (fmt.objectIndex() != -1) {
76  int newObjectIndex = objectIndexMap.value(fmt.objectIndex(), -1);
77  if (newObjectIndex == -1) {
79  Q_ASSERT(objFormat.objectIndex() == -1);
80  newObjectIndex = formatCollection.createObjectIndex(objFormat);
81  objectIndexMap.insert(fmt.objectIndex(), newObjectIndex);
82  }
83  fmt.setObjectIndex(newObjectIndex);
84  }
85  int idx = formatCollection.indexForFormat(fmt);
86  Q_ASSERT(formatCollection.format(idx).type() == oldFormat.type());
87  return idx;
88 }
89 
90 int QTextCopyHelper::appendFragment(int pos, int endPos, int objectIndex)
91 {
93  const QTextFragmentData * const frag = fragIt.value();
94 
95  Q_ASSERT(objectIndex == -1
96  || (frag->size_array[0] == 1 && src->formatCollection()->format(frag->format).objectIndex() != -1));
97 
98  int charFormatIndex;
99  if (forceCharFormat)
100  charFormatIndex = primaryCharFormatIndex;
101  else
102  charFormatIndex = convertFormatIndex(frag->format, objectIndex);
103 
104  const int inFragmentOffset = qMax(0, pos - fragIt.position());
105  int charsToCopy = qMin(int(frag->size_array[0] - inFragmentOffset), endPos - pos);
106 
107  QTextBlock nextBlock = src->blocksFind(pos + 1);
108 
109  int blockIdx = -2;
110  if (nextBlock.position() == pos + 1) {
111  blockIdx = convertFormatIndex(nextBlock.blockFormat());
112  } else if (pos == 0 && insertPos == 0) {
114  dst->setCharFormat(-1, 1, convertFormat(src->blocksBegin().charFormat()).toCharFormat());
115  }
116 
117  QString txtToInsert(originalText.constData() + frag->stringPosition + inFragmentOffset, charsToCopy);
118  if (txtToInsert.length() == 1
119  && (txtToInsert.at(0) == QChar::ParagraphSeparator
120  || txtToInsert.at(0) == QTextBeginningOfFrame
121  || txtToInsert.at(0) == QTextEndOfFrame
122  )
123  ) {
124  dst->insertBlock(txtToInsert.at(0), insertPos, blockIdx, charFormatIndex);
125  ++insertPos;
126  } else {
127  if (nextBlock.textList()) {
128  QTextBlock dstBlock = dst->blocksFind(insertPos);
129  if (!dstBlock.textList()) {
130  // insert a new text block with the block and char format from the
131  // source block to make sure that the following text fragments
132  // end up in a list as they should
133  int listBlockFormatIndex = convertFormatIndex(nextBlock.blockFormat());
134  int listCharFormatIndex = convertFormatIndex(nextBlock.charFormat());
135  dst->insertBlock(insertPos, listBlockFormatIndex, listCharFormatIndex);
136  ++insertPos;
137  }
138  }
139  dst->insert(insertPos, txtToInsert, charFormatIndex);
140  const int userState = nextBlock.userState();
141  if (userState != -1)
142  dst->blocksFind(insertPos).setUserState(userState);
143  insertPos += txtToInsert.length();
144  }
145 
146  return charsToCopy;
147 }
148 
149 void QTextCopyHelper::appendFragments(int pos, int endPos)
150 {
151  Q_ASSERT(pos < endPos);
152 
153  while (pos < endPos)
154  pos += appendFragment(pos, endPos);
155 }
156 
158 {
159  if (cursor.hasComplexSelection()) {
160  QTextTable *table = cursor.currentTable();
161  int row_start, col_start, num_rows, num_cols;
162  cursor.selectedTableCells(&row_start, &num_rows, &col_start, &num_cols);
163 
164  QTextTableFormat tableFormat = table->format();
165  tableFormat.setColumns(num_cols);
166  tableFormat.clearColumnWidthConstraints();
167  const int objectIndex = dst->formatCollection()->createObjectIndex(tableFormat);
168 
169  Q_ASSERT(row_start != -1);
170  for (int r = row_start; r < row_start + num_rows; ++r) {
171  for (int c = col_start; c < col_start + num_cols; ++c) {
172  QTextTableCell cell = table->cellAt(r, c);
173  const int rspan = cell.rowSpan();
174  const int cspan = cell.columnSpan();
175  if (rspan != 1) {
176  int cr = cell.row();
177  if (cr != r)
178  continue;
179  }
180  if (cspan != 1) {
181  int cc = cell.column();
182  if (cc != c)
183  continue;
184  }
185 
186  // add the QTextBeginningOfFrame
187  QTextCharFormat cellFormat = cell.format();
188  if (r + rspan >= row_start + num_rows) {
189  cellFormat.setTableCellRowSpan(row_start + num_rows - r);
190  }
191  if (c + cspan >= col_start + num_cols) {
192  cellFormat.setTableCellColumnSpan(col_start + num_cols - c);
193  }
194  const int charFormatIndex = convertFormatIndex(cellFormat, objectIndex);
195 
196  int blockIdx = -2;
197  const int cellPos = cell.firstPosition();
198  QTextBlock block = src->blocksFind(cellPos);
199  if (block.position() == cellPos) {
200  blockIdx = convertFormatIndex(block.blockFormat());
201  }
202 
203  dst->insertBlock(QTextBeginningOfFrame, insertPos, blockIdx, charFormatIndex);
204  ++insertPos;
205 
206  // nothing to add for empty cells
207  if (cell.lastPosition() > cellPos) {
208  // add the contents
209  appendFragments(cellPos, cell.lastPosition());
210  }
211  }
212  }
213 
214  // add end of table
215  int end = table->lastPosition();
216  appendFragment(end, end+1, objectIndex);
217  } else {
219  }
220 }
221 
223  : ref(1), doc(new QTextDocument), importedFromPlainText(false)
224 {
225  doc->setUndoRedoEnabled(false);
226 
227  if (!_cursor.hasSelection())
228  return;
229 
231  QTextCursor destCursor(doc);
232  QTextCopyHelper(_cursor, destCursor).copy();
233  doc->docHandle()->endEditBlock();
234 
235  if (_cursor.d)
236  doc->docHandle()->mergeCachedResources(_cursor.d->priv);
237 }
238 
240 {
241  if (_cursor.isNull())
242  return;
243 
244  QTextDocumentPrivate *destPieceTable = _cursor.d->priv;
245  destPieceTable->beginEditBlock();
246 
247  QTextCursor sourceCursor(doc);
249  QTextCopyHelper(sourceCursor, _cursor, importedFromPlainText, _cursor.charFormat()).copy();
250 
251  destPieceTable->endEditBlock();
252 }
253 
285  : d(0)
286 {
287 }
288 
295  : d(0)
296 {
297  if (!document)
298  return;
299 
300  QTextCursor cursor(const_cast<QTextDocument *>(document));
302  d = new QTextDocumentFragmentPrivate(cursor);
303 }
304 
312  : d(0)
313 {
314  if (!cursor.hasSelection())
315  return;
316 
317  d = new QTextDocumentFragmentPrivate(cursor);
318 }
319 
329  : d(rhs.d)
330 {
331  if (d)
332  d->ref.ref();
333 }
334 
344 {
345  if (rhs.d)
346  rhs.d->ref.ref();
347  if (d && !d->ref.deref())
348  delete d;
349  d = rhs.d;
350  return *this;
351 }
352 
357 {
358  if (d && !d->ref.deref())
359  delete d;
360 }
361 
366 {
367  return !d || !d->doc || d->doc->docHandle()->length() <= 1;
368 }
369 
377 {
378  if (!d)
379  return QString();
380 
381  return d->doc->toPlainText();
382 }
383 
384 // #### Qt 5: merge with other overload
389 #ifndef QT_NO_TEXTHTMLPARSER
390 
392 {
393  return toHtml(QByteArray());
394 }
395 
408 {
409  if (!d)
410  return QString();
411 
413 }
414 
415 #endif // QT_NO_TEXTHTMLPARSER
416 
424 {
426 
428  res.d->importedFromPlainText = true;
429  QTextCursor cursor(res.d->doc);
430  cursor.insertText(plainText);
431  return res;
432 }
433 
435 {
436  if (style == QTextListFormat::ListDisc)
438  else if (style == QTextListFormat::ListCircle)
440  return style;
441 }
442 
443 #ifndef QT_NO_TEXTHTMLPARSER
444 
445 QTextHtmlImporter::QTextHtmlImporter(QTextDocument *_doc, const QString &_html, ImportMode mode, const QTextDocument *resourceProvider)
446  : indent(0), compressNextWhitespace(PreserveWhiteSpace), doc(_doc), importMode(mode)
447 {
450 
451  QString html = _html;
452  const int startFragmentPos = html.indexOf(QLatin1String("<!--StartFragment-->"));
453  if (startFragmentPos != -1) {
454  QString qt3RichTextHeader(QLatin1String("<meta name=\"qrichtext\" content=\"1\" />"));
455 
456  // Hack for Qt3
457  const bool hasQtRichtextMetaTag = html.contains(qt3RichTextHeader);
458 
459  const int endFragmentPos = html.indexOf(QLatin1String("<!--EndFragment-->"));
460  if (startFragmentPos < endFragmentPos)
461  html = html.mid(startFragmentPos, endFragmentPos - startFragmentPos);
462  else
463  html = html.mid(startFragmentPos);
464 
465  if (hasQtRichtextMetaTag)
466  html.prepend(qt3RichTextHeader);
467  }
468 
469  parse(html, resourceProvider ? resourceProvider : doc);
470 // dumpHtml();
471 }
472 
474 {
476  hasBlock = true;
477  forceBlockMerging = false;
479  blockTagClosed = false;
483 
484  /*
485  * process each node in three stages:
486  * 1) check if the hierarchy changed and we therefore passed the
487  * equivalent of a closing tag -> we may need to finish off
488  * some structures like tables
489  *
490  * 2) check if the current node is a special node like a
491  * <table>, <ul> or <img> tag that requires special processing
492  *
493  * 3) if the node should result in a QTextBlock create one and
494  * finally insert text that may be attached to the node
495  */
496 
497  /* emit 'closing' table blocks or adjust current indent level
498  * if we
499  * 1) are beyond the first node
500  * 2) the current node not being a child of the previous node
501  * means there was a tag closing in the input html
502  */
503  if (currentNodeIdx > 0 && (currentNode->parent != currentNodeIdx - 1)) {
505  // visually collapse subsequent block tags, but if the element after the closed block tag
506  // is for example an inline element (!isBlock) we have to make sure we start a new paragraph by setting
507  // hasBlock to false.
508  if (blockTagClosed
509  && !currentNode->isBlock()
510  && currentNode->id != Html_unknown)
511  {
512  hasBlock = false;
513  } else if (hasBlock) {
514  // when collapsing subsequent block tags we need to clear the block format
516  blockFormat.setIndent(indent);
517 
518  QTextBlockFormat oldFormat = cursor.blockFormat();
519  if (oldFormat.hasProperty(QTextFormat::PageBreakPolicy)) {
520  QTextFormat::PageBreakFlags pageBreak = oldFormat.pageBreakPolicy();
521  if (pageBreak == QTextFormat::PageBreak_AlwaysAfter)
522  /* We remove an empty paragrah that requested a page break after.
523  moving that request to the next paragraph means we also need to make
524  that a pagebreak before to keep the same visual appearance.
525  */
527  blockFormat.setPageBreakPolicy(pageBreak);
528  }
529 
530  cursor.setBlockFormat(blockFormat);
531  }
532  }
533 
535  if (currentNode->id == Html_title)
537  // ignore explicitly 'invisible' elements
538  continue;
539  }
540 
542  continue;
543 
544  // make sure there's a block for 'Blah' after <ul><li>foo</ul>Blah
545  if (blockTagClosed
546  && !hasBlock
547  && !currentNode->isBlock()
550 
552  block.setIndent(indent);
553 
555 
556  hasBlock = true;
557  }
558 
559  if (currentNode->isBlock()) {
561  if (result == ContinueWithNextNode) {
562  continue;
563  } else if (result == ContinueWithNextSibling) {
565  continue;
566  }
567  }
568 
571  }
572 
573  if (appendNodeText())
574  hasBlock = false; // if we actually appended text then we don't
575  // have an empty block anymore
576  }
577 
579 }
580 
582 {
583  const int initialCursorPosition = cursor.position();
585 
588 
590 
591  QString textToInsert;
592  textToInsert.reserve(text.size());
593 
594  for (int i = 0; i < text.length(); ++i) {
595  QChar ch = text.at(i);
596 
597  if (ch.isSpace()
598  && ch != QChar::Nbsp
599  && ch != QChar::ParagraphSeparator) {
600 
602  compressNextWhitespace = RemoveWhiteSpace; // allow this one, and remove the ones coming next.
604  continue;
605 
607  || textEditMode
608  ) {
609  if (ch == QLatin1Char('\n')) {
610  if (textEditMode)
611  continue;
612  } else if (ch == QLatin1Char('\r')) {
613  continue;
614  }
618  ch = QChar::Nbsp;
619  else
620  ch = QLatin1Char(' ');
621  }
622  } else {
624  }
625 
626  if (ch == QLatin1Char('\n')
627  || ch == QChar::ParagraphSeparator) {
628 
629  if (!textToInsert.isEmpty()) {
630  cursor.insertText(textToInsert, format);
631  textToInsert.clear();
632  }
633 
635 
637  QTextBlockFormat tmp = fmt;
639  cursor.setBlockFormat(tmp);
640  }
641 
643  appendBlock(fmt, cursor.charFormat());
644  } else {
645  if (!namedAnchors.isEmpty()) {
646  if (!textToInsert.isEmpty()) {
647  cursor.insertText(textToInsert, format);
648  textToInsert.clear();
649  }
650 
651  format.setAnchor(true);
653  cursor.insertText(ch, format);
657  } else {
658  textToInsert += ch;
659  }
660  }
661  }
662 
663  if (!textToInsert.isEmpty()) {
664  cursor.insertText(textToInsert, format);
665  }
666 
667  return cursor.position() != initialCursorPosition;
668 }
669 
671 {
672  switch (currentNode->id) {
673  case Html_body:
677  doc->rootFrame()->setFrameFormat(fmt);
678  const_cast<QTextHtmlParserNode *>(currentNode)->charFormat.clearProperty(QTextFormat::BackgroundBrush);
679  }
681  break;
682 
683  case Html_ol:
684  case Html_ul: {
686 
689  while (n) {
690  if (n->id == Html_ul) {
692  }
693  if (n->parent)
694  n = &at(n->parent);
695  else
696  n = 0;
697  }
698  }
699 
700  QTextListFormat listFmt;
701  listFmt.setStyle(style);
706 
707  ++indent;
710  else
711  listFmt.setIndent(indent);
712 
713  List l;
714  l.format = listFmt;
716  lists.append(l);
718 
719  // broken html: <ul>Text here<li>Foo
720  const QString simpl = currentNode->text.simplified();
721  if (simpl.isEmpty() || simpl.at(0).isSpace())
722  return ContinueWithNextNode;
723  break;
724  }
725 
726  case Html_table: {
728  tables.append(t);
729  hasBlock = false;
731  return ContinueWithNextNode;
732  }
733 
734  case Html_tr:
735  return ContinueWithNextNode;
736 
737  case Html_img: {
738  QTextImageFormat fmt;
740 
742 
743  if (currentNode->imageWidth != -1)
745  if (currentNode->imageHeight != -1)
747 
749 
754 
755  hasBlock = false;
756  return ContinueWithNextNode;
757  }
758 
759  case Html_hr: {
761  blockFormat.setTopMargin(topMargin(currentNodeIdx));
765  cursor.mergeBlockFormat(blockFormat);
766  else
767  appendBlock(blockFormat);
768  hasBlock = false;
770  return ContinueWithNextNode;
771  }
772 
773  default: break;
774  }
776 }
777 
778 // returns true if a block tag was closed
780 {
781  const QTextHtmlParserNode *closedNode = &at(currentNodeIdx - 1);
782  const int endDepth = depth(currentNodeIdx) - 1;
783  int depth = this->depth(currentNodeIdx - 1);
784  bool blockTagClosed = false;
785 
786  while (depth > endDepth) {
787  Table *t = 0;
788  if (!tables.isEmpty())
789  t = &tables.last();
790 
791  switch (closedNode->id) {
792  case Html_tr:
793  if (t && !t->isTextFrame) {
794  ++t->currentRow;
795 
796  // for broken html with rowspans but missing tr tags
797  while (!t->currentCell.atEnd() && t->currentCell.row < t->currentRow)
798  ++t->currentCell;
799  }
800 
801  blockTagClosed = true;
802  break;
803 
804  case Html_table:
805  if (!t)
806  break;
807  indent = t->lastIndent;
808 
809  tables.resize(tables.size() - 1);
810  t = 0;
811 
812  if (tables.isEmpty()) {
814  } else {
815  t = &tables.last();
816  if (t->isTextFrame)
818  else if (!t->currentCell.atEnd())
820  }
821 
822  // we don't need an extra block after tables, so we don't
823  // claim to have closed one for the creation of a new one
824  // in import()
825  blockTagClosed = false;
827  break;
828 
829  case Html_th:
830  case Html_td:
831  if (t && !t->isTextFrame)
832  ++t->currentCell;
833  blockTagClosed = true;
835  break;
836 
837  case Html_ol:
838  case Html_ul:
839  if (lists.isEmpty())
840  break;
841  lists.resize(lists.size() - 1);
842  --indent;
843  blockTagClosed = true;
844  break;
845 
846  case Html_br:
848  break;
849 
850  case Html_div:
851  if (closedNode->children.isEmpty())
852  break;
853  // fall through
854  default:
855  if (closedNode->isBlock())
856  blockTagClosed = true;
857  break;
858  }
859 
860  closedNode = &at(closedNode->parent);
861  --depth;
862  }
863 
864  return blockTagClosed;
865 }
866 
868 {
869  Table table;
870  table.columns = 0;
871 
872  QVector<QTextLength> columnWidths;
873 
874  int tableHeaderRowCount = 0;
875  QVector<int> rowNodes;
876  rowNodes.reserve(at(tableNodeIdx).children.count());
877  foreach (int row, at(tableNodeIdx).children)
878  switch (at(row).id) {
879  case Html_tr:
880  rowNodes += row;
881  break;
882  case Html_thead:
883  case Html_tbody:
884  case Html_tfoot:
885  foreach (int potentialRow, at(row).children)
886  if (at(potentialRow).id == Html_tr) {
887  rowNodes += potentialRow;
888  if (at(row).id == Html_thead)
889  ++tableHeaderRowCount;
890  }
891  break;
892  default: break;
893  }
894 
895  QVector<RowColSpanInfo> rowColSpans;
896  QVector<RowColSpanInfo> rowColSpanForColumn;
897 
898  int effectiveRow = 0;
899  foreach (int row, rowNodes) {
900  int colsInRow = 0;
901 
902  foreach (int cell, at(row).children)
903  if (at(cell).isTableCell()) {
904  // skip all columns with spans from previous rows
905  while (colsInRow < rowColSpanForColumn.size()) {
906  const RowColSpanInfo &spanInfo = rowColSpanForColumn[colsInRow];
907 
908  if (spanInfo.row + spanInfo.rowSpan > effectiveRow) {
909  Q_ASSERT(spanInfo.col == colsInRow);
910  colsInRow += spanInfo.colSpan;
911  } else
912  break;
913  }
914 
915  const QTextHtmlParserNode &c = at(cell);
916  const int currentColumn = colsInRow;
917  colsInRow += c.tableCellColSpan;
918 
919  RowColSpanInfo spanInfo;
920  spanInfo.row = effectiveRow;
921  spanInfo.col = currentColumn;
922  spanInfo.colSpan = c.tableCellColSpan;
923  spanInfo.rowSpan = c.tableCellRowSpan;
924  if (spanInfo.colSpan > 1 || spanInfo.rowSpan > 1)
925  rowColSpans.append(spanInfo);
926 
927  columnWidths.resize(qMax(columnWidths.count(), colsInRow));
928  rowColSpanForColumn.resize(columnWidths.size());
929  for (int i = currentColumn; i < currentColumn + c.tableCellColSpan; ++i) {
930  if (columnWidths.at(i).type() == QTextLength::VariableLength) {
931  QTextLength w = c.width;
933  w = QTextLength(w.type(), w.value(100.) / c.tableCellColSpan);
934  columnWidths[i] = w;
935  }
936  rowColSpanForColumn[i] = spanInfo;
937  }
938  }
939 
940  table.columns = qMax(table.columns, colsInRow);
941 
942  ++effectiveRow;
943  }
944  table.rows = effectiveRow;
945 
946  table.lastIndent = indent;
947  indent = 0;
948 
949  if (table.rows == 0 || table.columns == 0)
950  return table;
951 
952  QTextFrameFormat fmt;
953  const QTextHtmlParserNode &node = at(tableNodeIdx);
954 
955  if (!node.isTextFrame) {
956  QTextTableFormat tableFmt;
957  tableFmt.setCellSpacing(node.tableCellSpacing);
958  tableFmt.setCellPadding(node.tableCellPadding);
960  tableFmt.setAlignment(node.blockFormat.alignment());
961  tableFmt.setColumns(table.columns);
962  tableFmt.setColumnWidthConstraints(columnWidths);
963  tableFmt.setHeaderRowCount(tableHeaderRowCount);
964  fmt = tableFmt;
965  }
966 
967  fmt.setTopMargin(topMargin(tableNodeIdx));
968  fmt.setBottomMargin(bottomMargin(tableNodeIdx));
969  fmt.setLeftMargin(leftMargin(tableNodeIdx)
970  + table.lastIndent * 40 // ##### not a good emulation
971  );
972  fmt.setRightMargin(rightMargin(tableNodeIdx));
973 
974  // compatibility
975  if (qFuzzyCompare(fmt.leftMargin(), fmt.rightMargin())
976  && qFuzzyCompare(fmt.leftMargin(), fmt.topMargin())
977  && qFuzzyCompare(fmt.leftMargin(), fmt.bottomMargin()))
979 
980  fmt.setBorderStyle(node.borderStyle);
981  fmt.setBorderBrush(node.borderBrush);
982  fmt.setBorder(node.tableBorder);
983  fmt.setWidth(node.width);
984  fmt.setHeight(node.height);
987 
990  if (node.charFormat.background().style() != Qt::NoBrush)
991  fmt.setBackground(node.charFormat.background());
993 
994  if (node.isTextFrame) {
995  if (node.isRootFrame) {
996  table.frame = cursor.currentFrame();
997  table.frame->setFrameFormat(fmt);
998  } else
999  table.frame = cursor.insertFrame(fmt);
1000 
1001  table.isTextFrame = true;
1002  } else {
1003  const int oldPos = cursor.position();
1004  QTextTable *textTable = cursor.insertTable(table.rows, table.columns, fmt.toTableFormat());
1005  table.frame = textTable;
1006 
1007  for (int i = 0; i < rowColSpans.count(); ++i) {
1008  const RowColSpanInfo &nfo = rowColSpans.at(i);
1009  textTable->mergeCells(nfo.row, nfo.col, nfo.rowSpan, nfo.colSpan);
1010  }
1011 
1012  table.currentCell = TableCellIterator(textTable);
1013  cursor.setPosition(oldPos); // restore for caption support which needs to be inserted right before the table
1014  }
1015  return table;
1016 }
1017 
1019 {
1020  QTextBlockFormat block;
1021  QTextCharFormat charFmt;
1022  bool modifiedBlockFormat = true;
1023  bool modifiedCharFormat = true;
1024 
1025  if (currentNode->isTableCell() && !tables.isEmpty()) {
1026  Table &t = tables.last();
1027  if (!t.isTextFrame && !t.currentCell.atEnd()) {
1028  QTextTableCell cell = t.currentCell.cell();
1029  if (cell.isValid()) {
1031  if (topPadding(currentNodeIdx) >= 0)
1033  if (bottomPadding(currentNodeIdx) >= 0)
1035  if (leftPadding(currentNodeIdx) >= 0)
1037  if (rightPadding(currentNodeIdx) >= 0)
1039  cell.setFormat(fmt);
1040 
1042  }
1043  }
1044  hasBlock = true;
1046 
1049  cursor.mergeBlockCharFormat(charFmt);
1050  }
1051  }
1052 
1053  if (hasBlock) {
1054  block = cursor.blockFormat();
1055  charFmt = cursor.blockCharFormat();
1056  modifiedBlockFormat = false;
1057  modifiedCharFormat = false;
1058  }
1059 
1060  // collapse
1061  {
1063  if (tm > block.topMargin()) {
1064  block.setTopMargin(tm);
1065  modifiedBlockFormat = true;
1066  }
1067  }
1068 
1070 
1071  // for list items we may want to collapse with the bottom margin of the
1072  // list.
1073  const QTextHtmlParserNode *parentNode = currentNode->parent ? &at(currentNode->parent) : 0;
1074  if ((currentNode->id == Html_li || currentNode->id == Html_dt || currentNode->id == Html_dd)
1075  && parentNode
1076  && (parentNode->isListStart() || parentNode->id == Html_dl)
1077  && (parentNode->children.last() == currentNodeIdx)) {
1078  bottomMargin = qMax(bottomMargin, this->bottomMargin(currentNode->parent));
1079  }
1080 
1081  if (block.bottomMargin() != bottomMargin) {
1082  block.setBottomMargin(bottomMargin);
1083  modifiedBlockFormat = true;
1084  }
1085 
1086  {
1087  const qreal lm = leftMargin(currentNodeIdx);
1088  const qreal rm = rightMargin(currentNodeIdx);
1089 
1090  if (block.leftMargin() != lm) {
1091  block.setLeftMargin(lm);
1092  modifiedBlockFormat = true;
1093  }
1094  if (block.rightMargin() != rm) {
1095  block.setRightMargin(rm);
1096  modifiedBlockFormat = true;
1097  }
1098  }
1099 
1100  if (currentNode->id != Html_li
1101  && indent != 0
1102  && (lists.isEmpty()
1103  || !hasBlock
1104  || !lists.last().list
1105  || lists.last().list->itemNumber(cursor.block()) == -1
1106  )
1107  ) {
1108  block.setIndent(indent);
1109  modifiedBlockFormat = true;
1110  }
1111 
1112  if (currentNode->blockFormat.propertyCount() > 0) {
1113  modifiedBlockFormat = true;
1114  block.merge(currentNode->blockFormat);
1115  }
1116 
1117  if (currentNode->charFormat.propertyCount() > 0) {
1118  modifiedCharFormat = true;
1119  charFmt.merge(currentNode->charFormat);
1120  }
1121 
1122  // ####################
1123  // block.setFloatPosition(node->cssFloat);
1124 
1126  block.setNonBreakableLines(true);
1127  modifiedBlockFormat = true;
1128  }
1129 
1132  modifiedBlockFormat = true;
1133  }
1134 
1136  if (modifiedBlockFormat)
1137  cursor.setBlockFormat(block);
1138  if (modifiedCharFormat)
1139  cursor.setBlockCharFormat(charFmt);
1140  } else {
1141  if (currentNodeIdx == 1 && cursor.position() == 0 && currentNode->isEmptyParagraph) {
1142  cursor.setBlockFormat(block);
1143  cursor.setBlockCharFormat(charFmt);
1144  } else {
1145  appendBlock(block, charFmt);
1146  }
1147  }
1148 
1149  if (currentNode->userState != -1)
1151 
1152  if (currentNode->id == Html_li && !lists.isEmpty()) {
1153  List &l = lists.last();
1154  if (l.list) {
1155  l.list->add(cursor.block());
1156  } else {
1157  l.list = cursor.createList(l.format);
1158  const qreal listTopMargin = topMargin(l.listNode);
1159  if (listTopMargin > block.topMargin()) {
1160  block.setTopMargin(listTopMargin);
1161  cursor.mergeBlockFormat(block);
1162  }
1163  }
1164  if (hasBlock) {
1165  QTextBlockFormat fmt;
1166  fmt.setIndent(0);
1167  cursor.mergeBlockFormat(fmt);
1168  }
1169  }
1170 
1171  forceBlockMerging = false;
1173  forceBlockMerging = true;
1174 
1176  hasBlock = false;
1177  return ContinueWithNextSibling;
1178  }
1179 
1180  hasBlock = true;
1181  blockTagClosed = false;
1182  return ContinueWithCurrentNode;
1183 }
1184 
1186 {
1187  if (!namedAnchors.isEmpty()) {
1188  charFmt.setAnchor(true);
1189  charFmt.setAnchorNames(namedAnchors);
1190  namedAnchors.clear();
1191  }
1192 
1193  cursor.insertBlock(format, charFmt);
1194 
1197 }
1198 
1199 #endif // QT_NO_TEXTHTMLPARSER
1200 
1213 #ifndef QT_NO_TEXTHTMLPARSER
1214 
1216 {
1217  return fromHtml(html, 0);
1218 }
1219 
1234 {
1236  res.d = new QTextDocumentFragmentPrivate;
1237 
1238  QTextHtmlImporter importer(res.d->doc, html, QTextHtmlImporter::ImportToFragment, resourceProvider);
1239  importer.import();
1240  return res;
1241 }
1242 
1244 #endif // QT_NO_TEXTHTMLPARSER
int objectIndex() const
Returns the index of the format object, or -1 if the format object is invalid.
void setRightPadding(qreal padding)
Sets the right padding of the table cell.
Definition: qtextformat.h:954
QBool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.h:904
double d
Definition: qnumeric_p.h:62
QTextTable * insertTable(int rows, int cols, const QTextTableFormat &format)
Creates a new table with the given number of rows and columns in the specified format, inserts it at the current cursor position() in the document, and returns the table object.
void endEditBlock()
Indicates the end of a block of editing operations on the document that should appear as a single ope...
void setBorderBrush(const QBrush &brush)
Sets the brush used for the frame&#39;s border.
Definition: qtextformat.h:765
QMap< int, int > objectIndexMap
The QTextCharFormat class provides formatting information for characters in a QTextDocument.
Definition: qtextformat.h:372
double qreal
Definition: qglobal.h:1193
The QTextListFormat class provides formatting information for lists in a QTextDocument.
Definition: qtextformat.h:642
QString toHtml() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
unsigned char c[8]
Definition: qnumeric_p.h:62
QTextCharFormat charFormat() const
Returns the format of the character immediately before the cursor position().
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
QTextFrameFormat::BorderStyle borderStyle
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
~QTextDocumentFragment()
Destroys the document fragment.
Table scanTable(int tableNodeIdx)
QTextFormatCollection & formatCollection
QTextList * textList() const
If the block represents a list item, returns the list that the item belongs to; otherwise returns 0...
const QTextDocument * resourceProvider
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
int rightMargin(int i) const
void setUserState(int state)
Stores the specified state integer value in the text block.
void setBorder(qreal border)
Sets the width (in pixels) of the frame&#39;s border.
Definition: qtextformat.h:816
QVector< int > children
void appendFragments(int pos, int endPos)
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
void setBorderStyle(BorderStyle style)
Sets the style of the frame&#39;s border.
Definition: qtextformat.h:770
void setProperty(int propertyId, const QVariant &value)
Sets the property specified by the propertyId to the given value.
Type type() const
Returns the type of this length object.
Definition: qtextformat.h:93
QTextFrame * insertFrame(const QTextFrameFormat &format)
Inserts a frame with the given format at the current cursor position(), moves the cursor position() i...
Position
This enum describes how a frame is located relative to the surrounding text.
Definition: qtextformat.h:734
int selectionEnd() const
Returns the end of the selection or position() if the cursor doesn&#39;t have a selection.
QTextTableCellFormat toTableCellFormat() const
Returns this format as a table cell format.
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
PageBreakFlags pageBreakPolicy() const
Returns the currently set page break policy for the paragraph.
Definition: qtextformat.h:608
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
void setBlockCharFormat(const QTextCharFormat &format)
Sets the block char format of the current block (or all blocks that are contained in the selection) t...
QString & prepend(QChar c)
Definition: qstring.h:261
void setIndent(int indent)
Sets the list format&#39;s indentation.
Definition: qtextformat.h:685
void insertImage(const QTextImageFormat &format, QTextFrameFormat::Position alignment)
Inserts the image defined by the given format at the cursor&#39;s current position with the specified ali...
QTextList * createList(const QTextListFormat &format)
Creates and returns a new list with the given format, and makes the current paragraph the cursor is i...
void setWidth(qreal width)
Convenience method that sets the width of the frame&#39;s border rectangle&#39;s width to the specified fixed...
Definition: qtextformat.h:822
QTextDocumentFragmentPrivate * d
QTextBlockFormat blockFormat() const
Returns the block format of the block the cursor is in.
int createObjectIndex(const QTextFormat &f)
const QTextHtmlParserNode & at(int i) const
void setCellPadding(qreal padding)
Sets the cell padding for the table.
Definition: qtextformat.h:892
QTextDocumentPrivate * dst
static Q_DECL_CONSTEXPR bool qFuzzyCompare(double p1, double p2)
Definition: qglobal.h:2030
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
QString anchorName() const
This function is deprecated.
#define QTextBeginningOfFrame
void setBlockFormat(const QTextBlock &from, const QTextBlock &to, const QTextBlockFormat &newFormat, FormatChangeMode mode=SetFormat)
bool ref()
Atomically increments the value of this QAtomicInt.
qreal leftMargin() const
Returns the width of the frame&#39;s left margin in pixels.
void setBackground(const QBrush &brush)
Sets the brush use to paint the document&#39;s background to the brush specified.
Definition: qtextformat.h:343
void setTableCellRowSpan(int tableCellRowSpan)
If this character format is applied to characters in a table cell, the cell will span tableCellRowSpa...
Definition: qtextformat.h:529
QTextTableFormat toTableFormat() const
Returns this format as a table format.
The QString class provides a Unicode character string.
Definition: qstring.h:83
QTextFormat format(int idx) const
qreal topMargin() const
Returns the paragraph&#39;s top margin.
Definition: qtextformat.h:566
void mergeCells(int row, int col, int numRows, int numCols)
Merges the cell at the specified row and column with the adjacent cells into one cell.
QTextFormat objectFormat(int objectIndex) const
void setLeftPadding(qreal padding)
Sets the left padding of the table cell.
Definition: qtextformat.h:944
qreal rightMargin() const
Returns the paragraph&#39;s right margin.
Definition: qtextformat.h:581
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
bool hasOnlyWhitespace() const
void mergeBlockFormat(const QTextBlockFormat &modifier)
Modifies the block format of the current block (or all blocks that are contained in the selection) wi...
Qt::Alignment alignment() const
Returns the paragraph&#39;s alignment.
Definition: qtextformat.h:561
QTextCursor lastCursorPosition() const
Returns the last valid cursor position in this cell.
Definition: qtexttable.cpp:259
QSharedDataPointer< QTextCursorPrivate > d
Definition: qtextcursor.h:230
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
QTextListFormat::Style listStyle
int insertBlock(int pos, int blockFormat, int charFormat, QTextUndoCommand::Operation=QTextUndoCommand::MoveCursor)
QString toPlainText() const
Returns the plain text contained in the document.
void insertText(const QString &text)
Inserts text at the current position, using the current character format.
int topPadding(int i) const
void insert(int pos, const QString &text, int format)
FragmentMap::ConstIterator FragmentIterator
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
bool isSpace() const
Returns true if the character is a separator character (Separator_* categories); otherwise returns fa...
Definition: qchar.cpp:609
Qt::LayoutDirection layoutDirection() const
Returns the document&#39;s layout direction.
Definition: qtextformat.h:340
const QString originalText
void setMetaInformation(MetaInformation info, const QString &)
Sets the document&#39;s meta information of the type specified by info to the given string.
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
void resize(int size)
Sets the size of the vector to size.
Definition: qvector.h:342
QTextHtmlParserNode::WhiteSpaceMode wsm
void setColumnWidthConstraints(const QVector< QTextLength > &constraints)
Sets the column width constraints for the table.
Definition: qtextformat.h:853
void setTopMargin(qreal margin)
Sets the paragraph&#39;s top margin.
Definition: qtextformat.h:564
int rowSpan() const
Returns the number of rows this cell spans.
Definition: qtexttable.cpp:218
QTextFrame * rootFrame() const
Returns the document&#39;s root frame.
void setAnchorNames(const QStringList &names)
Sets the text format&#39;s anchor names.
Definition: qtextformat.h:513
int position() const
Returns the index of the block&#39;s first character within the document.
void setPosition(Position f)
Sets the policy for positioning frames with this frame format.
Definition: qtextformat.h:756
int leftMargin(int i) const
QTextFrame * currentFrame() const
Returns a pointer to the current frame.
void setTopMargin(qreal margin)
Sets the frame&#39;s top margin in pixels.
Definition: qtextformat.h:830
void setTableCellColumnSpan(int tableCellColumnSpan)
If this character format is applied to characters in a table cell, the cell will span tableCellColumn...
Definition: qtextformat.h:537
void setLeftMargin(qreal margin)
Sets the paragraph&#39;s left margin.
Definition: qtextformat.h:574
void reserve(int size)
Attempts to allocate memory for at least size characters.
Definition: qstring.h:881
bool hasProperty(int propertyId) const
Returns true if the text format has a property with the given propertyId; otherwise returns false...
void selectedTableCells(int *firstRow, int *numRows, int *firstColumn, int *numColumns) const
If the selection spans over table cells, firstRow is populated with the number of the first row in th...
int type() const
Returns the type of this format.
QTextTableCell cellAt(int row, int col) const
Returns the table cell at the given row and column in the table.
Definition: qtexttable.cpp:630
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
QTextCharFormat charFormat
void setBottomMargin(qreal margin)
Sets the paragraph&#39;s bottom margin.
Definition: qtextformat.h:569
The QTextImageFormat class provides formatting information for images in a QTextDocument.
Definition: qtextformat.h:694
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
FragmentIterator find(int pos) const
qreal topMargin() const
Returns the width of the frame&#39;s top margin in pixels.
QTextCharFormat format() const
Returns the cell&#39;s character format.
Definition: qtexttable.cpp:153
QTextTableFormat format() const
Returns the table&#39;s format.
Definition: qtexttable.h:133
void setBottomPadding(qreal padding)
Sets the bottom padding of the table cell.
Definition: qtextformat.h:934
int column() const
Returns the number of the column in the table that contains this cell.
Definition: qtexttable.cpp:201
QTextBlock blocksBegin() const
qreal bottomMargin() const
Returns the width of the frame&#39;s bottom margin in pixels.
void setHeaderRowCount(int count)
Declares the first count rows of the table as table header.
Definition: qtextformat.h:875
int lastPosition() const
Returns the last document position inside the frame.
void appendBlock(const QTextBlockFormat &format, QTextCharFormat charFmt=QTextCharFormat())
static QTextDocumentFragment fromHtml(const QString &html)
Returns a QTextDocumentFragment based on the arbitrary piece of HTML in the given text...
bool hasSelection() const
Returns true if the cursor contains a selection; otherwise returns false.
QTextTable * currentTable() const
Returns a pointer to the current table if the cursor position() is inside a block that is part of a t...
void setPageBreakPolicy(PageBreakFlags flags)
Sets the page break policy for the frame/table to policy.
Definition: qtextformat.h:806
bool isAnchor() const
Returns true if the text is formatted as an anchor; otherwise returns false.
Definition: qtextformat.h:501
QTextDocumentFragment()
Constructs an empty QTextDocumentFragment.
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
Style
This enum describes the symbols used to decorate list items:
Definition: qtextformat.h:649
The QTextFormat class provides formatting information for a QTextDocument.
Definition: qtextformat.h:129
int bottomMargin(int i) const
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
void setBlockFormat(const QTextBlockFormat &format)
Sets the block format of the current block (or all blocks that are contained in the selection) to for...
QTextDocumentPrivate * docHandle() const
So that not all classes have to be friends of each other.
The QTextCursor class offers an API to access and modify QTextDocuments.
Definition: qtextcursor.h:70
void setName(const QString &name)
Sets the name of the image.
Definition: qtextformat.h:718
QTextFormatCollection * formatCollection()
const T value(const Key &key) const
Returns the value associated with the key key.
Definition: qmap.h:499
bool deref()
Atomically decrements the value of this QAtomicInt.
void setPageBreakPolicy(PageBreakFlags flags)
Sets the page break policy for the paragraph to policy.
Definition: qtextformat.h:606
QTextBlockFormat blockFormat
static QTextDocumentFragment fromPlainText(const QString &plainText)
Returns a document fragment that contains the given plainText.
void setFormat(const QTextCharFormat &format)
Sets the cell&#39;s character format to format.
Definition: qtexttable.cpp:134
QTextCopyHelper(const QTextCursor &_source, const QTextCursor &_destination, bool forceCharFormat=false, const QTextCharFormat &fmt=QTextCharFormat())
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
bool isEmpty() const
Returns true if the fragment is empty; otherwise returns false.
The QTextBlock class provides a container for text fragments in a QTextDocument.
Definition: qtextobject.h:199
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
int topMargin(int i) const
void mergeBlockCharFormat(const QTextCharFormat &modifier)
Modifies the block char format of the current block (or all blocks that are contained in the selectio...
QTextDocumentFragment & operator=(const QTextDocumentFragment &rhs)
Assigns the other fragment to this fragment.
int convertFormatIndex(const QTextFormat &oldFormat, int objectIndexToSet=-1)
int bottomPadding(int i) const
void setNumberPrefix(const QString &numberPrefix)
Sets the list format&#39;s number prefix to the string specified by numberPrefix.
Definition: qtextformat.h:688
QString toHtml(const QByteArray &encoding, ExportMode mode=ExportEntireDocument)
Returns the document in HTML format.
int row() const
Returns the number of the row in the table that contains this cell.
Definition: qtexttable.cpp:184
void clear()
Removes all items from the list.
Definition: qlist.h:764
int position() const
Returns the absolute position of the cursor within the document.
QBrush background() const
Returns the brush used to paint the document&#39;s background.
Definition: qtextformat.h:345
Qt::BrushStyle style() const
Returns the brush style.
Definition: qbrush.h:182
The QTextTable class represents a table in a QTextDocument.
Definition: qtexttable.h:103
QTextHTMLElements id
void setNonBreakableLines(bool b)
If b is true, the lines in the paragraph are treated as non-breakable; otherwise they are breakable...
Definition: qtextformat.h:601
void mergeCharFormat(const QTextCharFormat &modifier)
Merges the cursor&#39;s current character format with the properties described by format modifier...
void insert(QTextCursor &cursor) const
QTextCharFormat charFormat() const
Returns the QTextCharFormat that describes the block&#39;s character format.
QTextBlock block() const
Returns the block that contains the cursor.
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
QTextCharFormat blockCharFormat() const
Returns the block character format of the block the cursor is in.
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition: qstring.h:505
void insertBlock()
Inserts a new empty block at the cursor position() with the current blockFormat() and charFormat()...
void setColumns(int columns)
Sets the number of columns required by the table format.
Definition: qtextformat.h:885
int userState() const
Returns the integer value previously set with setUserState() or -1.
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
QTextDocumentFragmentPrivate(const QTextCursor &cursor=QTextCursor())
void beginEditBlock()
Indicates the start of a block of editing operations on the document that should appear as a single o...
void setCellSpacing(qreal spacing)
Sets the cell spacing for the table.
Definition: qtextformat.h:864
static QTextListFormat::Style nextListStyle(QTextListFormat::Style style)
void merge(const QTextFormat &other)
Merges the other format with this format; where there are conflicts the other format takes precedence...
void setNumberSuffix(const QString &numberSuffix)
Sets the list format&#39;s number suffix to the string specified by numberSuffix.
Definition: qtextformat.h:691
int firstPosition() const
Returns the first valid position in the document occupied by this cell.
Definition: qtexttable.cpp:273
QString simplified() const Q_REQUIRED_RESULT
Returns a string that has whitespace removed from the start and the end, and that has each sequence o...
Definition: qstring.cpp:4415
void clear()
Clears the contents of the string and makes it empty.
Definition: qstring.h:723
QString buffer() const
void setAlignment(Qt::Alignment alignment)
Sets the table&#39;s alignment.
Definition: qtextformat.h:895
void mergeCachedResources(const QTextDocumentPrivate *priv)
iterator insert(const Key &key, const T &value)
Inserts a new item with the key key and a value of value.
Definition: qmap.h:559
quint32 size_array[N]
void setHeight(qreal height)
Sets the height of the rectangle occupied by the image.
Definition: qtextformat.h:724
void setLeftMargin(qreal margin)
Sets the frame&#39;s left margin in pixels.
Definition: qtextformat.h:836
void setHeight(qreal height)
Sets the frame&#39;s height.
Definition: qtextformat.h:825
qreal bottomMargin() const
Returns the paragraph&#39;s bottom margin.
Definition: qtextformat.h:571
T & last()
Returns a reference to the last item in the vector.
Definition: qvector.h:262
qreal rightMargin() const
Returns the width of the frame&#39;s right margin in pixels.
void setTopPadding(qreal padding)
Sets the top padding of the table cell.
Definition: qtextformat.h:924
The QTextFrameFormat class provides formatting information for frames in a QTextDocument.
Definition: qtextformat.h:727
The QTextTableCell class represents the properties of a cell in a QTextTable.
Definition: qtexttable.h:59
int appendFragment(int pos, int endPos, int objectIndex=-1)
bool hasComplexSelection() const
Returns true if the cursor contains a selection that is not simply a range from selectionStart() to s...
The QTextLength class encapsulates the different types of length used in a QTextDocument.
Definition: qtextformat.h:84
The QTextBlockFormat class provides formatting information for blocks of text in a QTextDocument...
Definition: qtextformat.h:545
bool isNull() const
Returns true if the cursor is null; otherwise returns false.
void add(const QTextBlock &block)
Makes the given block part of the list.
Definition: qtextlist.cpp:332
void setUndoRedoEnabled(bool enable)
void setRightMargin(qreal margin)
Sets the frame&#39;s right margin in pixels.
Definition: qtextformat.h:839
qreal value(qreal maximumLength) const
Returns the effective length, constrained by the type of the length object and the specified maximumL...
Definition: qtextformat.h:94
int leftPadding(int i) const
QFactoryLoader * l
void clearColumnWidthConstraints()
Clears the column width constraints for the table.
Definition: qtextformat.h:859
QTextDocumentPrivate * priv
int lastPosition() const
Returns the last valid position in the document occupied by this cell.
Definition: qtexttable.cpp:287
void setIndent(int indent)
Sets the paragraph&#39;s indentation.
Definition: qtextformat.h:622
bool movePosition(MoveOperation op, MoveMode=MoveAnchor, int n=1)
Moves the cursor by performing the given operation n times, using the specified mode, and returns true if all operations were completed successfully; otherwise returns false.
void setRightMargin(qreal margin)
Sets the paragraph&#39;s right margin.
Definition: qtextformat.h:579
bool isValid() const
Returns true if this is a valid table cell; otherwise returns false.
Definition: qtexttable.h:77
The QTextTableCellFormat class provides formatting information for table cells in a QTextDocument...
Definition: qtextformat.h:898
QTextCursor lastCursorPosition() const
Returns the last cursor position inside the frame.
void setPosition(int pos, MoveMode mode=MoveAnchor)
Moves the cursor to the absolute position in the document specified by pos using a MoveMode specified...
void setAnchor(bool anchor)
If anchor is true, text with this format represents an anchor, and is formatted in the appropriate wa...
Definition: qtextformat.h:499
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...
The QTextTableFormat class provides formatting information for tables in a QTextDocument.
Definition: qtextformat.h:842
const QTextHtmlParserNode * currentNode
int depth(int i) const
QString toPlainText() const
Returns the document fragment&#39;s text as plain text (i.e.
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139
void clearProperty(int propertyId)
Clears the value of the property given by propertyId.
ProcessNodeResult processSpecialNodes()
void reserve(int size)
Attempts to allocate memory for at least size elements.
Definition: qvector.h:339
ProcessNodeResult processBlockNode()
QTextBlock blocksFind(int pos) const
int columnSpan() const
Returns the number of columns this cell spans.
Definition: qtexttable.cpp:228
QTextFormat convertFormat(const QTextFormat &fmt)
void setCharFormat(int pos, int length, const QTextCharFormat &newFormat, FormatChangeMode mode=SetFormat)
void setBottomMargin(qreal margin)
Sets the frame&#39;s bottom margin in pixels.
Definition: qtextformat.h:833
void setObjectIndex(int object)
Sets the format object&#39;s object index.
static const KeyPair *const end
void setStyle(Style style)
Sets the list format&#39;s style.
Definition: qtextformat.h:682
QTextHtmlImporter(QTextDocument *_doc, const QString &html, ImportMode mode, const QTextDocument *resourceProvider=0)
void setLayoutDirection(Qt::LayoutDirection direction)
Sets the document&#39;s layout direction to the specified direction.
Definition: qtextformat.h:338
void setWidth(qreal width)
Sets the width of the rectangle occupied by the image.
Definition: qtextformat.h:721
int indexForFormat(const QTextFormat &f)
int propertyCount() const
Returns the number of properties stored in the format.
void setFrameFormat(const QTextFrameFormat &format)
Sets the frame&#39;s format.
Definition: qtextobject.h:191
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
QPointer< QTextFrame > frame
QTextFrameFormat frameFormat() const
Returns the frame&#39;s format.
Definition: qtextobject.h:131
QTextDocumentPrivate * src
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
int rightPadding(int i) const
qreal leftMargin() const
Returns the paragraph&#39;s left margin.
Definition: qtextformat.h:576
QTextBlockFormat blockFormat() const
Returns the QTextBlockFormat that describes block-specific properties.
const QChar * constData() const
Returns a pointer to the data stored in the QString.
Definition: qstring.h:712
The QTextDocumentFragment class represents a piece of formatted text from a QTextDocument.
int selectionStart() const
Returns the start of the selection or position() if the cursor doesn&#39;t have a selection.
#define text
Definition: qobjectdefs.h:80
#define QTextEndOfFrame