8#if QT_CONFIG(textmarkdownreader)
11#if QT_CONFIG(textmarkdownwriter)
34 this->forceCharFormat = forceCharFormat;
35 primaryCharFormatIndex = convertFormatIndex(
fmt);
39int QTextCopyHelper::convertFormatIndex(
const QTextFormat &oldFormat,
int objectIndexToSet)
42 if (objectIndexToSet != -1) {
43 fmt.setObjectIndex(objectIndexToSet);
44 }
else if (
fmt.objectIndex() != -1) {
45 int newObjectIndex = objectIndexMap.
value(
fmt.objectIndex(), -1);
46 if (newObjectIndex == -1) {
50 objectIndexMap.
insert(
fmt.objectIndex(), newObjectIndex);
52 fmt.setObjectIndex(newObjectIndex);
59int QTextCopyHelper::appendFragment(
int pos,
int endPos,
int objectIndex)
65 || (frag->
size_array[0] == 1 &&
src->formatCollection()->format(frag->
format).objectIndex() != -1));
69 charFormatIndex = primaryCharFormatIndex;
71 charFormatIndex = convertFormatIndex(frag->
format, objectIndex);
73 const int inFragmentOffset =
qMax(0,
pos - fragIt.position());
74 int charsToCopy =
qMin(
int(frag->
size_array[0] - inFragmentOffset), endPos -
pos);
80 blockIdx = convertFormatIndex(nextBlock.
blockFormat());
81 }
else if (
pos == 0 && insertPos == 0) {
82 dst->setBlockFormat(
dst->blocksBegin(),
dst->blocksBegin(), convertFormat(
src->blocksBegin().blockFormat()).
toBlockFormat());
83 dst->setCharFormat(-1, 1, convertFormat(
src->blocksBegin().charFormat()).
toCharFormat());
87 if (txtToInsert.size() == 1
93 dst->insertBlock(txtToInsert.at(0), insertPos, blockIdx, charFormatIndex);
102 int listBlockFormatIndex = convertFormatIndex(nextBlock.
blockFormat());
103 int listCharFormatIndex = convertFormatIndex(nextBlock.
charFormat());
104 dst->insertBlock(insertPos, listBlockFormatIndex, listCharFormatIndex);
108 dst->insert(insertPos, txtToInsert, charFormatIndex);
109 const int userState = nextBlock.
userState();
111 dst->blocksFind(insertPos).setUserState(userState);
112 insertPos += txtToInsert.size();
118void QTextCopyHelper::appendFragments(
int pos,
int endPos)
123 pos += appendFragment(
pos, endPos);
130 int row_start, col_start, num_rows, num_cols;
136 const int objectIndex =
dst->formatCollection()->createObjectIndex(tableFormat);
139 for (
int r = row_start;
r < row_start + num_rows; ++
r) {
140 for (
int c = col_start;
c < col_start + num_cols; ++
c) {
142 const int rspan = cell.
rowSpan();
157 if (
r + rspan >= row_start + num_rows) {
160 if (
c + cspan >= col_start + num_cols) {
163 const int charFormatIndex = convertFormatIndex(cellFormat, objectIndex);
169 blockIdx = convertFormatIndex(block.
blockFormat());
185 appendFragment(
end,
end+1, objectIndex);
206 p->mergeCachedResources(_cursor.d->
priv);
281 if (!
cursor.hasSelection())
365#ifndef QT_NO_TEXTHTMLPARSER
384#if QT_CONFIG(textmarkdownwriter)
394QString QTextDocumentFragment::toMarkdown(QTextDocument::MarkdownFeatures features)
const
399 return d->
doc->toMarkdown(features);
421#ifndef QT_NO_TEXTHTMLPARSER
433 : indent(0), headingLevel(0), compressNextWhitespace(PreserveWhiteSpace), doc(_doc), importMode(
mode)
439 const int startFragmentPos = html.
indexOf(
"<!--StartFragment-->"_L1);
440 if (startFragmentPos != -1) {
441 const auto qt3RichTextHeader =
"<meta name=\"qrichtext\" content=\"1\" />"_L1;
444 const bool hasQtRichtextMetaTag = html.
contains(qt3RichTextHeader);
446 const int endFragmentPos = html.
indexOf(
"<!--EndFragment-->"_L1);
447 if (startFragmentPos < endFragmentPos)
448 html = html.
mid(startFragmentPos, endFragmentPos - startFragmentPos);
450 html = html.
mid(startFragmentPos);
452 if (hasQtRichtextMetaTag)
453 html.
prepend(qt3RichTextHeader);
464 forceBlockMerging =
false;
465 compressNextWhitespace = RemoveWhiteSpace;
466 blockTagClosed =
false;
467 for (currentNodeIdx = 0; currentNodeIdx <
count(); ++currentNodeIdx) {
468 currentNode = &
at(currentNodeIdx);
490 if (currentNodeIdx > 0 && (currentNode->
parent != currentNodeIdx - 1)) {
491 blockTagClosed = closeTag();
500 }
else if (blockTagClosed && hasBlock) {
528 if (processSpecialNodes() == ContinueWithNextNode)
547 QTextHtmlImporter::ProcessNodeResult
result = processBlockNode();
548 if (
result == ContinueWithNextNode) {
550 }
else if (
result == ContinueWithNextSibling) {
558 if (!
names.isEmpty())
559 namedAnchors.append(
names.constFirst());
562 if (appendNodeText())
570bool QTextHtmlImporter::appendNodeText()
572 const int initialCursorPosition = cursor.
position();
576 compressNextWhitespace = PreserveWhiteSpace;
591 compressNextWhitespace = PreserveWhiteSpace;
593 if (compressNextWhitespace == CollapseWhiteSpace)
594 compressNextWhitespace = RemoveWhiteSpace;
595 else if (compressNextWhitespace == RemoveWhiteSpace)
604 }
else if (
ch == u
'\r') {
608 compressNextWhitespace = RemoveWhiteSpace;
617 compressNextWhitespace = PreserveWhiteSpace;
625 textToInsert = textToInsert.
chopped(1);
627 textToInsert.
clear();
641 if (!namedAnchors.isEmpty()) {
644 textToInsert.
clear();
648 format.setAnchorNames(namedAnchors);
650 namedAnchors.clear();
663 return cursor.
position() != initialCursorPosition;
666QTextHtmlImporter::ProcessNodeResult QTextHtmlImporter::processSpecialNodes()
668 switch (currentNode->
id) {
676 compressNextWhitespace = RemoveWhiteSpace;
713 l.listNode = currentNodeIdx;
715 compressNextWhitespace = RemoveWhiteSpace;
720 return ContinueWithNextNode;
725 Table t = scanTable(currentNodeIdx);
728 compressNextWhitespace = RemoveWhiteSpace;
729 return ContinueWithNextNode;
733 return ContinueWithNextNode;
755 compressNextWhitespace = CollapseWhiteSpace;
758 return ContinueWithNextNode;
769 appendBlock(blockFormat);
771 compressNextWhitespace = RemoveWhiteSpace;
772 return ContinueWithNextNode;
797 return ContinueWithCurrentNode;
801bool QTextHtmlImporter::closeTag()
804 const int endDepth =
depth(currentNodeIdx) - 1;
806 bool blockTagClosed =
false;
808 while (
depth > endDepth) {
813 switch (closedNode->
id) {
815 if (
t && !
t->isTextFrame) {
819 while (!
t->currentCell.atEnd() &&
t->currentCell.row <
t->currentRow)
823 blockTagClosed =
true;
829 indent =
t->lastIndent;
839 cursor =
t->frame->lastCursorPosition();
840 else if (!
t->currentCell.atEnd())
841 cursor =
t->currentCell.cell().lastCursorPosition();
847 blockTagClosed =
false;
848 compressNextWhitespace = RemoveWhiteSpace;
853 if (
t && !
t->isTextFrame)
855 blockTagClosed =
true;
856 compressNextWhitespace = RemoveWhiteSpace;
865 blockTagClosed =
true;
869 compressNextWhitespace = RemoveWhiteSpace;
876 blockTagClosed =
true;
887 blockTagClosed =
true;
891 blockTagClosed =
true;
895 closedNode = &
at(closedNode->
parent);
899 return blockTagClosed;
909 int tableHeaderRowCount = 0;
911 rowNodes.
reserve(
at(tableNodeIdx).children.size());
912 for (
int row :
at(tableNodeIdx).children) {
913 switch (
at(
row).
id) {
920 for (
int potentialRow :
at(
row).children) {
922 rowNodes += potentialRow;
924 ++tableHeaderRowCount;
935 int effectiveRow = 0;
936 for (
int row :
std::as_const(rowNodes)) {
939 for (
int cell :
at(
row).children) {
940 if (
at(cell).isTableCell()) {
942 while (colsInRow < rowColSpanForColumn.
size()) {
943 const RowColSpanInfo &spanInfo = rowColSpanForColumn.
at(colsInRow);
945 if (spanInfo.row + spanInfo.rowSpan > effectiveRow) {
946 Q_ASSERT(spanInfo.col == colsInRow);
947 colsInRow += spanInfo.colSpan;
953 const int currentColumn = colsInRow;
954 colsInRow +=
c.tableCellColSpan;
956 RowColSpanInfo spanInfo;
957 spanInfo.row = effectiveRow;
958 spanInfo.col = currentColumn;
959 spanInfo.colSpan =
c.tableCellColSpan;
960 spanInfo.rowSpan =
c.tableCellRowSpan;
961 if (spanInfo.colSpan > 1 || spanInfo.rowSpan > 1)
962 rowColSpans.
append(spanInfo);
965 rowColSpanForColumn.
resize(columnWidths.
size());
966 for (
int i = currentColumn;
i < currentColumn +
c.tableCellColSpan; ++
i) {
973 rowColSpanForColumn[
i] = spanInfo;
982 table.rows = effectiveRow;
984 table.lastIndent = indent;
1009 +
table.lastIndent * 40
1040 table.isTextFrame =
true;
1042 const int oldPos = cursor.
position();
1044 table.frame = textTable;
1046 for (
int i = 0;
i < rowColSpans.
size(); ++
i) {
1047 const RowColSpanInfo &nfo = rowColSpans.
at(
i);
1048 textTable->
mergeCells(nfo.row, nfo.col, nfo.rowSpan, nfo.colSpan);
1051 table.currentCell = TableCellIterator(textTable);
1057QTextHtmlImporter::ProcessNodeResult QTextHtmlImporter::processBlockNode()
1061 bool modifiedBlockFormat =
true;
1062 bool modifiedCharFormat =
true;
1066 if (!
t.isTextFrame && !
t.currentCell.atEnd()) {
1078#ifndef QT_NO_CSSPARSER
1111 compressNextWhitespace = RemoveWhiteSpace;
1122 modifiedBlockFormat =
false;
1123 modifiedCharFormat =
false;
1131 modifiedBlockFormat =
true;
1149 modifiedBlockFormat =
true;
1158 modifiedBlockFormat =
true;
1162 modifiedBlockFormat =
true;
1170 || !
lists.constLast().list
1171 ||
lists.constLast().list->itemNumber(cursor.
block()) == -1
1175 modifiedBlockFormat =
true;
1180 modifiedBlockFormat =
true;
1184 modifiedBlockFormat =
true;
1189 modifiedCharFormat =
true;
1199 modifiedBlockFormat =
true;
1204 modifiedBlockFormat =
true;
1208 if (modifiedBlockFormat)
1210 if (modifiedCharFormat)
1217 appendBlock(block, charFmt);
1227 l.list->add(cursor.
block());
1231 if (listTopMargin > block.
topMargin()) {
1243 forceBlockMerging =
false;
1245 forceBlockMerging =
true;
1249 return ContinueWithNextSibling;
1253 blockTagClosed =
false;
1254 return ContinueWithCurrentNode;
1259 if (!namedAnchors.isEmpty()) {
1262 namedAnchors.clear();
1268 compressNextWhitespace = RemoveWhiteSpace;
1296#if QT_CONFIG(textmarkdownreader)
1317 importer.import(
res.d->doc, markdown);
Qt::BrushStyle style() const
Returns the brush style.
constexpr bool isSpace() const noexcept
Returns true if the character is a separator character (Separator_* categories or certain code points...
qsizetype size() const noexcept
bool isEmpty() const noexcept
const_reference at(qsizetype i) const noexcept
void reserve(qsizetype size)
void resize(qsizetype size)
void append(parameter_type t)
iterator insert(const Key &key, const T &value)
T value(const Key &key, const T &defaultValue=T()) const
\macro QT_RESTRICTED_CAST_FROM_ASCII
void reserve(qsizetype size)
Ensures the string has space for at least size characters.
void clear()
Clears the contents of the string and makes it null.
const QChar * constData() const
Returns a pointer to the data stored in the QString.
bool isNull() const
Returns true if this string is null; otherwise returns false.
qsizetype size() const
Returns the number of characters in this string.
QString mid(qsizetype position, qsizetype n=-1) const
Returns a string that contains n characters of this string, starting at the specified position index.
QString simplified() const &
const QChar at(qsizetype i) const
Returns the character at the given index position in the string.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
bool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
static QString static QString qsizetype indexOf(QChar c, qsizetype from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
QString chopped(qsizetype n) const
QString & prepend(QChar c)
qreal bottomMargin() const
Returns the paragraph's bottom margin.
qreal topMargin() const
Returns the paragraph's top margin.
void setLeftMargin(qreal margin)
Sets the paragraph's left margin.
Qt::Alignment alignment() const
Returns the paragraph's alignment.
void setPageBreakPolicy(PageBreakFlags flags)
void setBottomMargin(qreal margin)
Sets the paragraph's bottom margin.
PageBreakFlags pageBreakPolicy() const
void setNonBreakableLines(bool b)
If b is true, the lines in the paragraph are treated as non-breakable; otherwise they are breakable.
void setRightMargin(qreal margin)
Sets the paragraph's right margin.
void setIndent(int indent)
Sets the paragraph's indentation.
int indent() const
Returns the paragraph's indent.
qreal leftMargin() const
Returns the paragraph's left margin.
void setHeadingLevel(int alevel)
qreal rightMargin() const
Returns the paragraph's right margin.
void setTopMargin(qreal margin)
Sets the paragraph's top margin.
void setUserState(int state)
QTextBlockFormat blockFormat() const
Returns the QTextBlockFormat that describes block-specific properties.
int position() const
Returns the index of the block's first character within the document.
QTextCharFormat charFormat() const
Returns the QTextCharFormat that describes the block's character format.
QTextList * textList() const
If the block represents a list item, returns the list that the item belongs to; otherwise returns \nu...
bool isAnchor() const
Returns true if the text is formatted as an anchor; otherwise returns false.
QStringList anchorNames() const
void setAnchor(bool anchor)
If anchor is true, text with this format represents an anchor, and is formatted in the appropriate wa...
void setAnchorNames(const QStringList &names)
void setTableCellColumnSpan(int tableCellColumnSpan)
void setTableCellRowSpan(int tableCellRowSpan)
QTextCopyHelper(const QTextCursor &_source, const QTextCursor &_destination, bool forceCharFormat=false, const QTextCharFormat &fmt=QTextCharFormat())
QTextDocumentPrivate * priv
\reentrant \inmodule QtGui
void setBlockCharFormat(const QTextCharFormat &format)
Sets the block char format of the current block (or all blocks that are contained in the selection) t...
QTextBlockFormat blockFormat() const
Returns the block format of the block the cursor is in.
QTextDocument * document() const
QTextCharFormat charFormat() const
Returns the format of the character immediately before the cursor position().
QTextBlock block() const
Returns the block that contains the cursor.
QTextCharFormat blockCharFormat() const
Returns the block character format of the block the cursor is in.
void beginEditBlock()
Indicates the start of a block of editing operations on the document that should appear as a single o...
void setPosition(int pos, MoveMode mode=MoveAnchor)
Moves the cursor to the absolute position in the document specified by pos using a MoveMode specified...
int selectionStart() const
Returns the start of the selection or position() if the cursor doesn't have a selection.
bool movePosition(MoveOperation op, MoveMode=MoveAnchor, int n=1)
Moves the cursor by performing the given operation n times, using the specified mode,...
bool isNull() const
Returns true if the cursor is null; otherwise returns false.
void setBlockFormat(const QTextBlockFormat &format)
Sets the block format of the current block (or all blocks that are contained in the selection) to for...
void mergeBlockCharFormat(const QTextCharFormat &modifier)
Modifies the block char format of the current block (or all blocks that are contained in the selectio...
void mergeCharFormat(const QTextCharFormat &modifier)
Merges the cursor's current character format with the properties described by format modifier.
int selectionEnd() const
Returns the end of the selection or position() if the cursor doesn't have a selection.
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...
void insertText(const QString &text)
Inserts text at the current position, using the current character format.
void insertImage(const QTextImageFormat &format, QTextFrameFormat::Position alignment)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void insertBlock()
Inserts a new empty block at the cursor position() with the current blockFormat() and charFormat().
bool hasSelection() const
Returns true if the cursor contains a selection; otherwise returns false.
void endEditBlock()
Indicates the end of a block of editing operations on the document that should appear as a single ope...
void mergeBlockFormat(const QTextBlockFormat &modifier)
Modifies the block format of the current block (or all blocks that are contained in the selection) wi...
bool hasComplexSelection() const
Returns true if the cursor contains a selection that is not simply a range from selectionStart() to s...
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,...
QTextTable * currentTable() const
Returns a pointer to the current table if the cursor position() is inside a block that is part of a t...
QTextFrame * insertFrame(const QTextFrameFormat &format)
Inserts a frame with the given format at the current cursor position(), moves the cursor position() i...
int position() const
Returns the absolute position of the cursor within the document.
QTextFrame * currentFrame() const
Returns a pointer to the current frame.
QTextList * createList(const QTextListFormat &format)
Creates and returns a new list with the given format, and makes the current paragraph the cursor is i...
uint importedFromPlainText
void insert(QTextCursor &cursor) const
QTextDocumentFragmentPrivate(const QTextCursor &cursor=QTextCursor())
QString toPlainText() const
This function returns the same as toRawText(), but will replace some unicode characters with ASCII al...
QTextDocumentFragment & operator=(const QTextDocumentFragment &rhs)
Assigns the other fragment to this fragment.
QTextDocumentFragment()
Constructs an empty QTextDocumentFragment.
bool isEmpty() const
Returns true if the fragment is empty; otherwise returns false.
static QTextDocumentFragment fromHtml(const QString &html, const QTextDocument *resourceProvider=nullptr)
~QTextDocumentFragment()
Destroys the document fragment.
static QTextDocumentFragment fromPlainText(const QString &plainText)
Returns a document fragment that contains the given plainText.
QString toRawText() const
Returns the document fragment's text as raw text (i.e.
QTextFormatCollection * formatCollection()
static const QTextDocumentPrivate * get(const QTextDocument *document)
FragmentMap::ConstIterator FragmentIterator
\reentrant \inmodule QtGui
QString toRawText() const
Returns the raw text contained in the document without any formatting information.
QChar characterAt(int pos) const
void setUndoRedoEnabled(bool enable)
QString toPlainText() const
Returns the plain text contained in the document.
QTextFrame * rootFrame() const
Returns the document's root frame.
void setMetaInformation(MetaInformation info, const QString &)
Sets the document's meta information of the type specified by info to the given string.
int indexForFormat(const QTextFormat &f)
int createObjectIndex(const QTextFormat &f)
QTextFormat format(int idx) const
QTextCharFormat toCharFormat() const
Returns this format as a character format.
QBrush background() const
Returns the brush used to paint the document's background.
QTextBlockFormat toBlockFormat() const
Returns this format as a block format.
Qt::LayoutDirection layoutDirection() const
Returns the document's layout direction.
@ BlockTrailingHorizontalRulerWidth
int objectIndex() const
Returns the index of the format object, or -1 if the format object is invalid.
void setBackground(const QBrush &brush)
Sets the brush use to paint the document's background to the brush specified.
void setProperty(int propertyId, const QVariant &value)
Sets the property specified by the propertyId to the given value.
QTextTableCellFormat toTableCellFormat() const
int propertyCount() const
bool hasProperty(int propertyId) const
Returns true if the text format has a property with the given propertyId; otherwise returns false.
int type() const
Returns the type of this format.
void clearProperty(int propertyId)
Clears the value of the property given by propertyId.
void merge(const QTextFormat &other)
Merges the other format with this format; where there are conflicts the other format takes precedence...
Position
This enum describes how a frame is located relative to the surrounding text.
void setFrameFormat(const QTextFrameFormat &format)
Sets the frame's format.
QTextFrameFormat frameFormat() const
Returns the frame's format.
QTextCursor lastCursorPosition() const
Returns the last cursor position inside the frame.
QString toHtml(ExportMode mode=ExportEntireDocument)
Returns the document in HTML format.
QTextHtmlImporter(QTextDocument *_doc, const QString &html, ImportMode mode, const QTextDocument *resourceProvider=nullptr)
QTextFrameFormat::BorderStyle tableCellBorderStyle(int i, int edge) const
QBrush tableCellBorderBrush(int i, int edge) const
qreal tableCellBorder(int i, int edge) const
int topMargin(int i) const
int topPadding(int i) const
int leftMargin(int i) const
int rightMargin(int i) const
int bottomPadding(int i) const
int leftPadding(int i) const
int bottomMargin(int i) const
const QTextDocument * resourceProvider
int rightPadding(int i) const
void setStyle(Style style)
Sets the list format's style.
Style
This enum describes the symbols used to decorate list items:
void setIndent(int indent)
Sets the list format's indentation.
void setNumberSuffix(const QString &numberSuffix)
void setNumberPrefix(const QString &numberPrefix)
void setStart(int indent)
QTextCharFormat format() const
Returns the cell's character format.
int columnSpan() const
Returns the number of columns this cell spans.
int firstPosition() const
int row() const
Returns the number of the row in the table that contains this cell.
int rowSpan() const
Returns the number of rows this cell spans.
void setFormat(const QTextCharFormat &format)
bool isValid() const
Returns true if this is a valid table cell; otherwise returns false.
int column() const
Returns the number of the column in the table that contains this cell.
void setAlignment(Qt::Alignment alignment)
Sets the table's alignment.
void clearColumnWidthConstraints()
Clears the column width constraints for the table.
void setBorderCollapse(bool borderCollapse)
void setColumnWidthConstraints(const QList< QTextLength > &constraints)
Sets the column width constraints for the table.
void setHeaderRowCount(int count)
void setColumns(int columns)
void setCellSpacing(qreal spacing)
Sets the cell spacing for the table.
void setCellPadding(qreal padding)
Sets the cell padding for the table.
void mergeCells(int row, int col, int numRows, int numCols)
Combined button and popup list for selecting options.
bool qFuzzyCompare(qfloat16 p1, qfloat16 p2) noexcept
constexpr const T & qMin(const T &a, const T &b)
constexpr const T & qMax(const T &a, const T &b)
GLint GLenum GLsizei GLsizei GLsizei depth
GLfloat GLfloat GLfloat w
[0]
GLint GLsizei GLsizei GLenum format
GLenum GLenum GLsizei void * row
GLenum GLenum GLsizei void * table
#define QTextBeginningOfFrame
static QTextListFormat::Style nextListStyle(QTextListFormat::Style style)
QVideoFrameFormat::PixelFormat fmt
const QByteArray plainText
QString textListNumberSuffix
QTextListFormat::Style listStyle
QTextFrameFormat::BorderStyle borderStyle
bool hasOnlyWhitespace() const
QTextCharFormat charFormat
QTextBlockFormat blockFormat
QString textListNumberPrefix