KTextEditor::Range
#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
Definition at line 44 of file include/ktexteditor/range.h.
Constructor & Destructor Documentation
◆ Range() [1/5]
|
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]
Constructor which creates a range from start to end.
If start is after end, they will be swapped.
- Parameters
-
start start position end end position
Definition at line 62 of file include/ktexteditor/range.h.
◆ Range() [3/5]
|
inlineconstexpr |
Constructor which creates a single-line range from start
, extending width
characters along the same line.
- Parameters
-
start start position width width of this range in columns along the same line
Definition at line 73 of file include/ktexteditor/range.h.
◆ Range() [4/5]
|
inlineconstexpr |
Constructor which creates a range from start
, to endLine
, endColumn
.
- Parameters
-
start start position endLine end line endColumn end column
Definition at line 85 of file include/ktexteditor/range.h.
◆ Range() [5/5]
|
inlineconstexpr |
Constructor which creates a range from startLine, startColumn to endLine, endColumn.
- Parameters
-
startLine start line startColumn start column endLine end line endColumn end column
Definition at line 98 of file include/ktexteditor/range.h.
Member Function Documentation
◆ boundaryAtCursor()
|
inlineconstexpr |
◆ columnWidth()
|
inlineconstexpr |
◆ confineToRange()
bool Range::confineToRange | ( | const Range & | range | ) |
Confine this range if necessary to fit within range
.
- Parameters
-
range range which should contain this range
- Returns
- true if confinement occurred, false otherwise
Definition at line 52 of file utils/range.cpp.
◆ contains() [1/2]
|
inlineconstexpr |
Check to see if cursor
is contained within this range, ie >= start() and < end().
- Parameters
-
cursor the 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]
|
inlineconstexpr |
Check whether the this range wholly encompasses range.
- Parameters
-
range range to check
- Returns
- true, if this range contains range, otherwise false
Definition at line 343 of file include/ktexteditor/range.h.
◆ containsColumn()
|
inlineconstexpr |
Check whether the range contains column.
- Parameters
-
column column to check
- Returns
- true if the range contains column, otherwise false
Definition at line 379 of file include/ktexteditor/range.h.
◆ containsLine()
|
inlineconstexpr |
Returns true if this range wholly encompasses line
.
- Parameters
-
line line 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()
Returns the smallest range which encompasses this range and the supplied range.
- Parameters
-
range other 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()
|
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
-
range range which this range should contain
- Returns
- true if expansion occurred, false otherwise
Definition at line 69 of file utils/range.cpp.
◆ fromString()
|
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()
Intersects this range with another, returning the shared area of the two ranges.
- Parameters
-
range other 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()
|
inlinestaticconstexpr |
Returns an invalid range.
Definition at line 115 of file include/ktexteditor/range.h.
◆ isEmpty()
|
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()
|
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()
|
inlineconstexpr |
◆ onSingleLine()
|
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()
|
inlineconstexpr |
Check whether the this range overlaps with range.
- Parameters
-
range range to check against
- Returns
- true, if this range overlaps with range, otherwise false
Definition at line 391 of file include/ktexteditor/range.h.
◆ overlapsColumn()
|
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
-
column the 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()
|
inlineconstexpr |
Check whether the range overlaps at least part of line.
- Parameters
-
line line 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
.
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
.
Definition at line 86 of file utils/range.cpp.
◆ setEnd()
|
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
-
end new end cursor
Definition at line 254 of file include/ktexteditor/range.h.
◆ setRange() [1/2]
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
-
start start cursor end end 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
-
range range to assign to this range
◆ setStart()
|
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
-
start new start cursor
Definition at line 238 of file include/ktexteditor/range.h.
◆ start()
|
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()
|
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()
|
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:
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon May 8 2023 03:50:24 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.