KTextEditor::Range
#include <KTextEditor/Range>
Public Member Functions | |
constexpr | Range () noexcept=default |
constexpr | Range (Cursor start, Cursor end) noexcept |
constexpr | Range (Cursor start, int endLine, int endColumn) noexcept |
constexpr | Range (Cursor start, int width) noexcept |
constexpr | Range (int startLine, int startColumn, int endLine, int endColumn) noexcept |
constexpr Range | encompass (Range range) const noexcept |
constexpr Range | intersect (Range range) const noexcept |
constexpr bool | isValid () const noexcept |
QString | toString () const |
Position | |
The following functions provide access to, and manipulation of, the range's position. | |
constexpr Cursor | start () const noexcept |
constexpr Cursor | end () const noexcept |
constexpr LineRange | toLineRange () const noexcept |
void | setBothLines (int line) noexcept |
void | setBothColumns (int column) noexcept |
void | setRange (Range range) noexcept |
void | setRange (Cursor start, Cursor end) noexcept |
void | setStart (Cursor start) noexcept |
void | setEnd (Cursor end) noexcept |
bool | expandToRange (Range range) noexcept |
bool | confineToRange (Range range) noexcept |
constexpr bool | onSingleLine () const noexcept |
constexpr int | numberOfLines () const noexcept |
constexpr int | columnWidth () const noexcept |
constexpr bool | isEmpty () const noexcept |
Comparison | |
The following functions perform checks against this range in comparison to other lines, columns, cursors, and ranges. | |
constexpr bool | contains (Range range) const noexcept |
constexpr bool | contains (Cursor cursor) const noexcept |
constexpr bool | containsLine (int line) const noexcept |
constexpr bool | containsColumn (int column) const noexcept |
constexpr bool | overlaps (Range range) const noexcept |
constexpr bool | overlapsLine (int line) const noexcept |
constexpr bool | overlapsColumn (int column) const noexcept |
constexpr bool | boundaryAtCursor (Cursor cursor) const noexcept |
Static Public Member Functions | |
static Range | fromString (QStringView str) noexcept |
static constexpr Range | invalid () 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 48 of file include/ktexteditor/range.h.
Constructor & Destructor Documentation
◆ Range() [1/5]
|
constexprdefaultnoexcept |
Default constructor.
Creates a valid range from position (0, 0) to position (0, 0).
◆ 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 64 of file include/ktexteditor/range.h.
◆ Range() [3/5]
|
inlineconstexprnoexcept |
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 77 of file include/ktexteditor/range.h.
◆ Range() [4/5]
|
inlineconstexprnoexcept |
Constructor which creates a range from start
, to endLine
, endColumn
.
- Parameters
-
start start position endLine end line endColumn end column
Definition at line 90 of file include/ktexteditor/range.h.
◆ Range() [5/5]
|
inlineconstexprnoexcept |
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 104 of file include/ktexteditor/range.h.
Member Function Documentation
◆ boundaryAtCursor()
|
inlineconstexprnoexcept |
◆ columnWidth()
|
inlineconstexprnoexcept |
◆ confineToRange()
|
noexcept |
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 50 of file utils/range.cpp.
◆ contains() [1/2]
|
inlineconstexprnoexcept |
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 335 of file include/ktexteditor/range.h.
◆ contains() [2/2]
|
inlineconstexprnoexcept |
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 323 of file include/ktexteditor/range.h.
◆ containsColumn()
|
inlineconstexprnoexcept |
Check whether the range contains column.
- Parameters
-
column column to check
- Returns
- true if the range contains column, otherwise false
Definition at line 359 of file include/ktexteditor/range.h.
◆ containsLine()
|
inlineconstexprnoexcept |
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 347 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 440 of file include/ktexteditor/range.h.
◆ end()
|
inlineconstexprnoexcept |
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 163 of file include/ktexteditor/range.h.
◆ expandToRange()
|
noexcept |
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 67 of file utils/range.cpp.
◆ fromString()
|
staticnoexcept |
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 22 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 427 of file include/ktexteditor/range.h.
◆ invalid()
|
inlinestaticconstexprnoexcept |
Returns an invalid range.
Definition at line 121 of file include/ktexteditor/range.h.
◆ isEmpty()
|
inlineconstexprnoexcept |
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 301 of file include/ktexteditor/range.h.
◆ isValid()
|
inlineconstexprnoexcept |
Validity check.
In the base class, returns true unless the range starts before (0,0).
Definition at line 113 of file include/ktexteditor/range.h.
◆ numberOfLines()
|
inlineconstexprnoexcept |
◆ onSingleLine()
|
inlineconstexprnoexcept |
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 268 of file include/ktexteditor/range.h.
◆ overlaps()
|
inlineconstexprnoexcept |
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 371 of file include/ktexteditor/range.h.
◆ overlapsColumn()
|
inlineconstexprnoexcept |
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 398 of file include/ktexteditor/range.h.
◆ overlapsLine()
|
inlineconstexprnoexcept |
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 383 of file include/ktexteditor/range.h.
◆ setBothColumns()
|
noexcept |
Convenience function.
Set the start and end columns to column
.
Definition at line 89 of file utils/range.cpp.
◆ setBothLines()
|
noexcept |
Convenience function.
Set the start and end lines to line
.
Definition at line 84 of file utils/range.cpp.
◆ setEnd()
|
inlinenoexcept |
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 234 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
Definition at line 41 of file utils/range.cpp.
◆ setRange() [2/2]
|
noexcept |
Set the start and end cursors to range.start() and range.end() respectively.
- Parameters
-
range range to assign to this range
Definition at line 35 of file utils/range.cpp.
◆ setStart()
|
inlinenoexcept |
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 218 of file include/ktexteditor/range.h.
◆ start()
|
inlineconstexprnoexcept |
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 153 of file include/ktexteditor/range.h.
◆ toLineRange()
|
inlineconstexprnoexcept |
Convert this Range to a LineRange.
- Returns
- LineRange from the start line to the end line of this range.
Definition at line 173 of file include/ktexteditor/range.h.
◆ toString()
QString Range::toString | ( | ) | const |
Returns the cursor position as string in the format "start-line:start-column,endl-line:end-column".
- See also
- fromString()
Definition at line 140 of file utils/range.cpp.
The documentation for this class was generated from the following files:
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:01:56 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.