66 :
priv(p), x(0),
position(0), anchor(0), adjusted_anchor(0),
67 currentCharFormat(-1), visualNavigation(false), keepPositionOnInsert(false),
106 if (charsAddedOrRemoved < 0 &&
position < positionOfChange - charsAddedOrRemoved)
114 if (
anchor >= positionOfChange
116 if (charsAddedOrRemoved < 0 &&
anchor < positionOfChange - charsAddedOrRemoved)
117 anchor = positionOfChange;
119 anchor += charsAddedOrRemoved;
124 if (charsAddedOrRemoved < 0 &&
adjusted_anchor < positionOfChange - charsAddedOrRemoved)
169 int startRow, startCol, numRows, numCols;
171 clearCells(table, startRow, startCol, numRows, numCols, op);
186 for (
int row = startRow; row < startRow + numRows; ++row)
187 for (
int col = startCol; col < startCol + numCols; ++col) {
192 priv->
remove(startPos, endPos - startPos, op);
224 if (f_position != f_anchor) {
242 if (positionChain.
at(i) != anchorChain.
at(i))
247 if (i < positionChain.
size())
250 if (i < positionChain.
size())
254 if (i < anchorChain.
size())
257 if (i < anchorChain.
size())
261 f_position = positionChain.
at(i-1);
271 if (c_position != c_anchor) {
273 int col_position = c_position.
column();
274 int col_anchor = c_anchor.
column();
275 if (col_position == col_anchor) {
276 before = c_position.
row() < c_anchor.
row();
278 before = col_position < col_anchor;
316 qSwap(curFrom, curTo);
321 if (cellStart.
row() >= removedCellFrom.
row() && cellEnd.
row() <= removedCellEnd.
row()
326 if (removedCellFrom.
row() == 0 && removedCellEnd.
row() == t->
rows()-1)
342 else if (cellStart.
row() >= removedCellFrom.
row() && cellStart.
row() <= removedCellEnd.
row()
343 && cellEnd.
row() > removedCellEnd.
row()) {
344 int newPosition = t->
cellAt(removedCellEnd.
row() + 1, cellStart.
column()).firstPosition();
352 int newPosition = t->
cellAt(cellStart.
row(), removedCellEnd.
column()+1).firstPosition();
376 if (!visualMovement) {
442 if (relativePos == 0)
448 if ((relativePos == blockIt.
length() - 1)
452 if (relativePos < blockIt.
length()-1)
466 int blockPosition = blockIt.
position();
471 int row = cell.
row() - 1;
473 blockPosition = table->
cellAt(row, cell.
column()).lastPosition();
503 if (blockIt.
length() >= 1)
521 const int len = blockIt.
length() - 1;
522 if (relativePos >= len)
526 while (relativePos < len && engine->atWordSeparator(relativePos))
529 while (relativePos < len && !engine->atSpace(relativePos) && !engine->
atWordSeparator(relativePos))
532 newPosition = blockIt.
position() + relativePos;
536 if (blockIt.
length() >= 1)
541 blockIt = blockIt.
next();
581 if (row < table->rows()) {
582 blockPosition = table->
cellAt(row, cell.
column()).firstPosition();
589 blockIt = blockIt.
next();
592 blockIt = blockIt.
next();
619 int column = cell.
column();
620 int row = cell.
row();
621 const int currentRow = row;
625 if (column >= table->
columns()) {
629 cell = table->
cellAt(row, column);
633 || cell.
row() < row));
642 cell = table->
cellAt(row, column);
646 || cell.
row() < row));
664 int newColumn = otherCell.
column();
698 if (cell_pos == cell_anchor)
723 if (cell_pos == cell_anchor)
726 *firstRow =
qMin(cell_pos.
row(), cell_anchor.
row());
740 for (; it !=
end; it = it.
next()) {
755 int row_start, col_start, num_rows, num_cols;
759 for (
int r = row_start; r < row_start + num_rows; ++r) {
760 for (
int c = col_start;
c < col_start + num_cols; ++
c) {
799 int row_start, col_start, num_rows, num_cols;
803 for (
int r = row_start; r < row_start + num_rows; ++r) {
804 for (
int c = col_start;
c < col_start + num_cols; ++
c) {
847 int row_start, col_start, num_rows, num_cols;
851 for (
int r = row_start; r < row_start + num_rows; ++r) {
852 for (
int c = col_start;
c < col_start + num_cols; ++
c) {
1171 qWarning(
"QTextCursor::setPosition: Position '%d' out of range", pos);
1273 for (; n > 0; --n) {
1280 if (previousPosition < d->
position) {
1375 return d ?
d->
x : -1;
1465 bool hasEditBlock =
false;
1468 hasEditBlock =
true;
1486 for (
int i = 0; i < text.
length(); ++i) {
1489 const int blockEnd = i;
1492 && (i + 1) < text.
length()
1504 if (!hasEditBlock) {
1505 hasEditBlock =
true;
1509 if (blockEnd > blockStart)
1516 if (textStart + blockStart < textEnd)
1517 d->
priv->
insert(
d->
position, textStart + blockStart, textEnd - textStart - blockStart, formatIdx);
1570 int fpos = fragIt.position();
1597 switch (selection) {
1734 const int offsetInFragment =
qMax(0, pos - fragIt.position());
1735 const int len =
qMin(
int(frag->
size_array[0] - offsetInFragment), end - pos);
1763 int row_start, col_start, num_rows, num_cols;
1767 for (
int r = row_start; r < row_start + num_rows; ++r) {
1768 for (
int c = col_start;
c < col_start + num_cols; ++
c) {
1773 int cr = cell.
row();
1937 idx = it.value()->format;
1980 format.
merge(modifier);
2222 if(!
d || !
d->
priv || rows == 0 || cols == 0)
2299 if (fragment.
d && fragment.
d->
doc)
2317 #ifndef QT_NO_TEXTHTMLPARSER 2327 #endif // QT_NO_TEXTHTMLPARSER 2399 qWarning(
"QTextCursor::insertImage: attempt to add an invalid image");
2442 Q_ASSERT_X(
d->
priv == rhs.
d->
priv,
"QTextCursor::operator<",
"cannot compare cursors attached to different documents");
2465 Q_ASSERT_X(
d->
priv == rhs.
d->
priv,
"QTextCursor::operator<=",
"cannot compare cursors attached to different documents");
2508 Q_ASSERT_X(
d->
priv == rhs.
d->
priv,
"QTextCursor::operator>=",
"cannot compare cursors attached to different documents");
2530 Q_ASSERT_X(
d->
priv == rhs.
d->
priv,
"QTextCursor::operator>",
"cannot compare cursors attached to different documents");
2610 return d == other.
d;
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
int objectIndex() const
Returns the index of the format object, or -1 if the format object is invalid.
T qobject_cast(QObject *object)
int columns() const
Returns the number of columns in the table.
QTextCharFormat charFormat(int index) const
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.
QTextTable * complexSelectionTable() const
QTextEngine * engine() const
int anchor() const
Returns the anchor position; this is the same as position() unless there is a selection in which case...
void endEditBlock()
Indicates the end of a block of editing operations on the document that should appear as a single ope...
static void getText(QString &text, QTextDocumentPrivate *priv, const QString &docText, int pos, int end)
QString text() const
Returns the block's contents as plain text.
bool keepPositionOnInsert() const
Returns whether the cursor should keep its current position when text gets inserted at the position o...
The QTextCharFormat class provides formatting information for characters in a QTextDocument.
The QTextListFormat class provides formatting information for lists in a QTextDocument.
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)
#define QT_END_NAMESPACE
This macro expands to.
bool atWordSeparator(int position) const
const QChar at(int i) const
Returns the character at the given index position in the string.
void remove(int pos, int length, QTextUndoCommand::Operation=QTextUndoCommand::MoveCursor)
#define it(className, varName)
The QTextFrame class represents a frame in a QTextDocument.
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.
int selectionEnd() const
Returns the end of the selection or position() if the cursor doesn't have a selection.
bool isNull() const
Returns true if it is a null image, otherwise returns false.
bool operator!=(const QTextCursor &rhs) const
Returns true if the other cursor is at a different position in the document as this cursor; otherwise...
int length() const
Returns the number of characters in this string.
void setBlockCharFormat(const QTextCharFormat &format)
Sets the block char format of the current block (or all blocks that are contained in the selection) t...
The QTextLine class represents a line of text inside a QTextLayout.
void insertImage(const QTextImageFormat &format, QTextFrameFormat::Position alignment)
Inserts the image defined by the given format at the cursor's current position with the specified ali...
static qreal position(QGraphicsObject *item, QDeclarativeAnchorLine::AnchorLine anchorLine)
QTextList * createList(const QTextListFormat &format)
Creates and returns a new list with the given format, and makes the current paragraph the cursor is i...
int textLength() const
Returns the length of the text in the line.
bool isLowSurrogate() const
Returns true if the QChar is the low part of a utf16 surrogate (ie.
QTextDocumentFragmentPrivate * d
QTextBlockFormat blockFormat() const
Returns the block format of the block the cursor is in.
QTextDocument * document() const
Returns the document this cursor is associated with.
QTextLayout * blockLayout(QTextBlock &block) const
#define QTextBeginningOfFrame
bool atBlockStart() const
Returns true if the cursor is at the start of a block; otherwise returns false.
void setBlockFormat(const QTextBlock &from, const QTextBlock &to, const QTextBlockFormat &newFormat, FormatChangeMode mode=SetFormat)
void setCharFormat(const QTextCharFormat &format)
Sets the cursor's current character format to the given format.
QAbstractTextDocumentLayout * layout() const
The QUrl class provides a convenient interface for working with URLs.
The QString class provides a Unicode character string.
QTextFormat format(int idx) const
bool isValid() const
Returns true if this character format is valid; otherwise returns false.
bool isHighSurrogate() const
Returns true if the QChar is the high part of a utf16 surrogate (ie.
void setVerticalMovementX(int x)
Sets the visual x position for vertical cursor movements to x.
void setBlockFormat(const QTextBlockFormat &format, QTextDocumentPrivate::FormatChangeMode changeMode)
const HB_CharAttributes * attributes() const
int firstPosition() const
Returns the first document position inside the frame.
void mergeBlockFormat(const QTextBlockFormat &modifier)
Modifies the block format of the current block (or all blocks that are contained in the selection) wi...
int blockCharFormatIndex(int node) const
QString selectedText() const
Returns the current selection's text (which may be empty).
bool isValid() const
Returns true if this text line is valid; otherwise returns false.
void aboutToRemoveCell(int from, int to)
QSharedDataPointer< QTextCursorPrivate > d
The QChar class provides a 16-bit Unicode character.
int insertBlock(int pos, int blockFormat, int charFormat, QTextUndoCommand::Operation=QTextUndoCommand::MoveCursor)
void insertText(const QString &text)
Inserts text at the current position, using the current character format.
void insert(int pos, const QString &text, int format)
void addCursor(QTextCursorPrivate *c)
FragmentMap::ConstIterator FragmentIterator
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
QTextDocumentFragment selection() const
Returns the current selection (which may be empty) with all its formatting information.
QTextCursor & operator=(const QTextCursor &other)
Makes a copy of cursor and assigns it to this QTextCursor.
QTextCursor()
Constructs a null cursor.
QTextBlock next() const
Returns the text block in the document after this block, or an empty text block if this is the last o...
QTextLine lineForTextPosition(int pos) const
Returns the line that contains the cursor position specified by pos.
int rowSpan() const
Returns the number of rows this cell spans.
bool isInEditBlock() const
int position() const
Returns the index of the block's first character within the document.
int leftCursorPosition(int position) const
void setPosition(Position f)
Sets the policy for positioning frames with this frame format.
QTextFrame * currentFrame() const
Returns a pointer to the current frame.
QTextBlock previous() const
Returns the text block in the document before this block, or an empty text block if this is the first...
bool setPosition(int newPosition)
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...
QTextTableCell cellAt(int row, int col) const
Returns the table cell at the given row and column in the table.
qreal cursorToX(int *cursorPos, Edge edge=Leading) const
Converts the cursor position cursorPos to the corresponding x position inside the line...
void setKeepPositionOnInsert(bool b)
Defines whether the cursor should keep its current position when text gets inserted at the current po...
bool isVisible() const
Returns true if the block is visible; otherwise returns false.
The QTextImageFormat class provides formatting information for images in a QTextDocument.
void setBlockCharFormat(const QTextCharFormat &format, QTextDocumentPrivate::FormatChangeMode changeMode)
#define QT_BEGIN_NAMESPACE
This macro expands to.
FragmentIterator find(int pos) const
MoveMode
If the anchor() is kept where it is and the position() is moved, the text in between will be selected...
int objectType() const
Returns the text format's object type.
int column() const
Returns the number of the column in the table that contains this cell.
int objectIndex() const
Returns the object index of this object.
QTextFrame * frameAt(int pos) const
QTextBlock blocksBegin() const
int blockNumber() const
Returns the number of the block the cursor is in, or 0 if the cursor is invalid.
int lastPosition() const
Returns the last document position inside the frame.
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...
Style
This enum describes the symbols used to decorate list items:
bool isEmpty() const
Returns true if the string has no characters; 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...
QTextFrame * parentFrame() const
Returns the frame's parent frame.
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.
void setName(const QString &name)
Sets the name of the image.
QTextFormatCollection * formatCollection()
void prepend(const T &t)
Inserts value at the beginning of the list.
const T & at(int i) const
Returns the item at index position i in the list.
int lineNumber() const
Returns the position of the line in the text engine.
QTextObject * objectForFormat(int formatIndex) const
bool visualNavigation() const
Returns true if the cursor does visual navigation; otherwise returns false.
QTextObject * createObject(const QTextFormat &newFormat, int objectIndex=-1)
bool movePosition(QTextCursor::MoveOperation op, QTextCursor::MoveMode mode=QTextCursor::MoveAnchor)
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 ...
Q_CORE_EXPORT void qWarning(const char *,...)
bool isEmpty() const
Returns true if the fragment is empty; otherwise returns false.
The QImage class provides a hardware-independent image representation that allows direct access to th...
The QTextBlock class provides a container for text fragments in a QTextDocument.
void mergeBlockCharFormat(const QTextCharFormat &modifier)
Modifies the block char format of the current block (or all blocks that are contained in the selectio...
int row() const
Returns the number of the row in the table that contains this cell.
void select(SelectionType selection)
Selects text in the document according to the given selection.
void insertFragment(const QTextDocumentFragment &fragment)
Inserts the text fragment at the current position().
int position() const
Returns the absolute position of the cursor within the document.
int length() const
Returns the length of the block in characters.
void joinPreviousEditBlock()
int positionInBlock() const
Returns the relative position of the cursor within the block.
The QTextTable class represents a table in a QTextDocument.
const BlockMap & blockMap() const
void mergeCharFormat(const QTextCharFormat &modifier)
Merges the cursor's current character format with the properties described by format modifier...
QTextLine lineAt(int i) const
Returns the {i}-th line of text in this text layout.
void removeSelectedText()
If there is a selection, its content is deleted; otherwise does nothing.
int rightCursorPosition(int position) const
void insert(QTextCursor &cursor) const
QTextList * currentList() const
Returns the current list if the cursor position() is inside a block that is part of a list; otherwise...
QTextCharFormat charFormat() const
Returns the QTextCharFormat that describes the block's character format.
bool isCopyOf(const QTextCursor &other) const
Returns true if this cursor and other are copies of each other, i.e.
QTextBlock block() const
Returns the block that contains the cursor.
void qSwap(T &value1, T &value2)
void clearSelection()
Clears the current selection by setting the anchor to the cursor position.
QTextCharFormat blockCharFormat() const
Returns the block character format of the block the cursor is in.
bool atStart() const
Returns true if the cursor is at the start of the document; otherwise returns false.
void insertBlock()
Inserts a new empty block at the cursor position() with the current blockFormat() and charFormat()...
void removeCursor(QTextCursorPrivate *c)
#define Q_ASSERT_X(cond, where, what)
int serialNumber() const
Returns a number that identifies the contents of this QImage object.
The QTextLayout class is used to lay out and render text.
void insertBlock(const QTextBlockFormat &format, const QTextCharFormat &charFormat)
bool operator>(const QTextCursor &rhs) const
Returns true if the other cursor is positioned earlier in the document than this cursor; otherwise re...
void joinPreviousEditBlock()
Like beginEditBlock() indicates the start of a block of editing operations that should appear as a si...
int previousCursorPosition(int position, QTextLayout::CursorMode mode) const
void beginEditBlock()
Indicates the start of a block of editing operations on the document that should appear as a single o...
virtual QRectF blockBoundingRect(const QTextBlock &block) const =0
Returns the bounding rectangle of block.
SelectionType
This enum describes the types of selection that can be applied with the select() function.
The QSharedData class is a base class for shared data objects.
void merge(const QTextFormat &other)
Merges the other format with this format; where there are conflicts the other format takes precedence...
int nextCursorPosition(int position, QTextLayout::CursorMode mode) const
bool operator<(const QTextCursor &rhs) const
Returns true if the other cursor is positioned later in the document than this cursor; otherwise retu...
int firstPosition() const
Returns the first valid position in the document occupied by this cell.
static QTextTable * createTable(QTextDocumentPrivate *, int pos, int rows, int cols, const QTextTableFormat &tableFormat)
void mergeCachedResources(const QTextDocumentPrivate *priv)
AdjustResult adjustPosition(int positionOfChange, int charsAddedOrRemoved, QTextUndoCommand::Operation op)
int editBlockCursorPosition
int rows() const
Returns the number of rows in the table.
bool isBlockFormat() const
Returns true if this text format is a BlockFormat; otherwise returns false.
The QTextFrameFormat class provides formatting information for frames in a QTextDocument.
void deletePreviousChar()
If there is no selected text, deletes the character before the current cursor position; otherwise del...
The QTextTableCell class represents the properties of a cell in a QTextTable.
bool hasComplexSelection() const
Returns true if the cursor contains a selection that is not simply a range from selectionStart() to s...
int size() const
Returns the number of items in the list.
The QTextBlockFormat class provides formatting information for blocks of text in a QTextDocument...
bool isNull() const
Returns true if the cursor is null; otherwise returns false.
void addResource(int type, const QUrl &name, const QVariant &resource)
Adds the resource resource to the resource cache, using type and name as identifiers.
if(void) toggleToolbarShown
QTextDocumentPrivate * priv
int lastPosition() const
Returns the last valid position in the document occupied by this cell.
bool isCharFormat() const
Returns true if this text format is a CharFormat; otherwise returns false.
Qt::LayoutDirection textDirection() const
Returns the resolved text direction.
void adjustCursor(QTextCursor::MoveOperation m)
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.
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...
bool isValid() const
Returns true if this is a valid table cell; otherwise returns false.
void setVisualNavigation(bool b)
Sets visual navigation to b.
void setPosition(int pos, MoveMode mode=MoveAnchor)
Moves the cursor to the absolute position in the document specified by pos using a MoveMode specified...
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...
bool isValid() const
Returns true if this text block is valid; otherwise returns false.
bool canDelete(int pos) const
int verticalMovementX() const
Returns the visual x position for vertical cursor movements.
bool atBlockEnd() const
Returns true if the cursor is at the end of a block; otherwise returns false.
The QTextTableFormat class provides formatting information for tables in a QTextDocument.
bool atSpace(int position) const
The QTextList class provides a decorated list of items in a QTextDocument.
Qt::CursorMoveStyle defaultCursorMoveStyle
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 ...
void clearProperty(int propertyId)
Clears the value of the property given by propertyId.
QTextCursorPrivate(QTextDocumentPrivate *p)
QTextFrame * insertFrame(int start, int end, const QTextFrameFormat &format)
QTextBlock blocksFind(int pos) const
int columnSpan() const
Returns the number of columns this cell spans.
bool atEnd() const
Returns true if the cursor is at the end of the document; otherwise returns false.
static void setBlockCharFormatHelper(QTextDocumentPrivate *priv, int pos1, int pos2, const QTextCharFormat &format, QTextDocumentPrivate::FormatChangeMode changeMode)
void setCharFormat(int pos, int length, const QTextCharFormat &newFormat, FormatChangeMode mode=SetFormat)
void insertHtml(const QString &html)
Inserts the text html at the current position().
void setObjectIndex(int object)
Sets the format object's object index.
void setCharFormat(const QTextCharFormat &format, QTextDocumentPrivate::FormatChangeMode changeMode)
void deleteChar()
If there is no selected text, deletes the character at the current cursor position; otherwise deletes...
The QTextObject class is a base class for different kinds of objects that can group parts of a QTextD...
static const KeyPair *const end
void setStyle(Style style)
Sets the list format's style.
uint keepPositionOnInsert
int xToCursor(qreal x, CursorPosition=CursorBetweenCharacters) const
Converts the x-coordinate x, to the nearest matching cursor position, depending on the cursor positio...
int columnNumber() const
Returns the position of the cursor within its containing line.
int indexForFormat(const QTextFormat &f)
~QTextCursor()
Destroys the QTextCursor.
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
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...
QTextBlockFormat blockFormat() const
Returns the QTextBlockFormat that describes block-specific properties.
void selectedTableCells(int *firstRow, int *numRows, int *firstColumn, int *numColumns) const
const QChar * constData() const
Returns a pointer to the data stored in the QString.
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't have a selection.
int blockNumber() const
Returns the number of this block, or -1 if the block is invalid.
int textStart() const
Returns the start of the line from the beginning of the string passed to the QTextLayout.
int lineCount() const
Returns the number of lines in this text layout.
QTextDocument * document()
void clearCells(QTextTable *table, int startRow, int startCol, int numRows, int numCols, QTextUndoCommand::Operation op)
The QList class is a template class that provides lists.
QTextBlock blocksEnd() const
QTextLayout * layout() const
Returns the QTextLayout that is used to lay out and display the block's contents. ...