edbee - Qt Editor Library v0.11.1
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
edbee::TextRangeSetBase Class Referenceabstract

This abstract class represents a set of textranges The ranges are kept ordered and will not contain overlapping regions. More...

#include <textrange.h>

+ Inheritance diagram for edbee::TextRangeSetBase:
+ Collaboration diagram for edbee::TextRangeSetBase:

Public Member Functions

 TextRangeSetBase (TextDocument *doc)
 
virtual ~TextRangeSetBase ()
 
virtual int rangeCount () const =0
 
virtual TextRangerange (int idx)=0
 
virtual const TextRangeconstRange (int idx) const =0
 
virtual void addRange (int anchor, int caret)=0
 
virtual void addRange (const TextRange &range)=0
 
virtual void removeRange (int idx)=0
 
virtual void clear ()=0
 
virtual void toSingleRange ()=0
 
virtual void sortRanges ()=0
 
TextRangelastRange ()
 this method returns the last range
 
TextRangefirstRange ()
 the first range
 
int rangeIndexAtOffset (int offset)
 This method returns the range index at the given offset.
 
bool rangesBetweenOffsets (int offsetBegin, int offsetEnd, int &firstIndex, int &lastIndex)
 returns the range indices that are being overlapped by the given offsetBegin and offsetEnd
 
bool rangesBetweenOffsetsExlusiveEnd (int offsetBegin, int offsetEnd, int &firstIndex, int &lastIndex)
 returns the range indices that are being overlapped by the given offsetBegin and offsetEnd
 
bool rangesAtLine (int line, int &firstIndex, int &lastIndex)
 Returns the range indices that are being used on the given line.
 
bool rangesAtLineExclusiveEnd (int line, int &firstIndex, int &lastIndex)
 Returns the range indices that are being used on the given line (Excluding the last offset)
 
bool hasSelection ()
 This method checks if there's a selection available A selection is an range with a different anchor then it's caret.
 
bool equals (TextRangeSetBase &sel)
 This method checks if two selections are equal.
 
void replaceAll (const TextRangeSetBase &base)
 Replaces all ranges with the supplied ranges.
 
QString getSelectedText ()
 This method returns all selected text For every filled selection range a line is returned.
 
QString getSelectedTextExpandedToFullLines ()
 Returns ALL lines that are touched by the selection. This means Full lines are always returned.
 
QString rangesAsString () const
 This method converts the selection ranges as a string, in the format: anchor>caret,anchor>caret.
 
void beginChanges ()
 This method starts the changes.
 
void endChanges ()
 
void endChangesWithoutProcessing ()
 Ends the changes without processing. WARNING, you should ONLY call this method if the operation you performed kept the rangeset in a valid state. This (at least) means the ranges need to be sorted.
 
bool changing () const
 Checks if the current rangeset is in a changing state.
 
void resetAnchors ()
 This method resets all anchors to the positions of the carets.
 
void clearSelection ()
 This method moves all carets to the anchor positions.
 
void addTextRanges (const TextRangeSetBase &sel)
 An union operation This method adds all text selection-items. Merges all ranges.
 
void substractTextRanges (const TextRangeSetBase &sel)
 The difference operation This method substracts the text-selection from the current selection.
 
void substractRange (int min, int max)
 This method substracts a single range from the ranges list.
 
void expandToFullLines (int amount)
 Expands the selection so it selects full lines.
 
void expandToWords (const QString &whitespace, const QStringList &characterGroups)
 Expands the selection to full words.
 
void selectWordAt (int offset, const QString &whitespace, const QStringList &characterGroups)
 Selects the word at the given offset.
 
void toggleWordSelectionAt (int offset, const QString &whitespace, const QStringList &characterGroups)
 Toggles a word selection at the given location The idea is the following, double-click an empty place to select the word at the given location Double click an existing selection to remove the selection (and caret)
 
void moveCarets (int amount)
 This method moves the carets by character.
 
void moveCaretsOrDeselect (int amount)
 This method moves the carets or deslects the given character.
 
void moveCaretsByCharGroup (int amount, const QString &whitespace, const QStringList &charGroups)
 This method moves the carets.
 
void moveCaretsToLineBoundary (int direction, const QString &whitespace)
 Moves all carets to the given line boundary (line-boundary automatically switches between column 0 and first non-whitespace character)
 
void changeSpatial (int pos, int length, int newLength, bool sticky=false, bool performDelete=false)
 This method adds (or removes) the given spatial length at the given location.
 
void setRange (int anchor, int caret, int index=0)
 This method sets the first range item.
 
void setRange (const TextRange &range, int index=0)
 Sets the range at the given index. Make sure the given index exists!!
 
virtual void processChangesIfRequired (bool joinBorders=false)
 This method process the changes if required.
 
TextDocumenttextDocument () const
 Returns the associated textdocument.
 
void mergeOverlappingRanges (bool joinBorders)
 This method merges overlapping ranges.
 

Protected Attributes

TextDocumenttextDocumentRef_
 The reference to the textbuffer.
 
int changing_
 A (integer) boolean for handling changes between beginChagnes and endChanges.
 

Detailed Description

This abstract class represents a set of textranges The ranges are kept ordered and will not contain overlapping regions.

Every method automatically orders and merges overlapping ranges. Except when the changing_ flag is != 0. The sorting and merging only happens when changing is 0. This way it possible to add/update muliple rages without the direct performance hit of sorting and merging.

Constructor & Destructor Documentation

◆ TextRangeSetBase()

edbee::TextRangeSetBase::TextRangeSetBase ( TextDocument * doc)

◆ ~TextRangeSetBase()

virtual edbee::TextRangeSetBase::~TextRangeSetBase ( )
inlinevirtual

Member Function Documentation

◆ addRange() [1/2]

virtual void edbee::TextRangeSetBase::addRange ( const TextRange & range)
pure virtual

◆ addRange() [2/2]

virtual void edbee::TextRangeSetBase::addRange ( int anchor,
int caret )
pure virtual

◆ addTextRanges()

void edbee::TextRangeSetBase::addTextRanges ( const TextRangeSetBase & sel)

An union operation This method adds all text selection-items. Merges all ranges.

◆ beginChanges()

void edbee::TextRangeSetBase::beginChanges ( )

This method starts the changes.

◆ changeSpatial()

void edbee::TextRangeSetBase::changeSpatial ( int pos,
int length,
int newLength,
bool sticky = false,
bool performDelete = false )

This method adds (or removes) the given spatial length at the given location.

It adjusts all locations, anchors with the given locations. It automatically moves carets, 'removes' selection etc.

Parameters
posthe position to add the spatial length to
lengththe length of the text that's changed
newLengththe new length of the text
sticky,whensticky the caret/anchor is sticky and isn't moved if the change happens at the same location

◆ changing()

bool edbee::TextRangeSetBase::changing ( ) const

Checks if the current rangeset is in a changing state.

◆ clear()

virtual void edbee::TextRangeSetBase::clear ( )
pure virtual

◆ clearSelection()

void edbee::TextRangeSetBase::clearSelection ( )

This method moves all carets to the anchor positions.

◆ constRange()

virtual const TextRange & edbee::TextRangeSetBase::constRange ( int idx) const
pure virtual

◆ endChanges()

void edbee::TextRangeSetBase::endChanges ( )

◆ endChangesWithoutProcessing()

void edbee::TextRangeSetBase::endChangesWithoutProcessing ( )

Ends the changes without processing. WARNING, you should ONLY call this method if the operation you performed kept the rangeset in a valid state. This (at least) means the ranges need to be sorted.

◆ equals()

bool edbee::TextRangeSetBase::equals ( TextRangeSetBase & sel)

This method checks if two selections are equal.

◆ expandToFullLines()

void edbee::TextRangeSetBase::expandToFullLines ( int amount)

Expands the selection so it selects full lines.

◆ expandToWords()

void edbee::TextRangeSetBase::expandToWords ( const QString & whitespace,
const QStringList & characterGroups )

Expands the selection to full words.

◆ firstRange()

TextRange & edbee::TextRangeSetBase::firstRange ( )

the first range

◆ getSelectedText()

QString edbee::TextRangeSetBase::getSelectedText ( )

This method returns all selected text For every filled selection range a line is returned.

◆ getSelectedTextExpandedToFullLines()

QString edbee::TextRangeSetBase::getSelectedTextExpandedToFullLines ( )

Returns ALL lines that are touched by the selection. This means Full lines are always returned.

◆ hasSelection()

bool edbee::TextRangeSetBase::hasSelection ( )

This method checks if there's a selection available A selection is an range with a different anchor then it's caret.

◆ lastRange()

TextRange & edbee::TextRangeSetBase::lastRange ( )

this method returns the last range

◆ mergeOverlappingRanges()

void edbee::TextRangeSetBase::mergeOverlappingRanges ( bool joinBorders)

This method merges overlapping ranges.

Parameters
joinBordersif joinborders is set, borders next to eachother are also interpretted as overlap. (inclusive/exclusive switch)

◆ moveCarets()

void edbee::TextRangeSetBase::moveCarets ( int amount)

This method moves the carets by character.

◆ moveCaretsByCharGroup()

void edbee::TextRangeSetBase::moveCaretsByCharGroup ( int amount,
const QString & whitespace,
const QStringList & charGroups )

This method moves the carets.

◆ moveCaretsOrDeselect()

void edbee::TextRangeSetBase::moveCaretsOrDeselect ( int amount)

This method moves the carets or deslects the given character.

◆ moveCaretsToLineBoundary()

void edbee::TextRangeSetBase::moveCaretsToLineBoundary ( int direction,
const QString & whitespace )

Moves all carets to the given line boundary (line-boundary automatically switches between column 0 and first non-whitespace character)

Parameters
directionthe direction < 0 to the start of the line (or first char) > 0 to the end of the line
whitespacethe characters to see as whitespace

◆ processChangesIfRequired()

void edbee::TextRangeSetBase::processChangesIfRequired ( bool joinBorders = false)
virtual

This method process the changes if required.

Reimplemented in edbee::MultiLineScopedTextRangeSet, and edbee::TextSelection.

◆ range()

virtual TextRange & edbee::TextRangeSetBase::range ( int idx)
pure virtual

◆ rangeCount()

virtual int edbee::TextRangeSetBase::rangeCount ( ) const
pure virtual

◆ rangeIndexAtOffset()

int edbee::TextRangeSetBase::rangeIndexAtOffset ( int offset)

This method returns the range index at the given offset.

Parameters
offsetthe offset to check
Returns
the offset index or -1 if not found

◆ rangesAsString()

QString edbee::TextRangeSetBase::rangesAsString ( ) const

This method converts the selection ranges as a string, in the format: anchor>caret,anchor>caret.

◆ rangesAtLine()

bool edbee::TextRangeSetBase::rangesAtLine ( int line,
int & firstIndex,
int & lastIndex )

Returns the range indices that are being used on the given line.

◆ rangesAtLineExclusiveEnd()

bool edbee::TextRangeSetBase::rangesAtLineExclusiveEnd ( int line,
int & firstIndex,
int & lastIndex )

Returns the range indices that are being used on the given line (Excluding the last offset)

◆ rangesBetweenOffsets()

bool edbee::TextRangeSetBase::rangesBetweenOffsets ( int offsetBegin,
int offsetEnd,
int & firstIndex,
int & lastIndex )

returns the range indices that are being overlapped by the given offsetBegin and offsetEnd

Parameters
offsetBeginthe offset to search
offsetEndthe end-offset to search
firstIndex(out)The first index found (-1 if not found)
lastIndex(out)The last index found (-1 if not found)
Returns
true if the range is found

Todo optimize with a binairy search

◆ rangesBetweenOffsetsExlusiveEnd()

bool edbee::TextRangeSetBase::rangesBetweenOffsetsExlusiveEnd ( int offsetBegin,
int offsetEnd,
int & firstIndex,
int & lastIndex )

returns the range indices that are being overlapped by the given offsetBegin and offsetEnd

Parameters
offsetBeginthe offset to search
offsetEndthe end-offset to search
firstIndex(out)The first index found (-1 if not found)
lastIndex(out)The last index found (-1 if not found)
Returns
true if the range is found

Todo optimize with a binairy search

◆ removeRange()

virtual void edbee::TextRangeSetBase::removeRange ( int idx)
pure virtual

◆ replaceAll()

void edbee::TextRangeSetBase::replaceAll ( const TextRangeSetBase & base)

Replaces all ranges with the supplied ranges.

◆ resetAnchors()

void edbee::TextRangeSetBase::resetAnchors ( )

This method resets all anchors to the positions of the carets.

◆ selectWordAt()

void edbee::TextRangeSetBase::selectWordAt ( int offset,
const QString & whitespace,
const QStringList & characterGroups )

Selects the word at the given offset.

Parameters
offsetthe offset of the word to select

◆ setRange() [1/2]

void edbee::TextRangeSetBase::setRange ( const TextRange & range,
int index = 0 )

Sets the range at the given index. Make sure the given index exists!!

Parameters
therange to use
indexthe index of the range to change (when not given index 0 is assumed)

◆ setRange() [2/2]

void edbee::TextRangeSetBase::setRange ( int anchor,
int caret,
int index = 0 )

This method sets the first range item.

Parameters
anchorthe anchor of the selection
caretthe caret position
indexthe default range index (default 0)

◆ sortRanges()

virtual void edbee::TextRangeSetBase::sortRanges ( )
pure virtual

◆ substractRange()

void edbee::TextRangeSetBase::substractRange ( int min,
int max )

This method substracts a single range from the ranges list.

Todo
Add support for copyrange

◆ substractTextRanges()

void edbee::TextRangeSetBase::substractTextRanges ( const TextRangeSetBase & sel)

The difference operation This method substracts the text-selection from the current selection.

◆ textDocument()

TextDocument * edbee::TextRangeSetBase::textDocument ( ) const

Returns the associated textdocument.

Returns
the associated text document

◆ toggleWordSelectionAt()

void edbee::TextRangeSetBase::toggleWordSelectionAt ( int offset,
const QString & whitespace,
const QStringList & characterGroups )

Toggles a word selection at the given location The idea is the following, double-click an empty place to select the word at the given location Double click an existing selection to remove the selection (and caret)

◆ toSingleRange()

virtual void edbee::TextRangeSetBase::toSingleRange ( )
pure virtual

Member Data Documentation

◆ changing_

int edbee::TextRangeSetBase::changing_
protected

A (integer) boolean for handling changes between beginChagnes and endChanges.

◆ textDocumentRef_

TextDocument* edbee::TextRangeSetBase::textDocumentRef_
protected

The reference to the textbuffer.


The documentation for this class was generated from the following files: