QCodeEdit
2.2
|
A reference to line objects. More...
Public Types | |
enum | State { None = 0, Hidden = 1, CollapsedBlockStart = 2, CollapsedBlockEnd = 4, LayoutDirty = 16, FormatsApplied = 32 } |
Public Member Functions | |
Q_DECLARE_FLAGS (States, State) | |
bool | operator== (const QDocumentLineHandle *h) const |
bool | operator!= (const QDocumentLineHandle *h) const |
QString | indentation () const |
bool | isHidden () const |
QDocumentLineHandle * | handle () const |
QDocumentLine (QDocument *doc) | |
QDocumentLine (const QDocumentLine &line) | |
QDocumentLine (QDocumentLineHandle *h=0) | |
bool | isNull () const |
bool | isValid () const |
bool | operator== (const QDocumentLine &l) const |
Comparision operator. | |
bool | operator!= (const QDocumentLine &l) const |
Comparision operator. | |
bool | operator< (const QDocumentLine &l) const |
Comparision operator. | |
bool | operator>= (const QDocumentLine &l) const |
Comparision operator. | |
bool | operator> (const QDocumentLine &l) const |
Comparision operator. | |
bool | operator<= (const QDocumentLine &l) const |
Comparision operator. | |
QDocumentLine & | operator++ () |
Iterate forward over the document. | |
QDocumentLine & | operator-- () |
Iterate backward over the document. | |
void | operator++ (int) |
Iterate forward over the document. | |
void | operator-- (int) |
Iterate backward over the document. | |
QDocumentLine & | operator= (const QDocumentLine &l) |
copy operator | |
int | lineNumber () const |
int | position () const |
QString | text () const |
int | length () const |
int | lineSpan () const |
int | firstChar () const |
Returns the position of the first non-whitespace character. | |
int | lastChar () const |
Returns the position of the last non-whitespace character. | |
int | indent () const |
int | nextNonSpaceChar (int pos) const |
int | previousNonSpaceChar (int pos) const |
Find the position of the previous char that is not a space. | |
bool | hasFlag (State s) const |
Check whether a given flag is set to the line. | |
bool | hasAnyFlag (int s) const |
Check whether any of the flags in a given combination is set to the line. | |
void | setFlag (State s, bool y=true) |
Set a flag of the line. | |
QDocumentLine | next () const |
QDocumentLine | previous () const |
QDocument * | document () const |
int | xToCursor (int x) const |
Converts a document position (unconstrained viewport) to a cursor position (column) | |
int | cursorToX (int cpos) const |
Converts a cursor position (column) to a document position (unconstrained viewport) | |
int | wrappedLineForCursor (int cpos) const |
int | documentOffsetToCursor (int x, int y) const |
Converts a document offset (viewport) to a cursor position (character / text column) | |
void | cursorToDocumentOffset (int cpos, int &x, int &y) const |
Converts a cursor position (character / text column) to a document offset (viewport) | |
QPoint | cursorToDocumentOffset (int cpos) const |
void | addMark (int id) |
Toggle a mark on the line. | |
void | removeMark (int id) |
Remove a mark from the line. | |
void | toggleMark (int id) |
Toggle a mark on the line. | |
QList< int > | marks () const |
bool | hasMark (int id) const |
bool | hasOverlay (int fid) const |
QList< QFormatRange > | overlays () const |
Clear all overlays applied to the line. | |
void | clearOverlays () |
Clear all overlays applied to the line. | |
void | addOverlay (const QFormatRange &over) |
Add an overlay to the line. | |
void | removeOverlay (const QFormatRange &over) |
Remove an overlay from the line. | |
void | setFormats (const QVector< int > &formats) |
Set the formatting of the line. | |
const QVector< QParenthesis > & | parentheses () const |
void | setParentheses (const QVector< QParenthesis > &parentheses) |
Set the parentheses present on that line. | |
QNFAMatchContext * | matchContext () |
Friends | |
class | QDocumentLineHandle |
class | QDocumentCursorHandle |
A reference to line objects.
In QCodeEdit, documents are stored as a list of lines. A QDocumentLine holds a pointer to the data of one line and gives access to its content.
It is not meant to be used to iterate over the document, though it is possible for conveneience and compatibility reasons. Indeed, QDocumentLine does not now where in the document it is located. It can obtain that information but this is a O(n) operation. Navigation within the document is one of the task devoted to QDocumentCursor which can move around in O(1) (or amortized O(1) in some rare cases).
Lines can be given formatting in various way : "regular" formatting used for highlighting, overlays used mainly to display search matches and similar informations and marks.
void QDocumentLine::addOverlay | ( | const QFormatRange & | over | ) |
Add an overlay to the line.
Overlays are format range that get applied on top of regular formatting.
They are typically used to display search matches, matching braces, ...
void QDocumentLine::cursorToDocumentOffset | ( | int | cpos, |
int & | x, | ||
int & | y | ||
) | const |
Converts a cursor position (character / text column) to a document offset (viewport)
The (x, y) coordinates given by this function are relative to the absolute position of the line, which can be obtained from the document.
QPoint QDocumentLine::cursorToDocumentOffset | ( | int | cpos | ) | const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
int QDocumentLine::cursorToX | ( | int | cpos | ) | const |
Converts a cursor position (column) to a document position (unconstrained viewport)
This function is kept for compatribility only. It dates back to the time before line wrapping was implemented. Due to the limitation of its design (i.e signature) it works in a somewhat awkard way : the x position returned is that the cursor would have in an unconstrained viewport, even when the line is wrapped so it does not map to an actual viewport coordinate, unless of course no wrapping is used.
QDocument * QDocumentLine::document | ( | ) | const |
Referenced by addMark(), marks(), removeMark(), and toggleMark().
int QDocumentLine::documentOffsetToCursor | ( | int | x, |
int | y | ||
) | const |
Converts a document offset (viewport) to a cursor position (character / text column)
The (x, y) coordinates given by this function are relative to the absolute position of the line, which can be obtained from the document.
int QDocumentLine::firstChar | ( | ) | const |
Returns the position of the first non-whitespace character.
References nextNonSpaceChar().
Referenced by QNFADefinition::collapse(), QEditor::insertText(), and QEditor::unindentSelection().
bool QDocumentLine::hasMark | ( | int | id | ) | const |
References marks().
bool QDocumentLine::hasOverlay | ( | int | fid | ) | const |
bool QDocumentLine::isNull | ( | ) | const |
Referenced by QNFADefinition::indent(), and QNFADefinition::unindent().
bool QDocumentLine::isValid | ( | ) | const |
Referenced by QLineMarksInfoCenter::addLineMark(), QNFADefinition::blockFlags(), QNFADefinition::collapse(), QNFADefinition::expand(), QDocumentCursor::isNull(), QDocumentCursor::isValid(), QNFADefinition::match(), QLineMarksInfoCenter::removeLineMark(), QLineMarksInfoCenter::toggleLineMark(), QNFADefinition::tokenize(), and QNFADefinition::unindent().
int QDocumentLine::lastChar | ( | ) | const |
Returns the position of the last non-whitespace character.
References length(), and previousNonSpaceChar().
int QDocumentLine::length | ( | ) | const |
Referenced by lastChar(), QDocumentInsertCommand::QDocumentInsertCommand(), and QDocumentCommand::updateTarget().
int QDocumentLine::lineNumber | ( | ) | const |
Starts at 0, -1 for invalid lines.
Referenced by QDocumentCursor::moveTo(), operator<(), operator<=(), operator>(), operator>=(), and QDocument::y().
int QDocumentLine::lineSpan | ( | ) | const |
This is NOT set to zero when the line is hidden (e.g due to folding).
QList< int > QDocumentLine::marks | ( | ) | const |
QNFAMatchContext * QDocumentLine::matchContext | ( | ) |
Reserved to syntax engines. do not mess with this unless you know what you are doing.
Referenced by QNFADefinition::tokenize(), and QNFADefinition::unindent().
QDocumentLine QDocumentLine::next | ( | ) | const |
Referenced by operator++().
int QDocumentLine::nextNonSpaceChar | ( | int | pos | ) | const |
Find the position of the next char that is not a space.
pos | Column of the character which is examined first. |
Referenced by firstChar().
bool QDocumentLine::operator< | ( | const QDocumentLine & | l | ) | const |
bool QDocumentLine::operator<= | ( | const QDocumentLine & | l | ) | const |
QDocumentLine & QDocumentLine::operator= | ( | const QDocumentLine & | l | ) |
copy operator
QDocumentLine objects are just wrappers around the "real" line data. Copies of a QDocumentLine all points to the same underlying data and modifying one affect them all (no implicit sharing).
Referenced by operator++(), and operator--().
bool QDocumentLine::operator> | ( | const QDocumentLine & | l | ) | const |
bool QDocumentLine::operator>= | ( | const QDocumentLine & | l | ) | const |
const QVector< QParenthesis > & QDocumentLine::parentheses | ( | ) | const |
Referenced by QNFADefinition::blockFlags(), QNFADefinition::indent(), QNFADefinition::match(), and setParentheses().
int QDocumentLine::position | ( | ) | const |
QDocumentLine QDocumentLine::previous | ( | ) | const |
Referenced by operator--().
int QDocumentLine::previousNonSpaceChar | ( | int | pos | ) | const |
Find the position of the previous char that is not a space.
pos | Column of the character which is examined first. |
Referenced by lastChar().
void QDocumentLine::setFlag | ( | State | s, |
bool | y = true |
||
) |
Set a flag of the line.
Referenced by QNFADefinition::collapse(), and QNFADefinition::expand().
void QDocumentLine::setFormats | ( | const QVector< int > & | formats | ) |
Set the formatting of the line.
void QDocumentLine::setParentheses | ( | const QVector< QParenthesis > & | parentheses | ) |
Set the parentheses present on that line.
References parentheses().
QString QDocumentLine::text | ( | ) | const |
Referenced by QNFADefinition::indent(), QEditor::insertText(), QDocumentSearch::next(), QDocumentInsertCommand::QDocumentInsertCommand(), QEditor::text(), QNFADefinition::tokenize(), and QNFADefinition::unindent().
int QDocumentLine::wrappedLineForCursor | ( | int | cpos | ) | const |
cpos | cursor position, as a text column |
Referenced by QDocumentCursor::anchorWrappedLineOffset(), and QDocumentCursor::wrappedLineOffset().
int QDocumentLine::xToCursor | ( | int | xpos | ) | const |
Converts a document position (unconstrained viewport) to a cursor position (column)