KTextEditor::LineRange Class

class KTextEditor::LineRange

An object representing lines from a start line to an end line. More...

Header: #include <KTextEditor/LineRange>
CMake: find_package(KF6 REQUIRED COMPONENTS TextEditor)
target_link_libraries(mytarget PRIVATE KF6::TextEditor)
Since: 5.79

Public Functions

LineRange()
LineRange(int start, int end)
bool confineToRange(KTextEditor::LineRange range)
bool contains(KTextEditor::LineRange range) const
bool containsLine(int line) const
KTextEditor::LineRange encompass(KTextEditor::LineRange range) const
int end() const
bool expandToRange(KTextEditor::LineRange range)
KTextEditor::LineRange intersect(KTextEditor::LineRange range) const
bool isValid() const
int numberOfLines() const
bool onSingleLine() const
bool overlaps(KTextEditor::LineRange range) const
bool overlapsLine(int line) const
void setBothLines(int line)
void setEnd(int end)
void setRange(KTextEditor::LineRange range)
void setRange(int start, int end)
void setStart(int start)
int start() const
QString toString() const

Static Public Members

KTextEditor::LineRange fromString(QStringView str)
KTextEditor::LineRange invalid()
bool operator!=(KTextEditor::LineRange r1, KTextEditor::LineRange r2)
KTextEditor::LineRange &operator&=(KTextEditor::LineRange &r1, KTextEditor::LineRange r2)
KTextEditor::LineRange &operator+=(KTextEditor::LineRange &r1, KTextEditor::LineRange r2)
KTextEditor::LineRange &operator-=(KTextEditor::LineRange &r1, KTextEditor::LineRange r2)
bool operator<(KTextEditor::LineRange r1, KTextEditor::LineRange r2)
QDebug operator<<(QDebug s, KTextEditor::LineRange range)
bool operator==(KTextEditor::LineRange r1, KTextEditor::LineRange r2)
bool operator>(KTextEditor::LineRange r1, KTextEditor::LineRange r2)

Detailed Description

A LineRange is a basic class which represents a range of lines, from a start() line to an end() line.

For simplicity and convenience, ranges always maintain their start() line to be before or equal to their end() line. 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 line. In the constructor, the start and end will be swapped if necessary.

See also Range.

Member Function Documentation

[constexpr noexcept] LineRange::LineRange()

Default constructor. Creates a valid line range with both start and end line set to 0.

[constexpr noexcept] LineRange::LineRange(int start, int end)

Constructor which creates a range from start to end. If start is after end, they will be swapped.

start is the start line

end is the end line

[noexcept] bool LineRange::confineToRange(KTextEditor::LineRange range)

Confine this range if necessary to fit within range.

range range which should contain this range

Returns true if confinement occurred, false otherwise

[constexpr noexcept] bool LineRange::contains(KTextEditor::LineRange range) const

Check whether the this range wholly encompasses range.

range range to check

Returns true, if this range contains range, otherwise false

[constexpr noexcept] bool LineRange::containsLine(int line) const

Returns true if this range wholly encompasses line.

line line to check

Returns true if the line is wholly encompassed by this range, otherwise false.

[constexpr noexcept] KTextEditor::LineRange LineRange::encompass(KTextEditor::LineRange range) const

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

range other range to encompass

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

[constexpr noexcept] int LineRange::end() const

Get the end line of this line range. This will always be >= start().

Returns the end line of this line range.

See also setEnd().

[noexcept] bool LineRange::expandToRange(KTextEditor::LineRange range)

Expand this line range if necessary to contain range.

range range which this range should contain

Returns true if expansion occurred, false otherwise

[static noexcept] KTextEditor::LineRange LineRange::fromString(QStringView str)

Returns a LineRange created from the string str containing the format "[start line, end line]". In case the string cannot be parsed, an LineRange::invalid() is returned.

See also toString().

[constexpr noexcept] KTextEditor::LineRange LineRange::intersect(KTextEditor::LineRange range) const

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

range other line range to intersect with this

Returns the intersection of this range and the supplied range.

[static constexpr noexcept] KTextEditor::LineRange LineRange::invalid()

Returns an invalid line range.

[constexpr noexcept] bool LineRange::isValid() const

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

[constexpr noexcept] int LineRange::numberOfLines() const

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

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

[constexpr noexcept] bool LineRange::onSingleLine() const

Check whether this line range is on one line.

Returns true if both the start and end line are equal, otherwise false

[constexpr noexcept] bool LineRange::overlaps(KTextEditor::LineRange range) const

Check whether the this range overlaps with range.

range range to check against

Returns true, if this range overlaps with range, otherwise false

[constexpr noexcept] bool LineRange::overlapsLine(int line) const

Check whether the range overlaps at least part of line.

line line to check

Returns true, if the range overlaps at least part of line, otherwise false

[noexcept] void LineRange::setBothLines(int line)

Convenience function. Set the start and end lines to line.

line the line number to assign to start() and end()

[noexcept] void LineRange::setEnd(int end)

Set the end line to end.

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

end new end line

See also end().

[noexcept] void LineRange::setRange(KTextEditor::LineRange range)

Set the start and end lines of the range.

Note: If start is after end, they will be reversed.

range is the new range

[noexcept] void LineRange::setRange(int start, int end)

Set the start and end lines of the range.

Note: If start is after end, they will be reversed.

start is the start line of the range

end is the end line of the range

[noexcept] void LineRange::setStart(int start)

Set the start line to start.

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

start new start line

See also start().

[constexpr noexcept] int LineRange::start() const

Get the start line of this line range. This will always be <= end().

Returns the start line of this line range.

See also setStart().

QString LineRange::toString() const

Returns the line range as string in the format "[start line, end line]".

See also fromString().

Related Non-Members

[constexpr noexcept] bool operator!=(KTextEditor::LineRange r1, KTextEditor::LineRange r2)

Inequality operator.

r1 is the first range to compare

r2 is the second range to compare

Returns true if r1 and r2 do not equal, otherwise false

[noexcept] KTextEditor::LineRange &operator&=(KTextEditor::LineRange &r1, KTextEditor::LineRange r2)

Intersects r1 with r2 and assigns the result to r1.

r1 is the range to assign the intersection to

r2 is the range to intersect r1 with

Returns a reference to this range, after the intersection has taken place

[noexcept] KTextEditor::LineRange &operator+=(KTextEditor::LineRange &r1, KTextEditor::LineRange r2)

Addition assignment operator. Adds r2 to this range.

r1 is the first range

r2 is the second range

Returns a reference to the line range which has just been added to

[noexcept] KTextEditor::LineRange &operator-=(KTextEditor::LineRange &r1, KTextEditor::LineRange r2)

Subtraction assignment operator. Subtracts r2 from r1.

r1 is the first range

r2 is the second range

Returns a reference to the range which has just been subtracted from

[constexpr noexcept] bool operator<(KTextEditor::LineRange r1, KTextEditor::LineRange r2)

Less than operator. Looks only at the lines of the two ranges, does not consider their size.

r1 is the first range to compare

r2 is the second range to compare

Returns true if r1 ends before r2 begins, otherwise false

QDebug operator<<(QDebug s, KTextEditor::LineRange range)

qDebug() stream operator. Writes this range to the debug output in a nicely formatted way.

[constexpr noexcept] bool operator==(KTextEditor::LineRange r1, KTextEditor::LineRange r2)

Equality operator.

r1 is the first range to compare

r2 is the second range to compare

Returns true if r1 and r2 equal, otherwise false

[constexpr noexcept] bool operator>(KTextEditor::LineRange r1, KTextEditor::LineRange r2)

Greater than operator. Looks only at the lines of the two ranges, does not consider their size.

r1 is the first range to compare

r2 is the second range to compare

Returns true if r1 starts after where r2 ends, otherwise false