Public Types | |
| enum | MoveFlag { MoveAnchor = 0, KeepAnchor = 1, ThroughWrap = 2 } |
| enum | MoveOperation { NoMove, Up, Down, Left, PreviousCharacter = Left, Right, NextCharacter = Right, Start, StartOfLine, StartOfBlock = StartOfLine, StartOfWord, PreviousBlock, PreviousLine = PreviousBlock, PreviousWord, WordLeft, WordRight, End, EndOfLine, EndOfBlock = EndOfLine, EndOfWord, NextWord, NextBlock, NextLine = NextBlock } |
| enum | SelectionType { WordUnderCursor, LineUnderCursor } |
Public Member Functions | |
| Q_DECLARE_FLAGS (MoveMode, MoveFlag) | |
| QDocumentCursorHandle * | handle () const |
| QDocumentCursor (QDocument *doc) | |
| QDocumentCursor (const QDocumentCursor &cursor) | |
| QDocumentCursor (QDocument *doc, int line, int column=0) | |
| QDocumentCursor (QDocumentCursorHandle *handle=0) | |
| QDocumentCursor | clone () const |
| QDocumentCursor & | operator= (const QDocumentCursor &c) |
| bool | operator== (const QDocumentCursor &c) const |
| comparision operator | |
| bool | operator!= (const QDocumentCursor &c) const |
| comparision operator | |
| bool | operator< (const QDocumentCursor &c) const |
| comparision operator | |
| bool | operator> (const QDocumentCursor &c) const |
| comparision operator | |
| bool | operator<= (const QDocumentCursor &c) const |
| comparision operator | |
| bool | operator>= (const QDocumentCursor &c) const |
| comparision operator | |
| bool | isNull () const |
| comparision operator | |
| bool | isValid () const |
| comparision operator | |
| bool | atEnd () const |
| bool | atStart () const |
| bool | atBlockEnd () const |
| bool | atBlockStart () const |
| bool | atLineEnd () const |
| bool | atLineStart () const |
| bool | hasSelection () const |
| bool | isSilent () const |
| void | setSilent (bool y) |
| Set whether the cursor is silent. | |
| bool | isAutoUpdated () const |
| void | setAutoUpdated (bool y) |
| Set whether the cursor is aut updated. | |
| int | position () const |
| int | lineNumber () const |
| int | columnNumber () const |
| int | anchorLineNumber () const |
| int | anchorColumnNumber () const |
| int | visualColumnNumber () const |
| void | setColumnNumber (int c, MoveMode m=MoveAnchor) |
| Set the text column of the cursor. | |
| int | wrappedLineOffset () const |
| int | anchorWrappedLineOffset () const |
| QPoint | documentPosition () const |
| QPoint | anchorDocumentPosition () const |
| QPolygon | documentRegion () const |
| QDocumentLine | line () const |
| QDocumentLine | anchorLine () const |
| void | shift (int offset) |
| Shift cursor position (text column) by a number of columns (characters). | |
| void | setPosition (int pos, MoveMode m=MoveAnchor) |
| Set the text position of the cursor (within the whole document). | |
| bool | movePosition (int offset, MoveOperation op=NextCharacter, MoveMode m=MoveAnchor) |
| Moves the cursor position. | |
| void | moveTo (int line, int column) |
| Jump to another cursor position. | |
| void | moveTo (const QDocumentCursor &c) |
| Jump to the position of another cursor. | |
| void | moveTo (const QDocumentLine &l, int column) |
| Jump to another cursor position. | |
| void | eraseLine () |
| erase the whole line the cursor is on, newline included | |
| void | insertLine () |
| insert a new line at the cursor position | |
| void | insertText (const QString &s) |
| insert some text at the cursor position | |
| QDocumentCursor | selectionStart () const |
| QDocumentCursor | selectionEnd () const |
| QString | selectedText () const |
| void | clearSelection () |
| clear the selection | |
| void | removeSelectedText () |
| Remove the selected text. | |
| void | select (SelectionType t) |
| Select something. | |
| void | setSelectionBoundary (const QDocumentCursor &c) |
| Set the selection boundary. | |
| bool | isWithinSelection (const QDocumentCursor &c) const |
| void | deleteChar () |
| Delete the character at the position immediately after the cursor. | |
| void | deletePreviousChar () |
| Delete the character at the position immediately before the cursor. | |
| void | beginEditBlock () |
| Begin an edit block. | |
| void | endEditBlock () |
| End an edit block. | |
| void | refreshColumnMemory () |
| Refresh the column memory of the cursor. | |
| bool | hasColumnMemory () const |
| void | setColumnMemory (bool y) |
| Set whether the cursor use column memory. | |
| QDocumentSelection | selection () const |
| QDocument * | document () const |
QDocumentCursor is a central class of the public API.
It is the best (as in fastest and easiest) way to iterate over the content of a document.
It is also the only class that allows to perform editing operations.
A cursor position is defined by a line number and a text position within the line.
Every cursor can have one or two cursor positions. In the later case, they delimit a selection. The first position set (before selecting) is referred to as the "anchor" and the other (if it is different from the anchor) is the actual cursor position.
When the cursor does not have a selection, querying informations about the anchor has the same result as querying informations about the cursor position.
Informations you can get about both the anchor and the posiotion :
The visual line to which a given cursor resides can be obtained as follows :
int visual_line = cursor.document()->visualLine(cursor.lineNumber()) + cursor.wrappedLineOffset();
Quick overview of the various coordinate systems :
| int QDocumentCursor::anchorColumnNumber | ( | ) | const |
Referenced by anchorWrappedLineOffset(), QDocumentSearch::next(), and QDocumentSearch::setOption().
| QPoint QDocumentCursor::anchorDocumentPosition | ( | ) | const |
| QDocumentLine QDocumentCursor::anchorLine | ( | ) | const |
| int QDocumentCursor::anchorLineNumber | ( | ) | const |
| int QDocumentCursor::anchorWrappedLineOffset | ( | ) | const |
References anchorColumnNumber(), anchorLine(), and QDocumentLine::wrappedLineForCursor().
| bool QDocumentCursor::atBlockEnd | ( | ) | const |
| bool QDocumentCursor::atBlockStart | ( | ) | const |
| bool QDocumentCursor::atEnd | ( | ) | const |
Referenced by QEditor::commentSelection(), QEditor::indentSelection(), and QEditor::pageDown().
| bool QDocumentCursor::atLineEnd | ( | ) | const |
| bool QDocumentCursor::atLineStart | ( | ) | const |
| bool QDocumentCursor::atStart | ( | ) | const |
| void QDocumentCursor::beginEditBlock | ( | ) |
Begin an edit block.
Edit blocks are command groups. All the commands in an edit block are executed in a row when the edit block is ended with endEditBlock().
Edit blocks are considered as a single command as far as the undo/redo stack is concerned.
Edit blocks can be nested but that isn't of much use
Referenced by QEditor::commentSelection(), QEditor::indentSelection(), and QDocumentSearch::next().
| int QDocumentCursor::columnNumber | ( | ) | const |
Referenced by QEditor::getCursorPosition(), QEditor::insertFromMimeData(), QEditor::insertText(), QEditor::moveKeyEvent(), QDocumentSearch::next(), QDocumentSearch::setOption(), and wrappedLineOffset().
| QDocument * QDocumentCursor::document | ( | ) | const |
| QPoint QDocumentCursor::documentPosition | ( | ) | const |
Referenced by QEditor::ensureCursorVisible(), and QEditor::isCursorVisible().
| bool QDocumentCursor::hasColumnMemory | ( | ) | const |
| bool QDocumentCursor::hasSelection | ( | ) | const |
Referenced by QEditor::commentSelection(), QEditor::copy(), QEditor::createMimeDataFromSelection(), QEditor::cursorRect(), QEditor::emitCursorPositionChanged(), QEditor::indentSelection(), QEditor::insertFromMimeData(), QEditor::insertText(), QDocumentSearch::next(), selection(), QEditor::selectionChange(), QEditor::selectionRect(), QDocumentSearch::setScope(), QEditor::uncommentSelection(), and QEditor::unindentSelection().
| bool QDocumentCursor::isAutoUpdated | ( | ) | const |
QDocumentCursor c1(10, 0, document), c2(10, 0, document), c(5, 0, document); c1.setAutoUpdated(true); c.insertLine(); // at this point c2 still points to line 10 whereas c1 points to line 11
| bool QDocumentCursor::isSilent | ( | ) | const |
| bool QDocumentCursor::isWithinSelection | ( | const QDocumentCursor & | c | ) | const |
| QDocumentLine QDocumentCursor::line | ( | ) | const |
Referenced by QEditor::insertText(), isNull(), isValid(), QEditor::moveKeyEvent(), QDocumentSearch::next(), QEditor::unindentSelection(), and wrappedLineOffset().
| int QDocumentCursor::lineNumber | ( | ) | const |
Referenced by QEditor::commentSelection(), QEditor::cursorRect(), QEditor::getCursorPosition(), QEditor::indentSelection(), QDocumentSearch::next(), and QDocumentSearch::setOption().
| bool QDocumentCursor::movePosition | ( | int | offset, | |
| MoveOperation | op = NextCharacter, |
|||
| MoveMode | m = MoveAnchor | |||
| ) |
Moves the cursor position.
| offset | number of times the selected move will be done | |
| op | movement type | |
| m | movement mode (whether to select) |
Referenced by QEditor::addPlaceHolder(), QEditor::commentSelection(), QEditor::indentSelection(), QEditor::insertText(), QEditor::moveKeyEvent(), QDocumentSearch::next(), QEditor::pageDown(), QEditor::pageUp(), and QEditor::selectAll().
| void QDocumentCursor::moveTo | ( | const QDocumentLine & | l, | |
| int | column | |||
| ) |
Jump to another cursor position.
| l | target line | |
| column | target text column |
References QDocumentLine::lineNumber().
| void QDocumentCursor::moveTo | ( | const QDocumentCursor & | c | ) |
Jump to the position of another cursor.
| c | target cursor |
| void QDocumentCursor::moveTo | ( | int | line, | |
| int | column | |||
| ) |
Jump to another cursor position.
| line | target line number | |
| colum | target text column |
| bool QDocumentCursor::operator!= | ( | const QDocumentCursor & | c | ) | const |
comparision operator
References m_handle.
| bool QDocumentCursor::operator< | ( | const QDocumentCursor & | c | ) | const |
comparision operator
References m_handle.
| bool QDocumentCursor::operator<= | ( | const QDocumentCursor & | c | ) | const |
comparision operator
References m_handle.
| bool QDocumentCursor::operator== | ( | const QDocumentCursor & | c | ) | const |
comparision operator
References m_handle.
| bool QDocumentCursor::operator> | ( | const QDocumentCursor & | c | ) | const |
comparision operator
References m_handle.
| bool QDocumentCursor::operator>= | ( | const QDocumentCursor & | c | ) | const |
comparision operator
References m_handle.
| int QDocumentCursor::position | ( | ) | const |
| void QDocumentCursor::refreshColumnMemory | ( | ) |
Refresh the column memory of the cursor.
This set the current column memory to the current column position.
| QString QDocumentCursor::selectedText | ( | ) | const |
| QDocumentSelection QDocumentCursor::selection | ( | ) | const |
References hasSelection(), and isNull().
Referenced by QEditor::commentSelection(), QEditor::indentSelection(), QDocumentSearch::next(), QEditor::selectionRect(), QEditor::uncommentSelection(), and QEditor::unindentSelection().
| QDocumentCursor QDocumentCursor::selectionEnd | ( | ) | const |
Referenced by QDocumentSearch::next().
| QDocumentCursor QDocumentCursor::selectionStart | ( | ) | const |
Referenced by QDocumentSearch::next().
| void QDocumentCursor::setColumnNumber | ( | int | c, | |
| MoveMode | m = MoveAnchor | |||
| ) |
Set the text column of the cursor.
| c | text column to set | |
| m | move mode (determines whether text will be selected) |
Referenced by QEditor::insertFromMimeData(), and QDocumentSearch::next().
| void QDocumentCursor::setPosition | ( | int | pos, | |
| MoveMode | m = MoveAnchor | |||
| ) |
Set the text position of the cursor (within the whole document).
Remark made about position() applies.
| int QDocumentCursor::visualColumnNumber | ( | ) | const |
| int QDocumentCursor::wrappedLineOffset | ( | ) | const |
References columnNumber(), line(), and QDocumentLine::wrappedLineForCursor().
1.5.7.1