• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KTextEditor

  • KTextEditor
  • Cursor
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
KTextEditor::Cursor Class Reference

#include <cursor.h>

Inheritance diagram for KTextEditor::Cursor:
KTextEditor::SmartCursor

Public Member Functions

 Cursor ()
 
 Cursor (const Cursor &copy)
 
 Cursor (int line, int column)
 
virtual ~Cursor ()
 
virtual bool isSmartCursor () const
 
virtual bool isValid () const
 
Cursor & operator= (const Cursor &cursor)
 
Range * range () const
 
virtual SmartCursor * toSmartCursor () const
 
Position

The following functions provide access to, and manipulation of, the cursor's position.

virtual void setPosition (const Cursor &position)
 
void setPosition (int line, int column)
 
virtual int line () const
 
virtual void setLine (int line)
 
int column () const
 
virtual void setColumn (int column)
 
bool atStartOfLine () const
 
bool atStartOfDocument () const
 
void position (int &line, int &column) const
 

Static Public Member Functions

static Cursor invalid ()
 
static Cursor start ()
 

Protected Member Functions

void cursorChangedDirectly (const Cursor &from)
 
virtual void setRange (Range *range)
 

Protected Attributes

int m_column
 
int m_line
 
Range * m_range
 

Detailed Description

An object which represents a position in a Document.

A Cursor is a basic class which contains the line() and column() a position in a Document. It is very lightweight and maintains no affiliation with a particular Document.

If you want additional functionality such as the ability to maintain position in a document, see SmartCursor.

Note
The Cursor class is designed to be passed via value, while SmartCursor and derivatives must be passed via pointer or reference as they maintain a connection with their document internally and cannot be copied.
Lines and columns start at 0.
Think of cursors as having their position at the start of a character, not in the middle of one.
If a Cursor is associated with a Range the Range will be notified whenever the cursor (i.e. start or end position) changes its position. Read the class documentation about Ranges for further details.
See also
SmartCursor

Definition at line 61 of file cursor.h.

Constructor & Destructor Documentation

◆ Cursor() [1/3]

Cursor::Cursor ( )

The default constructor creates a cursor at position (0,0).

Definition at line 26 of file cursor.cpp.

◆ Cursor() [2/3]

Cursor::Cursor ( int  line,
int  column 
)

This constructor creates a cursor initialized with line and column.

Parameters
lineline for cursor
columncolumn for cursor

Definition at line 33 of file cursor.cpp.

◆ Cursor() [3/3]

Cursor::Cursor ( const Cursor &  copy)

Copy constructor.

Does not copy the owning range, as a range does not have any association with copies of its cursors.

Parameters
copythe cursor to copy.

Definition at line 40 of file cursor.cpp.

◆ ~Cursor()

Cursor::~Cursor ( )
virtual

Virtual destructor.

Definition at line 129 of file cursor.cpp.

Member Function Documentation

◆ atStartOfDocument()

bool KTextEditor::Cursor::atStartOfDocument ( ) const

Determine if this cursor is located at the start of a document.

Returns
true if the cursor is situated at the start of the document, false if it isn't.

Definition at line 153 of file cursor.cpp.

◆ atStartOfLine()

bool KTextEditor::Cursor::atStartOfLine ( ) const

Determine if this cursor is located at the start of a line.

Returns
true if the cursor is situated at the start of the line, false if it isn't.

Definition at line 148 of file cursor.cpp.

◆ column()

int Cursor::column ( ) const

Retrieve the column on which this cursor is situated.

Returns
column number, where 0 is the first column.

Definition at line 79 of file cursor.cpp.

◆ cursorChangedDirectly()

void KTextEditor::Cursor::cursorChangedDirectly ( const Cursor &  from)
protected

Notify the owning range, if any, that this cursor has changed directly.

Definition at line 138 of file cursor.cpp.

◆ invalid()

Cursor Cursor::invalid ( )
static

Returns an invalid cursor.

Definition at line 52 of file cursor.cpp.

◆ isSmartCursor()

bool Cursor::isSmartCursor ( ) const
virtual

Returns whether this cursor is a SmartCursor.

Reimplemented in KTextEditor::SmartCursor.

Definition at line 109 of file cursor.cpp.

◆ isValid()

bool Cursor::isValid ( ) const
virtual

Returns whether the current position of this cursor is a valid position (line + column must both be >= 0).

Smart cursors should override this to return whether the cursor is valid within the linked document.

Reimplemented in KTextEditor::SmartCursor.

Definition at line 47 of file cursor.cpp.

◆ line()

int Cursor::line ( ) const
virtual

Retrieve the line on which this cursor is situated.

Returns
line number, where 0 is the first line.

Definition at line 62 of file cursor.cpp.

◆ operator=()

Cursor & KTextEditor::Cursor::operator= ( const Cursor &  cursor)
inline

Assignment operator.

Same as setPosition().

Parameters
cursorthe position to assign.
Returns
a reference to this cursor
See also
setPosition()

Definition at line 202 of file cursor.h.

◆ position()

void Cursor::position ( int &  line,
int &  column 
) const

Get both the line and column of the cursor position.

Parameters
linewill be filled with current cursor line
columnwill be filled with current cursor column

Definition at line 119 of file cursor.cpp.

◆ range()

Range * Cursor::range ( ) const

Returns the range that this cursor belongs to, if any.

Definition at line 124 of file cursor.cpp.

◆ setColumn()

void Cursor::setColumn ( int  column)
virtual

Set the cursor column to column.

Parameters
columnnew cursor column

Definition at line 84 of file cursor.cpp.

◆ setLine()

void Cursor::setLine ( int  line)
virtual

Set the cursor line to line.

Parameters
linenew cursor line

Definition at line 67 of file cursor.cpp.

◆ setPosition() [1/2]

void Cursor::setPosition ( const Cursor &  position)
virtual

Set the current cursor position to position.

Parameters
positionnew cursor position
Todo:
add bool to indicate success or not, for smart cursors?

Definition at line 96 of file cursor.cpp.

◆ setPosition() [2/2]

void Cursor::setPosition ( int  line,
int  column 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Set the cursor position to line and column.

Parameters
linenew cursor line
columnnew cursor column

Definition at line 114 of file cursor.cpp.

◆ setRange()

void Cursor::setRange ( Range *  range)
protectedvirtual

Sets the range that this cursor belongs to.

Parameters
rangethe range that this cursor is referenced from.

Definition at line 133 of file cursor.cpp.

◆ start()

Cursor Cursor::start ( )
static

Returns a cursor representing the start of any document - i.e., line 0, column 0.

Definition at line 57 of file cursor.cpp.

◆ toSmartCursor()

SmartCursor * KTextEditor::Cursor::toSmartCursor ( ) const
virtual

Returns this cursor as a SmartCursor, if it is one.

Reimplemented in KTextEditor::SmartCursor.

Definition at line 158 of file cursor.cpp.

Member Data Documentation

◆ m_column

int KTextEditor::Cursor::m_column
protected

Cursor column

Definition at line 345 of file cursor.h.

◆ m_line

int KTextEditor::Cursor::m_line
protected

Cursor line

Definition at line 338 of file cursor.h.

◆ m_range

Range* KTextEditor::Cursor::m_range
protected

Range which owns this cursor, if any

Definition at line 352 of file cursor.h.


The documentation for this class was generated from the following files:
  • cursor.h
  • cursor.cpp
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KTextEditor

Skip menu "KTextEditor"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal