• Skip to content
  • Skip to link menu
KDE 4.3 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KTextEditor

KTextEditor::Cursor

KTextEditor::Cursor Class Reference

An object which represents a position in a Document. More...

#include <cursor.h>

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

List of all members.

Public Member Functions

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

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



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

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

Friends

bool operator!= (const Cursor &c1, const Cursor &c2)
Cursor operator+ (const Cursor &c1, const Cursor &c2)
Cursor & operator+= (Cursor &c1, const Cursor &c2)
Cursor operator- (const Cursor &c1, const Cursor &c2)
Cursor & operator-= (Cursor &c1, const Cursor &c2)
bool operator< (const Cursor &c1, const Cursor &c2)
QDebug operator<< (QDebug s, const Cursor &cursor)
bool operator<= (const Cursor &c1, const Cursor &c2)
bool operator== (const Cursor &c1, const Cursor &c2)
bool operator> (const Cursor &c1, const Cursor &c2)
bool operator>= (const Cursor &c1, const Cursor &c2)

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 60 of file cursor.h.


Constructor & Destructor Documentation

Cursor::Cursor (  ) 

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

Definition at line 25 of file cursor.cpp.

Cursor::Cursor ( int  line,
int  column 
)

This constructor creates a cursor initialized with line and column.

Parameters:
line line for cursor
column column for cursor

Definition at line 32 of file cursor.cpp.

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:
copy the cursor to copy.

Definition at line 39 of file cursor.cpp.

Cursor::~Cursor (  )  [virtual]

Virtual destructor.

Definition at line 128 of file cursor.cpp.


Member Function Documentation

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 152 of file cursor.cpp.

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 147 of file cursor.cpp.

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 78 of file cursor.cpp.

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

For internal use only.

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

Definition at line 137 of file cursor.cpp.

Cursor Cursor::invalid (  )  [static]

Returns an invalid cursor.

Definition at line 51 of file cursor.cpp.

bool Cursor::isSmartCursor (  )  const [virtual]

Returns whether this cursor is a SmartCursor.

Reimplemented in KTextEditor::SmartCursor.

Definition at line 108 of file cursor.cpp.

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 46 of file cursor.cpp.

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 61 of file cursor.cpp.

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

Assignment operator.

Same as setPosition().

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

Reimplemented in KTextEditor::SmartCursor.

Definition at line 201 of file cursor.h.

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

Get both the line and column of the cursor position.

Parameters:
line will be filled with current cursor line
column will be filled with current cursor column

Definition at line 118 of file cursor.cpp.

Range * Cursor::range (  )  const

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

Definition at line 123 of file cursor.cpp.

void Cursor::setColumn ( int  column  )  [virtual]

Set the cursor column to column.

Parameters:
column new cursor column

Definition at line 83 of file cursor.cpp.

void Cursor::setLine ( int  line  )  [virtual]

Set the cursor line to line.

Parameters:
line new cursor line

Definition at line 66 of file cursor.cpp.

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:
line new cursor line
column new cursor column

Definition at line 113 of file cursor.cpp.

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

Set the current cursor position to position.

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

Definition at line 95 of file cursor.cpp.

void Cursor::setRange ( Range *  range  )  [protected, virtual]

For internal use only.

Sets the range that this cursor belongs to.

Parameters:
range the range that this cursor is referenced from.

Definition at line 132 of file cursor.cpp.

Cursor Cursor::start (  )  [static]

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

Definition at line 56 of file cursor.cpp.

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

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

Reimplemented in KTextEditor::SmartCursor.

Definition at line 157 of file cursor.cpp.


Friends And Related Function Documentation

bool operator!= ( const Cursor &  c1,
const Cursor &  c2 
) [friend]

Inequality operator.

Parameters:
c1 first cursor to compare
c2 second cursor to compare
Returns:
true, if c1's and c2's line and column are not equal.

Definition at line 261 of file cursor.h.

Cursor operator+ ( const Cursor &  c1,
const Cursor &  c2 
) [friend]

Addition operator.

Takes two cursors and returns their summation.

Parameters:
c1 the first position
c2 the second position
Returns:
a the summation of the two input cursors

Definition at line 210 of file cursor.h.

Cursor& operator+= ( Cursor &  c1,
const Cursor &  c2 
) [friend]

Addition assignment operator.

Adds c2 to this cursor.

Parameters:
c1 the cursor being added to
c2 the position to add
Returns:
a reference to the cursor which has just been added to

Definition at line 219 of file cursor.h.

Cursor operator- ( const Cursor &  c1,
const Cursor &  c2 
) [friend]

Subtraction operator.

Takes two cursors and returns the subtraction of c2 from c1.

Parameters:
c1 the first position
c2 the second position
Returns:
a cursor representing the subtraction of c2 from c1

Definition at line 230 of file cursor.h.

Cursor& operator-= ( Cursor &  c1,
const Cursor &  c2 
) [friend]

Subtraction assignment operator.

Subtracts c2 from c1.

Parameters:
c1 the cursor being subtracted from
c2 the position to subtract
Returns:
a reference to the cursor which has just been subtracted from

Definition at line 239 of file cursor.h.

bool operator< ( const Cursor &  c1,
const Cursor &  c2 
) [friend]

Less than operator.

Parameters:
c1 first cursor to compare
c2 second cursor to compare
Returns:
true, if c1's position is greater than or equal to c2's position, otherwise false.

Definition at line 291 of file cursor.h.

QDebug operator<< ( QDebug  s,
const Cursor &  cursor 
) [friend]

kDebug() stream operator.

Writes this cursor to the debug output in a nicely formatted way.

Definition at line 307 of file cursor.h.

bool operator<= ( const Cursor &  c1,
const Cursor &  c2 
) [friend]

Less than or equal to operator.

Parameters:
c1 first cursor to compare
c2 second cursor to compare
Returns:
true, if c1's position is lesser than or equal to c2's position, otherwise false.

Definition at line 301 of file cursor.h.

bool operator== ( const Cursor &  c1,
const Cursor &  c2 
) [friend]

Equality operator.

Note:
comparison between two invalid cursors is undefined. comparison between and invalid and a valid cursor will always be false.
Parameters:
c1 first cursor to compare
c2 second cursor to compare
Returns:
true, if c1's and c2's line and column are equal.

Definition at line 252 of file cursor.h.

bool operator> ( const Cursor &  c1,
const Cursor &  c2 
) [friend]

Greater than operator.

Parameters:
c1 first cursor to compare
c2 second cursor to compare
Returns:
true, if c1's position is greater than c2's position, otherwise false.

Definition at line 271 of file cursor.h.

bool operator>= ( const Cursor &  c1,
const Cursor &  c2 
) [friend]

Greater than or equal to operator.

Parameters:
c1 first cursor to compare
c2 second cursor to compare
Returns:
true, if c1's position is greater than or equal to c2's position, otherwise false.

Definition at line 281 of file cursor.h.


Member Data Documentation

int KTextEditor::Cursor::m_column [protected]

For internal use only.

Cursor column

Definition at line 344 of file cursor.h.

int KTextEditor::Cursor::m_line [protected]

For internal use only.

Cursor line

Definition at line 337 of file cursor.h.

Range* KTextEditor::Cursor::m_range [protected]

For internal use only.

Range which owns this cursor, if any

Definition at line 351 of file cursor.h.


The documentation for this class was generated from the following files:
  • cursor.h
  • cursor.cpp

KTextEditor

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal