KTextEditor::Range

Search for usage in LXR

#include <KTextEditor/Range>

Public Member Functions

constexpr Range () Q_DECL_NOEXCEPT
 
constexpr Range (const Cursor &start, const Cursor &end) Q_DECL_NOEXCEPT
 
constexpr Range (const Cursor &start, int endLine, int endColumn) Q_DECL_NOEXCEPT
 
constexpr Range (const Cursor &start, int width) Q_DECL_NOEXCEPT
 
constexpr Range (int startLine, int startColumn, int endLine, int endColumn) Q_DECL_NOEXCEPT
 
constexpr Range encompass (const Range &range) const Q_DECL_NOEXCEPT
 
constexpr Range intersect (const Range &range) const Q_DECL_NOEXCEPT
 
constexpr bool isValid () const Q_DECL_NOEXCEPT
 
QString toString () const
 
Position

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

constexpr Cursor start () const Q_DECL_NOEXCEPT
 
constexpr Cursor end () const Q_DECL_NOEXCEPT
 
constexpr LineRange toLineRange () const Q_DECL_NOEXCEPT
 
void setBothLines (int line) Q_DECL_NOEXCEPT
 
void setBothColumns (int column) Q_DECL_NOEXCEPT
 
void setRange (const Range &range) Q_DECL_NOEXCEPT
 
void setRange (const Cursor &start, const Cursor &end) Q_DECL_NOEXCEPT
 
void setStart (const Cursor &start) Q_DECL_NOEXCEPT
 
void setEnd (const Cursor &end) Q_DECL_NOEXCEPT
 
bool expandToRange (const Range &range) Q_DECL_NOEXCEPT
 
bool confineToRange (const Range &range) Q_DECL_NOEXCEPT
 
constexpr bool onSingleLine () const Q_DECL_NOEXCEPT
 
constexpr int numberOfLines () const Q_DECL_NOEXCEPT
 
constexpr int columnWidth () const Q_DECL_NOEXCEPT
 
constexpr bool isEmpty () const Q_DECL_NOEXCEPT
 
Comparison

The following functions perform checks against this range in comparison to other lines, columns, cursors, and ranges.

constexpr bool contains (const Range &range) const Q_DECL_NOEXCEPT
 
constexpr bool contains (const Cursor &cursor) const Q_DECL_NOEXCEPT
 
constexpr bool containsLine (int line) const Q_DECL_NOEXCEPT
 
constexpr bool containsColumn (int column) const Q_DECL_NOEXCEPT
 
constexpr bool overlaps (const Range &range) const Q_DECL_NOEXCEPT
 
constexpr bool overlapsLine (int line) const Q_DECL_NOEXCEPT
 
constexpr bool overlapsColumn (int column) const Q_DECL_NOEXCEPT
 
constexpr bool boundaryAtCursor (const Cursor &cursor) const Q_DECL_NOEXCEPT
 

Static Public Member Functions

static Range fromString (QStringView str) Q_DECL_NOEXCEPT
 
constexpr static Range invalid () Q_DECL_NOEXCEPT
 

Detailed Description

An object representing a section of text, from one Cursor to another.

A Range is a basic class which represents a range of text with two Cursors, from a start() position to an end() position.

For simplicity and convenience, ranges always maintain their start position to be before or equal to their end position. Attempting to set either the start or end of the range beyond the respective end or start will result in both values being set to the specified position. In the constructor, the start and end will be swapped if necessary.

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

See also
MovingRange
Author
Hamish Rodda <rodda[email protected]@kde[email protected].org>

Definition at line 44 of file include/ktexteditor/range.h.

Constructor & Destructor Documentation

◆ Range() [1/5]

constexpr KTextEditor::Range::Range ( )
inlineconstexpr

Default constructor.

Creates a valid range from position (0, 0) to position (0, 0).

Definition at line 51 of file include/ktexteditor/range.h.

◆ Range() [2/5]

constexpr KTextEditor::Range::Range ( const Cursor start,
const Cursor end 
)
inlineconstexpr

Constructor which creates a range from start to end.

If start is after end, they will be swapped.

Parameters
startstart position
endend position

Definition at line 62 of file include/ktexteditor/range.h.

◆ Range() [3/5]

constexpr KTextEditor::Range::Range ( const Cursor start,
int  width 
)
inlineconstexpr

Constructor which creates a single-line range from start, extending width characters along the same line.

Parameters
startstart position
widthwidth of this range in columns along the same line

Definition at line 73 of file include/ktexteditor/range.h.

◆ Range() [4/5]

constexpr KTextEditor::Range::Range ( const Cursor start,
int  endLine,
int  endColumn 
)
inlineconstexpr

Constructor which creates a range from start, to endLine, endColumn.

Parameters
startstart position
endLineend line
endColumnend column

Definition at line 85 of file include/ktexteditor/range.h.

◆ Range() [5/5]

constexpr KTextEditor::Range::Range ( int  startLine,
int  startColumn,
int  endLine,
int  endColumn 
)
inlineconstexpr

Constructor which creates a range from startLine, startColumn to endLine, endColumn.

Parameters
startLinestart line
startColumnstart column
endLineend line
endColumnend column

Definition at line 98 of file include/ktexteditor/range.h.

Member Function Documentation

◆ boundaryAtCursor()

constexpr bool KTextEditor::Range::boundaryAtCursor ( const Cursor cursor) const
inlineconstexpr

Check whether cursor is located at either of the start() or end() boundaries.

Parameters
cursorcursor to check
Returns
true if the cursor is equal to start() or end(), otherwise false.

Definition at line 432 of file include/ktexteditor/range.h.

◆ columnWidth()

constexpr int KTextEditor::Range::columnWidth ( ) const
inlineconstexpr

Returns the number of columns separating the start() and end() positions.

Returns
the number of columns separating the start() and end() positions; 0 if the start and end columns are the same.

Definition at line 310 of file include/ktexteditor/range.h.

◆ confineToRange()

bool Range::confineToRange ( const Range range)

Confine this range if necessary to fit within range.

Parameters
rangerange which should contain this range
Returns
true if confinement occurred, false otherwise

Definition at line 52 of file utils/range.cpp.

◆ contains() [1/2]

constexpr bool KTextEditor::Range::contains ( const Cursor cursor) const
inlineconstexpr

Check to see if cursor is contained within this range, ie >= start() and < end().

Parameters
cursorthe position to test for containment
Returns
true if the cursor is contained within this range, otherwise false.

Definition at line 355 of file include/ktexteditor/range.h.

◆ contains() [2/2]

constexpr bool KTextEditor::Range::contains ( const Range range) const
inlineconstexpr

Check whether the this range wholly encompasses range.

Parameters
rangerange to check
Returns
true, if this range contains range, otherwise false

Definition at line 343 of file include/ktexteditor/range.h.

◆ containsColumn()

constexpr bool KTextEditor::Range::containsColumn ( int  column) const
inlineconstexpr

Check whether the range contains column.

Parameters
columncolumn to check
Returns
true if the range contains column, otherwise false

Definition at line 379 of file include/ktexteditor/range.h.

◆ containsLine()

constexpr bool KTextEditor::Range::containsLine ( int  line) const
inlineconstexpr

Returns true if this range wholly encompasses line.

Parameters
lineline to check
Returns
true if the line is wholly encompassed by this range, otherwise false.

Definition at line 367 of file include/ktexteditor/range.h.

◆ encompass()

constexpr Range KTextEditor::Range::encompass ( const Range range) const
inlineconstexpr

Returns the smallest range which encompasses this range and the supplied range.

Parameters
rangeother range to encompass
Returns
the smallest range which contains this range and the supplied range.

Definition at line 460 of file include/ktexteditor/range.h.

◆ end()

constexpr Cursor KTextEditor::Range::end ( ) const
inlineconstexpr

Get the end position of this range.

This will always be >= start().

Returns
const reference to the end position of this range.

Definition at line 183 of file include/ktexteditor/range.h.

◆ expandToRange()

bool Range::expandToRange ( const Range range)

Expand this range if necessary to contain range.

Parameters
rangerange which this range should contain
Returns
true if expansion occurred, false otherwise

Definition at line 69 of file utils/range.cpp.

◆ fromString()

Range Range::fromString ( QStringView  str)
static

Returns a Range created from the string str containing the format "[(start-line, start-column), (endl-line:end-column)]".

In case the string cannot be parsed, an Range::invalid() is returned.

See also
toString()

Definition at line 24 of file utils/range.cpp.

◆ intersect()

constexpr Range KTextEditor::Range::intersect ( const Range range) const
inlineconstexpr

Intersects this range with another, returning the shared area of the two ranges.

Parameters
rangeother range to intersect with this
Returns
the intersection of this range and the supplied range.

Definition at line 447 of file include/ktexteditor/range.h.

◆ invalid()

constexpr static Range KTextEditor::Range::invalid ( )
inlinestaticconstexpr

Returns an invalid range.

Definition at line 115 of file include/ktexteditor/range.h.

◆ isEmpty()

constexpr bool KTextEditor::Range::isEmpty ( ) const
inlineconstexpr

Returns true if this range contains no characters, ie.

the start() and end() positions are the same.

Returns
true if the range contains no characters, otherwise false

Definition at line 321 of file include/ktexteditor/range.h.

◆ isValid()

constexpr bool KTextEditor::Range::isValid ( ) const
inlineconstexpr

Validity check.

In the base class, returns true unless the range starts before (0,0).

Definition at line 107 of file include/ktexteditor/range.h.

◆ numberOfLines()

constexpr int KTextEditor::Range::numberOfLines ( ) const
inlineconstexpr

Returns the number of lines separating the start() and end() positions.

Returns
the number of lines separating the start() and end() positions; 0 if the start and end lines are the same.

Definition at line 299 of file include/ktexteditor/range.h.

◆ onSingleLine()

constexpr bool KTextEditor::Range::onSingleLine ( ) const
inlineconstexpr

Check whether this range is wholly contained within one line, ie.

if the start() and end() positions are on the same line.

Returns
true if both the start and end positions are on the same line, otherwise false

Definition at line 288 of file include/ktexteditor/range.h.

◆ overlaps()

constexpr bool KTextEditor::Range::overlaps ( const Range range) const
inlineconstexpr

Check whether the this range overlaps with range.

Parameters
rangerange to check against
Returns
true, if this range overlaps with range, otherwise false

Definition at line 391 of file include/ktexteditor/range.h.

◆ overlapsColumn()

constexpr bool KTextEditor::Range::overlapsColumn ( int  column) const
inlineconstexpr

Check to see if this range overlaps column; that is, if column is between start().column() and end().column().

This function is most likely to be useful in relation to block text editing.

Parameters
columnthe column to test
Returns
true if the column is between the range's starting and ending columns, otherwise false.

Definition at line 418 of file include/ktexteditor/range.h.

◆ overlapsLine()

constexpr bool KTextEditor::Range::overlapsLine ( int  line) const
inlineconstexpr

Check whether the range overlaps at least part of line.

Parameters
lineline to check
Returns
true, if the range overlaps at least part of line, otherwise false

Definition at line 403 of file include/ktexteditor/range.h.

◆ setBothColumns()

void KTextEditor::Range::setBothColumns ( int  column)

Convenience function.

Set the start and end columns to column.

Parameters
columnthe column number to assign to start() and end()

Definition at line 91 of file utils/range.cpp.

◆ setBothLines()

void Range::setBothLines ( int  line)

Convenience function.

Set the start and end lines to line.

Parameters
linethe line number to assign to start() and end()

Definition at line 86 of file utils/range.cpp.

◆ setEnd()

void KTextEditor::Range::setEnd ( const Cursor end)
inline

Set the end cursor to end.

Note
If end is in front of current start, start and end will be set to new end value.
Parameters
endnew end cursor

Definition at line 254 of file include/ktexteditor/range.h.

◆ setRange() [1/2]

void KTextEditor::Range::setRange ( const Cursor start,
const Cursor end 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Set the start and end cursors to start and end respectively.

Note
If start is after end, they will be reversed.
Parameters
startstart cursor
endend cursor

◆ setRange() [2/2]

void KTextEditor::Range::setRange ( const Range range)

Set the start and end cursors to range.start() and range.end() respectively.

Parameters
rangerange to assign to this range

◆ setStart()

void KTextEditor::Range::setStart ( const Cursor start)
inline

Set the start cursor to start.

Note
If start is after current end, start and end will be set to new start value.
Parameters
startnew start cursor

Definition at line 238 of file include/ktexteditor/range.h.

◆ start()

constexpr Cursor KTextEditor::Range::start ( ) const
inlineconstexpr

Get the start position of this range.

This will always be <= end().

Returns
const reference to the start position of this range.

Definition at line 173 of file include/ktexteditor/range.h.

◆ toLineRange()

constexpr LineRange KTextEditor::Range::toLineRange ( ) const
inlineconstexpr

Convert this Range to a LineRange.

Returns
LineRange from the start line to the end line of this range.

Definition at line 193 of file include/ktexteditor/range.h.

◆ toString()

QString KTextEditor::Range::toString ( ) const
inline

Returns the cursor position as string in the format "start-line:start-column,endl-line:end-column".

See also
fromString()

Definition at line 125 of file include/ktexteditor/range.h.


The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Fri Sep 30 2022 03:52:09 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.