edbee - Qt Editor Library
|
This abstract class represents a set of textranges The ranges are kept ordered and will not contain overlapping regions. More...
#include <textrange.h>
Public Member Functions | |
TextRangeSetBase (TextDocument *doc) | |
virtual | ~TextRangeSetBase () |
virtual int | rangeCount () const =0 |
virtual TextRange & | range (int idx)=0 |
virtual const TextRange & | constRange (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 |
TextRange & | lastRange () |
this method returns the last range More... | |
TextRange & | firstRange () |
the first range More... | |
int | rangeIndexAtOffset (int offset) |
This method returns the range index at the given offset. More... | |
bool | rangesBetweenOffsets (int offsetBegin, int offsetEnd, int &firstIndex, int &lastIndex) |
returns the range indices that are being overlapped by the given offsetBegin and offsetEnd More... | |
bool | rangesBetweenOffsetsExlusiveEnd (int offsetBegin, int offsetEnd, int &firstIndex, int &lastIndex) |
returns the range indices that are being overlapped by the given offsetBegin and offsetEnd More... | |
bool | rangesAtLine (int line, int &firstIndex, int &lastIndex) |
Returns the range indices that are being used on the given line. More... | |
bool | hasSelection () |
This method checks if there's a selection available A selection is an range with a different anchor then it's caret. More... | |
bool | equals (TextRangeSetBase &sel) |
This method checks if two selections are equal. More... | |
void | replaceAll (const TextRangeSetBase &base) |
Replaces all ranges with the supplied ranges. More... | |
QString | getSelectedText () |
This method returns all selected text For every filled selection range a line is returned. More... | |
QString | getSelectedTextExpandedToFullLines () |
Returns ALL lines that are touched by the selection. This means Full lines are always returned. More... | |
QString | rangesAsString () const |
This method converts the selection ranges as a string, in the format: anchor>caret,anchor>caret. More... | |
void | beginChanges () |
This method starts the changes. More... | |
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. More... | |
bool | changing () const |
Checks if the current rangeset is in a changing state. More... | |
void | resetAnchors () |
This method resets all anchors to the positions of the carets. More... | |
void | clearSelection () |
This method moves all carets to the anchor positions. More... | |
void | addTextRanges (const TextRangeSetBase &sel) |
An union operation This method adds all text selection-items. Merges all ranges. More... | |
void | substractTextRanges (const TextRangeSetBase &sel) |
The difference operation This method substracts the text-selection from the current selection. More... | |
void | substractRange (int min, int max) |
This method substracts a single range from the ranges list. More... | |
void | expandToFullLines (int amount) |
Expands the selection so it selects full lines. More... | |
void | expandToWords (const QString &whitespace, const QStringList &characterGroups) |
Expands the selection to full words. More... | |
void | selectWordAt (int offset, const QString &whitespace, const QStringList &characterGroups) |
Selects the word at the given offset. More... | |
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 wordt at the given location Double click an existing selection to remove the selection (and caret) More... | |
void | moveCarets (int amount) |
This method moves the carets by character. More... | |
void | moveCaretsOrDeselect (int amount) |
This method moves the carets or deslects the given character. More... | |
void | moveCaretsByCharGroup (int amount, const QString &whitespace, const QStringList &charGroups) |
This method moves the carets. More... | |
void | moveCaretsToLineBoundary (int direction, const QString &whitespace) |
Moves al carets to the given line boundary (line-boundary automaticly switches between column 0 and first non-whitespace character) More... | |
void | moveCaretsByLine (int amount) |
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. More... | |
void | setRange (int anchor, int caret, int index=0) |
This mehtod sets the first range item. More... | |
void | setRange (const TextRange &range, int index=0) |
Sets the range at the given index. Make sure the given index exists!! More... | |
virtual void | processChangesIfRequired (bool joinBorders=false) |
This method process the changes if required. More... | |
TextDocument * | textDocument () const |
Returns the associated textdocument. More... | |
void | mergeOverlappingRanges (bool joinBorders) |
This method merges overlapping ranges. More... | |
Protected Attributes | |
TextDocument * | textDocumentRef_ |
The reference to the textbuffer. More... | |
int | changing_ |
A (integer) boolean for handling changes between beginChagnes and endChanges. More... | |
This abstract class represents a set of textranges The ranges are kept ordered and will not contain overlapping regions.
Every method automaticly 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.
edbee::TextRangeSetBase::TextRangeSetBase | ( | TextDocument * | doc | ) |
|
inlinevirtual |
|
pure virtual |
Implemented in edbee::MultiLineScopedTextRangeSet, and edbee::TextRangeSet.
|
pure virtual |
Implemented in edbee::MultiLineScopedTextRangeSet, and edbee::TextRangeSet.
void edbee::TextRangeSetBase::addTextRanges | ( | const TextRangeSetBase & | sel | ) |
An union operation This method adds all text selection-items. Merges all ranges.
void edbee::TextRangeSetBase::beginChanges | ( | ) |
This method starts the changes.
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 automaticly moves carets, 'removes' selection etc.
pos | the position to add the spatial length to |
length | the length of the text that's changed |
newLength | the new length of the text |
sticky,when | sticky the caret/anchor is sticky and isn't moved if the change happens at the same location |
bool edbee::TextRangeSetBase::changing | ( | ) | const |
Checks if the current rangeset is in a changing state.
|
pure virtual |
Implemented in edbee::MultiLineScopedTextRangeSet, and edbee::TextRangeSet.
void edbee::TextRangeSetBase::clearSelection | ( | ) |
This method moves all carets to the anchor positions.
|
pure virtual |
Implemented in edbee::MultiLineScopedTextRangeSet, and edbee::TextRangeSet.
void edbee::TextRangeSetBase::endChanges | ( | ) |
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.
bool edbee::TextRangeSetBase::equals | ( | TextRangeSetBase & | sel | ) |
This method checks if two selections are equal.
void edbee::TextRangeSetBase::expandToFullLines | ( | int | amount | ) |
Expands the selection so it selects full lines.
void edbee::TextRangeSetBase::expandToWords | ( | const QString & | whitespace, |
const QStringList & | characterGroups | ||
) |
Expands the selection to full words.
TextRange & edbee::TextRangeSetBase::firstRange | ( | ) |
the first range
QString edbee::TextRangeSetBase::getSelectedText | ( | ) |
This method returns all selected text For every filled selection range a line is returned.
QString edbee::TextRangeSetBase::getSelectedTextExpandedToFullLines | ( | ) |
Returns ALL lines that are touched by the selection. This means Full lines are always returned.
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.
TextRange & edbee::TextRangeSetBase::lastRange | ( | ) |
this method returns the last range
void edbee::TextRangeSetBase::mergeOverlappingRanges | ( | bool | joinBorders | ) |
This method merges overlapping ranges.
joinBorders | if joinborders is set, borders next to eachother are also interpretted as overlap. (inclusive/exclusive switch) |
void edbee::TextRangeSetBase::moveCarets | ( | int | amount | ) |
This method moves the carets by character.
void edbee::TextRangeSetBase::moveCaretsByCharGroup | ( | int | amount, |
const QString & | whitespace, | ||
const QStringList & | charGroups | ||
) |
This method moves the carets.
void edbee::TextRangeSetBase::moveCaretsByLine | ( | int | amount | ) |
void edbee::TextRangeSetBase::moveCaretsOrDeselect | ( | int | amount | ) |
This method moves the carets or deslects the given character.
void edbee::TextRangeSetBase::moveCaretsToLineBoundary | ( | int | direction, |
const QString & | whitespace | ||
) |
Moves al carets to the given line boundary (line-boundary automaticly switches between column 0 and first non-whitespace character)
direction | the direction < 0 to the start of the line (or first char) > 0 to the end of the line |
whitespace | the characters to see as whitespace |
|
virtual |
This method process the changes if required.
Reimplemented in edbee::MultiLineScopedTextRangeSet, and edbee::TextSelection.
|
pure virtual |
Implemented in edbee::MultiLineScopedTextRangeSet, and edbee::TextRangeSet.
|
pure virtual |
Implemented in edbee::MultiLineScopedTextRangeSet, and edbee::TextRangeSet.
int edbee::TextRangeSetBase::rangeIndexAtOffset | ( | int | offset | ) |
This method returns the range index at the given offset.
offset | the offset to check |
QString edbee::TextRangeSetBase::rangesAsString | ( | ) | const |
This method converts the selection ranges as a string, in the format: anchor>caret,anchor>caret.
bool edbee::TextRangeSetBase::rangesAtLine | ( | int | line, |
int & | firstIndex, | ||
int & | lastIndex | ||
) |
Returns the range indices that are being used on the given line.
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
offsetBegin | the offset to search |
offsetEnd | the end-offset to search |
firstIndex(out) | The first index found (-1 if not found) |
lastIndex(out) | The last index found (-1 if not found) |
Todo optimize with a binairy search
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
offsetBegin | the offset to search |
offsetEnd | the end-offset to search |
firstIndex(out) | The first index found (-1 if not found) |
lastIndex(out) | The last index found (-1 if not found) |
Todo optimize with a binairy search
|
pure virtual |
Implemented in edbee::MultiLineScopedTextRangeSet, and edbee::TextRangeSet.
void edbee::TextRangeSetBase::replaceAll | ( | const TextRangeSetBase & | base | ) |
Replaces all ranges with the supplied ranges.
void edbee::TextRangeSetBase::resetAnchors | ( | ) |
This method resets all anchors to the positions of the carets.
void edbee::TextRangeSetBase::selectWordAt | ( | int | offset, |
const QString & | whitespace, | ||
const QStringList & | characterGroups | ||
) |
Selects the word at the given offset.
offset | the offset of the wordt to select |
void edbee::TextRangeSetBase::setRange | ( | int | anchor, |
int | caret, | ||
int | index = 0 |
||
) |
This mehtod sets the first range item.
anchor | the anchor of the selection |
caret | the caret position |
index | the default range index (default 0) |
void edbee::TextRangeSetBase::setRange | ( | const TextRange & | range, |
int | index = 0 |
||
) |
Sets the range at the given index. Make sure the given index exists!!
the | range to use |
index | the index of the range to change (when not given index 0 is assumed) |
|
pure virtual |
Implemented in edbee::MultiLineScopedTextRangeSet, and edbee::TextRangeSet.
void edbee::TextRangeSetBase::substractRange | ( | int | min, |
int | max | ||
) |
This method substracts a single range from the ranges list.
void edbee::TextRangeSetBase::substractTextRanges | ( | const TextRangeSetBase & | sel | ) |
The difference operation This method substracts the text-selection from the current selection.
TextDocument * edbee::TextRangeSetBase::textDocument | ( | ) | const |
Returns the associated textdocument.
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 wordt at the given location Double click an existing selection to remove the selection (and caret)
|
pure virtual |
Implemented in edbee::MultiLineScopedTextRangeSet, and edbee::TextRangeSet.
|
protected |
A (integer) boolean for handling changes between beginChagnes and endChanges.
|
protected |
The reference to the textbuffer.