29 currentCharFormat(-1), visualNavigation(
false), keepPositionOnInsert(
false),
69 if (charsAddedOrRemoved < 0 &&
position < positionOfChange - charsAddedOrRemoved)
77 if (
anchor >= positionOfChange
79 if (charsAddedOrRemoved < 0 &&
anchor < positionOfChange - charsAddedOrRemoved)
82 anchor += charsAddedOrRemoved;
87 if (charsAddedOrRemoved < 0 &&
adjusted_anchor < positionOfChange - charsAddedOrRemoved)
132 int startRow, startCol, numRows, numCols;
148 for (
int row = startRow;
row < startRow + numRows; ++
row)
149 for (
int col = startCol; col < startCol + numCols; ++col) {
154 priv->
remove(startPos, endPos - startPos, op);
186 if (f_position != f_anchor) {
193 f =
f->parentFrame();
198 f =
f->parentFrame();
204 if (positionChain.
at(
i) != anchorChain.
at(
i))
209 if (
i < positionChain.
size())
210 position = positionChain.
at(
i)->firstPosition() - 1;
212 if (
i < positionChain.
size())
213 position = positionChain.
at(
i)->lastPosition() + 1;
216 if (
i < anchorChain.
size())
219 if (
i < anchorChain.
size())
223 f_position = positionChain.
at(
i-1);
233 if (c_position != c_anchor) {
260 qSwap(curFrom, curTo);
265 if (cellStart.
row() >= removedCellFrom.
row() && cellEnd.
row() <= removedCellEnd.
row()
270 if (removedCellFrom.
row() == 0 && removedCellEnd.
row() ==
t->rows()-1)
271 cell =
t->cellAt(cellStart.
row(), removedCellEnd.
column()+1);
272 else if (removedCellFrom.
column() == 0 && removedCellEnd.
column() ==
t->columns()-1)
273 cell =
t->cellAt(removedCellEnd.
row() + 1, cellStart.
column());
279 newPosition =
t->lastPosition()+1;
286 else if (cellStart.
row() >= removedCellFrom.
row() && cellStart.
row() <= removedCellEnd.
row()
287 && cellEnd.
row() > removedCellEnd.
row()) {
288 int newPosition =
t->cellAt(removedCellEnd.
row() + 1, cellStart.
column()).firstPosition();
296 int newPosition =
t->cellAt(cellStart.
row(), removedCellEnd.
column()+1).firstPosition();
320 if (!visualMovement) {
332 line =
layout->lineForTextPosition(relativePos);
362 newPosition +=
line.textStart();
393 if (relativePos == 0)
399 if ((relativePos == blockIt.
length() - 1)
400 && (attributes[relativePos - 1].
whiteSpace ||
engine->atWordSeparator(relativePos - 1)))
403 if (relativePos < blockIt.
length()-1)
413 int i =
line.lineNumber() - 1;
417 int blockPosition = blockIt.
position();
427 blockPosition =
table->firstPosition() - 1;
439 if (
layout->lineCount()) {
453 if (!
line.isValid() ||
line.textLength() == 0) {
454 if (blockIt.
length() >= 1)
462 if (
line.lineNumber() <
layout->lineCount() - 1) {
475 if (relativePos >=
len)
477 if (
engine->atWordSeparator(relativePos)) {
479 while (relativePos < len && engine->atWordSeparator(relativePos))
482 while (relativePos <
len && !attributes[relativePos].whiteSpace && !
engine->atWordSeparator(relativePos))
485 newPosition = blockIt.
position() + relativePos;
489 if (blockIt.
length() >= 1)
494 blockIt = blockIt.
next();
521 int i =
line.lineNumber() + 1;
523 if (
i >=
layout->lineCount()) {
530 if (row < table->rows()) {
531 blockPosition =
table->cellAt(
row, cell.
column()).firstPosition();
534 blockPosition =
table->lastPosition() + 1;
538 blockIt = blockIt.
next();
541 blockIt = blockIt.
next();
549 if (
layout->lineCount()) {
570 const int currentRow =
row;
613 int newColumn = otherCell.
column();
647 if (cell_pos == cell_anchor)
672 if (cell_pos == cell_anchor)
675 *firstRow =
qMin(cell_pos.
row(), cell_anchor.
row());
690 priv->setCharFormat(
it.position() - 1, 1,
format, changeMode);
704 int row_start, col_start, num_rows, num_cols;
708 for (
int r = row_start;
r < row_start + num_rows; ++
r) {
709 for (
int c = col_start;
c < col_start + num_cols; ++
c) {
748 int row_start, col_start, num_rows, num_cols;
752 for (
int r = row_start;
r < row_start + num_rows; ++
r) {
753 for (
int c = col_start;
c < col_start + num_cols; ++
c) {
796 int row_start, col_start, num_rows, num_cols;
800 for (
int r = row_start;
r < row_start + num_rows; ++
r) {
801 for (
int c = col_start;
c < col_start + num_cols; ++
c) {
1104 return !d || !d->
priv;
1129 qWarning(
"QTextCursor::setPosition: Position '%d' out of range",
pos);
1238 int previousPosition = d->
position;
1239 for (;
n > 0; --
n) {
1246 if (previousPosition < d->
position) {
1247 while (!
b.next().isVisible())
1251 while (!
b.previous().isVisible())
1329 return d ? d->
x : -1;
1410 bool hasEditBlock =
false;
1413 hasEditBlock =
true;
1426 int textStart = d->
priv->text.
size();
1429 int textEnd = d->
priv->text.
size();
1434 const int blockEnd =
i;
1449 if (!hasEditBlock) {
1450 hasEditBlock =
true;
1454 if (blockEnd > blockStart)
1455 d->
priv->
insert(d->
position, textStart + blockStart, blockEnd - blockStart, formatIdx);
1461 if (textStart + blockStart < textEnd)
1462 d->
priv->
insert(d->
position, textStart + blockStart, textEnd - textStart - blockStart, formatIdx);
1515 int fpos = fragIt.position();
1679 const int offsetInFragment =
qMax(0,
pos - fragIt.position());
1708 int row_start, col_start, num_rows, num_cols;
1712 for (
int r = row_start;
r < row_start + num_rows; ++
r) {
1713 for (
int c = col_start;
c < col_start + num_cols; ++
c) {
1718 int cr = cell.
row();
1882 idx =
it.value()->format;
2100 fmt.setStyle(style);
2117 return qobject_cast<QTextList *>(
o);
2152 if (!d || !d->
priv || rows == 0 || cols == 0)
2226 fragment.d->
insert(*
this);
2230 if (fragment.d && fragment.d->
doc)
2245#ifndef QT_NO_TEXTHTMLPARSER
2263#if QT_CONFIG(textmarkdownreader)
2265void QTextCursor::insertMarkdown(
const QString &markdown, QTextDocument::MarkdownFeatures features)
2298 fmt.setObjectIndex(
obj->objectIndex());
2339 if (
image.isNull()) {
2340 qWarning(
"QTextCursor::insertImage: attempt to add an invalid image");
2348 format.setName(imageName);
2377 Q_ASSERT_X(d->
priv == rhs.d->
priv,
"QTextCursor::operator<",
"cannot compare cursors attached to different documents");
2397 Q_ASSERT_X(d->
priv == rhs.d->
priv,
"QTextCursor::operator<=",
"cannot compare cursors attached to different documents");
2434 Q_ASSERT_X(d->
priv == rhs.d->
priv,
"QTextCursor::operator>=",
"cannot compare cursors attached to different documents");
2453 Q_ASSERT_X(d->
priv == rhs.d->
priv,
"QTextCursor::operator>",
"cannot compare cursors attached to different documents");
2480 if (d->
priv->editBlock == 0)
2533 return d ==
other.d;
2576 if (
layout->lineCount() == 0)
2580 if (!
line.isValid())
2582 return relativePos -
line.textStart();
virtual QRectF blockBoundingRect(const QTextBlock &block) const =0
Returns the bounding rectangle of block.
@ ObjectReplacementCharacter
constexpr bool isLowSurrogate() const noexcept
Returns true if the QChar is the low part of a UTF16 surrogate (for example if its code point is in r...
constexpr bool isSpace() const noexcept
Returns true if the character is a separator character (Separator_* categories or certain code points...
constexpr bool isHighSurrogate() const noexcept
Returns true if the QChar is the high part of a UTF16 surrogate (for example if its code point is in ...
qsizetype size() const noexcept
const_reference at(qsizetype i) const noexcept
void prepend(rvalue_ref t)
\macro QT_RESTRICTED_CAST_FROM_ASCII
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
const QChar * constData() const
Returns a pointer to the data stored in the QString.
qsizetype size() const
Returns the number of characters in this string.
const QChar at(qsizetype i) const
Returns the character at the given index position in the string.
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
int length() const
Returns the length of the block in characters.
QTextBlockFormat blockFormat() const
Returns the QTextBlockFormat that describes block-specific properties.
bool isValid() const
Returns true if this text block is valid; otherwise returns false.
QTextBlock next() const
Returns the text block in the document after this block, or an empty text block if this is the last o...
QTextLayout * layout() const
Returns the QTextLayout that is used to lay out and display the block's contents.
int position() const
Returns the index of the block's first character within the document.
QString text() const
Returns the block's contents as plain text.
Qt::LayoutDirection textDirection() const
QTextCharFormat charFormat() const
Returns the QTextCharFormat that describes the block's character format.
QTextBlock previous() const
Returns the text block in the document before this block, or an empty text block if this is the first...
bool isValid() const
Returns true if this character format is valid; otherwise returns false.
bool movePosition(QTextCursor::MoveOperation op, QTextCursor::MoveMode mode=QTextCursor::MoveAnchor)
AdjustResult adjustPosition(int positionOfChange, int charsAddedOrRemoved, QTextUndoCommand::Operation op)
void setCharFormat(const QTextCharFormat &format, QTextDocumentPrivate::FormatChangeMode changeMode)
void setBlockCharFormat(const QTextCharFormat &format, QTextDocumentPrivate::FormatChangeMode changeMode)
void selectedTableCells(int *firstRow, int *numRows, int *firstColumn, int *numColumns) const
uint keepPositionOnInsert
QTextLayout * blockLayout(QTextBlock &block) const
void setBlockFormat(const QTextBlockFormat &format, QTextDocumentPrivate::FormatChangeMode changeMode)
bool setPosition(int newPosition)
bool canDelete(int pos) const
QTextDocumentPrivate * priv
QTextCursorPrivate(QTextDocumentPrivate *p)
void clearCells(QTextTable *table, int startRow, int startCol, int numRows, int numCols, QTextUndoCommand::Operation op)
void adjustCursor(QTextCursor::MoveOperation m)
void insertBlock(const QTextBlockFormat &format, const QTextCharFormat &charFormat)
void aboutToRemoveCell(int from, int to)
QTextTable * complexSelectionTable() const
\reentrant \inmodule QtGui
QString selectedText() const
Returns the current selection's text (which may be empty).
void setBlockCharFormat(const QTextCharFormat &format)
Sets the block char format of the current block (or all blocks that are contained in the selection) t...
void setVerticalMovementX(int x)
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...
bool atBlockStart() const
Returns true if the cursor is at the start of a block; otherwise returns false.
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 setKeepPositionOnInsert(bool b)
int selectionStart() const
Returns the start of the selection or position() if the cursor doesn't have a selection.
bool atStart() const
Returns true if the cursor is at the start of the document; otherwise returns false.
bool movePosition(MoveOperation op, MoveMode=MoveAnchor, int n=1)
Moves the cursor by performing the given operation n times, using the specified mode,...
bool operator<(const QTextCursor &rhs) const
Returns true if the other cursor is positioned later in the document than this cursor; otherwise retu...
bool atBlockEnd() const
Returns true if the cursor is at the end of a block; otherwise returns false.
int anchor() const
Returns the anchor position; this is the same as position() unless there is a selection in which case...
void insertHtml(const QString &html)
SelectionType
This enum describes the types of selection that can be applied with the select() function.
int positionInBlock() const
void clearSelection()
Clears the current selection by setting the anchor to the cursor position.
void insertFragment(const QTextDocumentFragment &fragment)
Inserts the text fragment at the current position().
bool isNull() const
Returns true if the cursor is null; otherwise returns false.
MoveMode
\value MoveAnchor Moves the anchor to the same position as the cursor itself.
bool keepPositionOnInsert() const
void setBlockFormat(const QTextBlockFormat &format)
Sets the block format of the current block (or all blocks that are contained in the selection) to for...
~QTextCursor()
Destroys the QTextCursor.
void setCharFormat(const QTextCharFormat &format)
Sets the cursor's current character format to the given format.
bool visualNavigation() const
QTextCursor()
Constructs a null cursor.
void removeSelectedText()
If there is a selection, its content is deleted; otherwise does nothing.
void mergeBlockCharFormat(const QTextCharFormat &modifier)
Modifies the block char format of the current block (or all blocks that are contained in the selectio...
QTextDocumentFragment selection() const
Returns the current selection (which may be empty) with all its formatting information.
int verticalMovementX() const
void mergeCharFormat(const QTextCharFormat &modifier)
Merges the cursor's current character format with the properties described by format modifier.
void joinPreviousEditBlock()
Like beginEditBlock() indicates the start of a block of editing operations that should appear as a si...
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 select(SelectionType selection)
Selects text in the document according to the given selection.
void insertText(const QString &text)
Inserts text at the current position, using the current character format.
QTextList * currentList() const
Returns the current list if the cursor position() is inside a block that is part of a list; otherwise...
void setVisualNavigation(bool b)
bool operator>=(const QTextCursor &rhs) const
Returns true if the other cursor is positioned earlier or at the same position in the document as thi...
bool isCopyOf(const QTextCursor &other) const
Returns true if this cursor and other are copies of each other, i.e.
bool operator>(const QTextCursor &rhs) const
Returns true if the other cursor is positioned earlier in the document than this cursor; otherwise re...
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...
QTextList * insertList(const QTextListFormat &format)
Inserts a new block at the current position and makes it the first list item of a newly created list ...
MoveOperation
\value NoMove Keep the cursor where it is
bool operator<=(const QTextCursor &rhs) const
Returns true if the other cursor is positioned later or at the same position in the document as this ...
void mergeBlockFormat(const QTextBlockFormat &modifier)
Modifies the block format of the current block (or all blocks that are contained in the selection) wi...
QTextCursor & operator=(const QTextCursor &other)
Makes a copy of cursor and assigns it to this QTextCursor.
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...
bool operator==(const QTextCursor &rhs) const
Returns true if the other cursor is at the same position in the document as this cursor; otherwise re...
QTextFrame * insertFrame(const QTextFrameFormat &format)
Inserts a frame with the given format at the current cursor position(), moves the cursor position() i...
void deletePreviousChar()
If there is no selected text, deletes the character before the current cursor position; otherwise del...
int position() const
Returns the absolute position of the cursor within the document.
void deleteChar()
If there is no selected text, deletes the character at the current cursor position; otherwise deletes...
QTextFrame * currentFrame() const
Returns a pointer to the current frame.
bool operator!=(const QTextCursor &rhs) const
Returns true if the other cursor is at a different position in the document as this cursor; otherwise...
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 insert(QTextCursor &cursor) const
bool isEmpty() const
Returns true if the fragment is empty; otherwise returns false.
static QTextDocumentFragment fromHtml(const QString &html, const QTextDocument *resourceProvider=nullptr)
QTextFormatCollection * formatCollection()
const BlockMap & blockMap() const
QAbstractTextDocumentLayout * layout() const
int insertBlock(int pos, int blockFormat, int charFormat, QTextUndoCommand::Operation=QTextUndoCommand::MoveCursor)
QTextFrame * frameAt(int pos) const
void remove(int pos, int length, QTextUndoCommand::Operation=QTextUndoCommand::MoveCursor)
int rightCursorPosition(int position) const
QTextFrame * insertFrame(int start, int end, const QTextFrameFormat &format)
void removeCursor(QTextCursorPrivate *c)
int blockCharFormatIndex(int node) const
QTextBlock blocksBegin() const
int nextCursorPosition(int position, QTextLayout::CursorMode mode) const
bool isInEditBlock() const
QTextDocument * document()
QTextBlock blocksEnd() const
QTextObject * createObject(const QTextFormat &newFormat, int objectIndex=-1)
static const QTextDocumentPrivate * get(const QTextDocument *document)
FragmentMap::ConstIterator FragmentIterator
@ SetFormatAndPreserveObjectIndices
void setBlockFormat(const QTextBlock &from, const QTextBlock &to, const QTextBlockFormat &newFormat, FormatChangeMode mode=SetFormat)
FragmentIterator find(int pos) const
Qt::CursorMoveStyle defaultCursorMoveStyle
void joinPreviousEditBlock()
QTextObject * objectForFormat(int formatIndex) const
void insert(int pos, const QString &text, int format)
int leftCursorPosition(int position) const
void setCharFormat(int pos, int length, const QTextCharFormat &newFormat, FormatChangeMode mode=SetFormat)
QTextBlock blocksFind(int pos) const
void mergeCachedResources(const QTextDocumentPrivate *priv)
int previousCursorPosition(int position, QTextLayout::CursorMode mode) const
void addCursor(QTextCursorPrivate *c)
\reentrant \inmodule QtGui
QTextBlock firstBlock() const
void addResource(int type, const QUrl &name, const QVariant &resource)
Adds the resource resource to the resource cache, using type and name as identifiers.
int indexForFormat(const QTextFormat &f)
QTextCharFormat charFormat(int index) const
void setObjectIndex(int object)
Sets the format object's object index.
void clearProperty(int propertyId)
Clears the value of the property given by propertyId.
void setPosition(Position f)
Sets the policy for positioning frames with this frame format.
Position
This enum describes how a frame is located relative to the surrounding text.
int lineCount() const
Returns the number of lines in this text layout.
Style
This enum describes the symbols used to decorate list items:
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.
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.
static QTextTable * createTable(QTextDocumentPrivate *, int pos, int rows, int cols, const QTextTableFormat &tableFormat)
QSet< QString >::iterator it
Combined button and popup list for selecting options.
static QDBusError::ErrorType get(const char *name)
constexpr const T & qMin(const T &a, const T &b)
constexpr const T & qMax(const T &a, const T &b)
n void setPosition(void) \n\
GLboolean GLboolean GLboolean b
GLint GLint GLint GLint GLint x
[0]
GLint GLsizei GLsizei GLenum format
GLenum GLenum GLsizei void GLsizei void * column
GLenum GLenum GLsizei void * row
GLenum GLenum GLsizei void * table
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
#define Q_ASSERT_X(cond, x, msg)
QLatin1StringView QLatin1String
static void getText(QString &text, QTextDocumentPrivate *priv, const QString &docText, int pos, int end)
static void setBlockCharFormatHelper(QTextDocumentPrivate *priv, int pos1, int pos2, const QTextCharFormat &format, QTextDocumentPrivate::FormatChangeMode changeMode)
#define QTextBeginningOfFrame
QVideoFrameFormat::PixelFormat fmt
QItemSelection * selection
[0]
\inmodule QtCore \reentrant