KTextEditor::MovingCursor Class
class KTextEditor::MovingCursorA Cursor which is bound to a specific Document, and maintains its position. More...
Header: | #include <KTextEditor/MovingCursor> |
CMake: | find_package(KF6 REQUIRED COMPONENTS TextEditor) target_link_libraries(mytarget PRIVATE KF6::TextEditor) |
Since: | 4.5 |
Public Types
enum | InsertBehavior { StayOnInsert, MoveOnInsert } |
enum | WrapBehavior { Wrap, NoWrap } |
Public Functions
MovingCursor(const KTextEditor::MovingCursor &) | |
virtual | ~MovingCursor() |
bool | atEndOfDocument() const |
bool | atEndOfLine() const |
bool | atStartOfDocument() const |
bool | atStartOfLine() const |
virtual int | column() const = 0 |
virtual KTextEditor::Document * | document() const = 0 |
bool | gotoNextLine() |
bool | gotoPreviousLine() |
virtual KTextEditor::MovingCursor::InsertBehavior | insertBehavior() const = 0 |
bool | isValid() const |
bool | isValidTextPosition() const |
virtual int | line() const = 0 |
bool | move(int chars, KTextEditor::MovingCursor::WrapBehavior wrapBehavior = Wrap) |
virtual KTextEditor::MovingRange * | range() const = 0 |
void | setColumn(int column) |
virtual void | setInsertBehavior(KTextEditor::MovingCursor::InsertBehavior insertBehavior) = 0 |
void | setLine(int line) |
virtual void | setPosition(KTextEditor::Cursor position) = 0 |
void | setPosition(int line, int column) |
const KTextEditor::Cursor | toCursor() const |
KTextEditor::Cursor | operator KTextEditor::Cursor() const |
KTextEditor::MovingCursor & | operator=(const KTextEditor::MovingCursor &) |
Protected Functions
Related Non-Members
bool | operator!=(const KTextEditor::MovingCursor &c1, const KTextEditor::MovingCursor &c2) |
bool | operator<(const KTextEditor::MovingCursor &c1, const KTextEditor::MovingCursor &c2) |
QDebug | operator<<(QDebug s, const KTextEditor::MovingCursor &cursor) |
QDebug | operator<<(QDebug s, const KTextEditor::MovingCursor *cursor) |
bool | operator<=(const KTextEditor::MovingCursor &c1, const KTextEditor::MovingCursor &c2) |
bool | operator==(const KTextEditor::MovingCursor &c1, const KTextEditor::MovingCursor &c2) |
bool | operator>(const KTextEditor::MovingCursor &c1, const KTextEditor::MovingCursor &c2) |
bool | operator>=(const KTextEditor::MovingCursor &c1, const KTextEditor::MovingCursor &c2) |
Detailed Description
A MovingCursor is an extension of the basic Cursor class. It maintains its position in the document. As a result of this, MovingCursor%s may not be copied, as they need to maintain a connection to the associated Document.
Create a new MovingCursor like this:
// Retrieve the MovingInterface KTextEditor::MovingInterface* moving = qobject_cast<KTextEditor::MovingInterface*>( yourDocument ); if ( moving ) { KTextEditor::MovingCursor* cursor = moving->newMovingCursor(); }
When finished with a MovingCursor, simply delete it. If the document the cursor belong to is deleted, it will get deleted automatically.
See also Cursor, Range, MovingRange, and MovingInterface.
Member Type Documentation
enum MovingCursor::InsertBehavior
Insert behavior of this cursor, should it stay if text is insert at its position or should it move.
Constant | Value | Description |
---|---|---|
KTextEditor::MovingCursor::StayOnInsert | 0x0 | Stay on insert. |
KTextEditor::MovingCursor::MoveOnInsert | 0x1 | Move on insert. |
enum MovingCursor::WrapBehavior
Wrap behavior for end of line treatement used in move().
Constant | Value | Description |
---|---|---|
KTextEditor::MovingCursor::Wrap | 0x0 | Wrap at end of line |
KTextEditor::MovingCursor::NoWrap | 0x1 | Do not wrap at end of line |
Member Function Documentation
[protected]
MovingCursor::MovingCursor()
For inherited class only.
MovingCursor::MovingCursor(const KTextEditor::MovingCursor &)
no copy constructor, don't allow this to be copied.
[virtual noexcept]
MovingCursor::~MovingCursor()
Destruct the moving cursor.
bool MovingCursor::atEndOfDocument() const
Determine if this cursor is located at the end of the last line in the document.
Returns true if the cursor is at the end of the document, otherwise false.
bool MovingCursor::atEndOfLine() const
Determine if this cursor is located at the end of the current line.
Returns true if the cursor is situated at the end of the line, otherwise false.
bool MovingCursor::atStartOfDocument() const
Determine if this cursor is located at line 0 and column 0.
Returns true if the cursor is at start of the document, otherwise false.
bool MovingCursor::atStartOfLine() const
Determine if this cursor is located at column 0 of a valid text line.
Returns true if cursor is a valid text position and column()=0, otherwise false.
[pure virtual]
int MovingCursor::column() const
Retrieve the column on which this cursor is situated.
Returns column number, where 0 is the first column.
See also setColumn().
[pure virtual]
KTextEditor::Document *MovingCursor::document() const
Gets the document to which this cursor is bound.
Returns a pointer to the document
bool MovingCursor::gotoNextLine()
Moves the cursor to the next line and sets the column to 0. If the cursor position is already in the last line of the document, the cursor position remains unchanged and the return value is false.
Returns true on success, otherwise false
bool MovingCursor::gotoPreviousLine()
Moves the cursor to the previous line and sets the column to 0. If the cursor position is already in line 0, the cursor position remains unchanged and the return value is false.
Returns true on success, otherwise false
[pure virtual]
KTextEditor::MovingCursor::InsertBehavior MovingCursor::insertBehavior() const
Get current insert behavior. Returns current insert behavior
See also setInsertBehavior().
bool MovingCursor::isValid() const
Returns whether the current position of this cursor is a valid position, i.e. whether line() >= 0 and column() >= 0.
Returns true , if the cursor position is valid, otherwise false
bool MovingCursor::isValidTextPosition() const
Check whether this MovingCursor is located at a valid text position.
A cursor position at (line, column) is valid, if:
- line >= 0 and line < document()->lines() holds, and
- column >= 0 and column <= lineLength(column).
Further, the text position is also invalid if it is inside a Unicode surrogate (utf-32 character).
Returns true, if the cursor is a valid text position, otherwise false
See also Document::isValidTextPosition().
[pure virtual]
int MovingCursor::line() const
Retrieve the line on which this cursor is situated.
Returns line number, where 0 is the first line.
See also setLine().
bool MovingCursor::move(int chars, KTextEditor::MovingCursor::WrapBehavior wrapBehavior = Wrap)
Moves the cursor chars character forward or backwards. If wrapBehavior equals WrapBehavior::Wrap, the cursor is automatically wrapped to the next line at the end of a line.
When moving backwards, the WrapBehavior does not have any effect.
Note: If the cursor could not be moved the amount of chars requested, the cursor is not moved at all!
Returns true on success, otherwise false
[pure virtual]
KTextEditor::MovingRange *MovingCursor::range() const
Get range this cursor belongs to, if any Returns range this pointer is part of, else 0
void MovingCursor::setColumn(int column)
Set the cursor column to column.
column is the new cursor column
See also column().
[pure virtual]
void MovingCursor::setInsertBehavior(KTextEditor::MovingCursor::InsertBehavior insertBehavior)
Set insert behavior.
insertBehavior is the new insert behavior
See also insertBehavior().
void MovingCursor::setLine(int line)
Set the cursor line to line.
line is the new cursor line
See also line().
[pure virtual]
void MovingCursor::setPosition(KTextEditor::Cursor position)
Set the current cursor position to position.
position is the new cursor position
void MovingCursor::setPosition(int line, int column)
This is an overloaded function.
Set the cursor position to line and column.
line is the new cursor line
column is the new cursor column
const KTextEditor::Cursor MovingCursor::toCursor() const
Convert this clever cursor into a dumb one. Even if this cursor belongs to a range, the created one not. Returns normal cursor
KTextEditor::Cursor MovingCursor::operator KTextEditor::Cursor() const
Convert this clever cursor into a dumb one. Equal to toCursor, allowing to use implicit conversion. Even if this cursor belongs to a range, the created one not. Returns normal cursor
KTextEditor::MovingCursor &MovingCursor::operator=(const KTextEditor::MovingCursor &)
no assignment operator, no copying around clever cursors.
Related Non-Members
bool operator!=(const KTextEditor::MovingCursor &c1, const KTextEditor::MovingCursor &c2)
Inequality operator.
c1 is the first cursor to compare
c2 is the second cursor to compare
Returns true, if c1's and c2's line and column are not equal.
bool operator<(const KTextEditor::MovingCursor &c1, const KTextEditor::MovingCursor &c2)
Less than operator.
c1 is the first cursor to compare
c2 is the second cursor to compare
Returns true, if c1's position is greater than or equal to c2's position, otherwise false.
QDebug operator<<(QDebug s, const KTextEditor::MovingCursor &cursor)
qDebug() stream operator. Writes this cursor to the debug output in a nicely formatted way.
s is the debug stream
cursor is the cursor to print
Returns debug stream
QDebug operator<<(QDebug s, const KTextEditor::MovingCursor *cursor)
qDebug() stream operator. Writes this cursor to the debug output in a nicely formatted way.
s is the debug stream
cursor is the cursor to print
Returns debug stream
bool operator<=(const KTextEditor::MovingCursor &c1, const KTextEditor::MovingCursor &c2)
Less than or equal to operator.
c1 is the first cursor to compare
c2 is the second cursor to compare
Returns true, if c1's position is lesser than or equal to c2's position, otherwise false.
bool operator==(const KTextEditor::MovingCursor &c1, const KTextEditor::MovingCursor &c2)
Equality operator.
Note: comparison between two invalid cursors is undefined. comparison between an invalid and a valid cursor will always be false.
c1 is the first cursor to compare
c2 is the second cursor to compare
Returns true, if c1's and c2's line and column are equal.
bool operator>(const KTextEditor::MovingCursor &c1, const KTextEditor::MovingCursor &c2)
Greater than operator.
c1 is the first cursor to compare
c2 is the second cursor to compare
Returns true, if c1's position is greater than c2's position, otherwise false.
bool operator>=(const KTextEditor::MovingCursor &c1, const KTextEditor::MovingCursor &c2)
Greater than or equal to operator.
c1 is the first cursor to compare
c2 is the second cursor to compare
Returns true, if c1's position is greater than or equal to c2's position, otherwise false.