QCodeEdit  2.2
Classes | Public Types | Signals | Public Member Functions | Friends
QDocument Class Reference

A class storing a document. More...

Inheritance diagram for QDocument:
Inheritance graph
[legend]

List of all members.

Classes

struct  PaintContext

Public Types

enum  LineEnding {
  Conservative, Local, Unix, Windows,
  Mac, OldMac = Mac
}
enum  TextProcessing { RemoveTrailingWS = 1, PreserveIndent = 2, RestoreTrailingIndent = 4 }
enum  WhiteSpaceFlag { ShowNone = 0x00, ShowTrailing = 0x01, ShowLeading = 0x02, ShowTabs = 0x04 }

Signals

void cleanChanged (bool m)
void undoAvailable (bool y)
void redoAvailable (bool y)
void formatsChanged ()
void contentsChanged ()
void formatsChange (int line, int lines)
void contentsChange (int line, int lines)
void widthChanged (int width)
void heightChanged (int height)
void sizeChanged (const QSize &s)
void lineCountChanged (int n)
void visualLineCountChanged (int n)
void lineDeleted (QDocumentLineHandle *h)
void markChanged (QDocumentLineHandle *l, int m, bool on)
void lineEndingChanged (int lineEnding)

Public Member Functions

QDocumentPrivateimpl ()
void markViewDirty ()

Friends

class QMatcher
class QDocumentPrivate
class QDocumentCommand
 QDocument (QObject *p=0)
 ctor
virtual ~QDocument ()
 dtor
QString text (int mode) const
QString text (bool removeTrailing=false, bool preserveIndent=true) const
void setText (const QString &s)
 Set the content of the document.
void startChunkLoading ()
 Start a chunk loading.
void stopChunkLoading ()
 Stop chunk loading.
void addChunk (const QString &txt)
 Add a chunk of text to the document.
LineEnding lineEnding () const
LineEnding originalLineEnding () const
void setLineEnding (LineEnding le)
 Set the line ending policy of the document.
QDateTime lastModified () const
void setLastModified (const QDateTime &d)
 set the date/time of the last modification of the document
bool canUndo () const
bool canRedo () const
int width () const
int height () const
int widthConstraint () const
int lines () const
int lineCount () const
int visualLines () const
int visualLineCount () const
int visualLineNumber (int textLineNumber) const
 Convert a text (logical) line number int a visual line number.
int textLineNumber (int visualLineNumber) const
 Convert a visual line number int a text (logical) line number.
int y (int line) const
int lineNumber (int ypos, int *wrap=0) const
int y (const QDocumentLine &l) const
QRect lineRect (int line) const
QRect lineRect (const QDocumentLine &l) const
QDocumentCursoreditCursor () const
 Set the edit cursor.
void setEditCursor (QDocumentCursor *c)
 Set the edit cursor.
QLanguageDefinitionlanguageDefinition () const
void setLanguageDefinition (QLanguageDefinition *l)
 Set the language definition.
int maxMarksPerLine () const
int findNextMark (int id, int from=0, int until=-1) const
 Find the next mark of a given type.
int findPreviousMark (int id, int from=-1, int until=0) const
 Find the previous mark of a given type.
QDocumentLine lineAt (const QPoint &p) const
void cursorForDocumentPosition (const QPoint &p, int &line, int &column) const
 Convert a document (or viewport) (x, y) position to a (line, column) cursor position.
QDocumentCursor cursorAt (const QPoint &p) const
QDocumentLine line (int line) const
QDocumentLine line (QDocumentConstIterator iterator) const
QDocumentCursor cursor (int line, int column=0) const
QDocumentLine findLine (int &position) const
bool isLineModified (const QDocumentLine &l) const
bool hasLineEverBeenModified (const QDocumentLine &l) const
virtual void draw (QPainter *p, PaintContext &cxt)
 Draw the contents of the document.
void execute (QDocumentCommand *cmd)
 Execute a document command (editing operation)
QDocumentConstIterator begin () const
QDocumentConstIterator end () const
QDocumentConstIterator iterator (int ln) const
QDocumentConstIterator iterator (const QDocumentLine &l) const
void beginMacro ()
 Begin a macro.
void endMacro ()
 End a macro.
QFormatSchemeformatScheme () const
void setFormatScheme (QFormatScheme *f)
 Set the format scheme used by the document.
int getNextGroupId ()
 Get an available group id for matches.
void releaseGroupId (int groupId)
void clearMatches (int groupId)
 Clear matches.
void flushMatches (int groupId)
void addMatch (int groupId, int line, int pos, int len, int format)
 Highlight the matched sequences.
bool isClean () const
static QFont font ()
static void setFont (const QFont &f)
 Set the font of ALL documents.
static const QFontMetrics & fontMetrics ()
static LineEnding defaultLineEnding ()
static void setDefaultLineEnding (LineEnding le)
 Set the default line ending policy.
static int tabStop ()
static void setTabStop (int n)
 Set the default tab stop common to all documents.
static WhiteSpaceMode showSpaces ()
static void setShowSpaces (WhiteSpaceMode y)
 Set the whitespace display mode.
static QFormatSchemedefaultFormatScheme ()
static void setDefaultFormatScheme (QFormatScheme *f)
 Set the default format scheme.
static QFormatSchemeformatFactory ()
 Compatibility alias for defaultFormatScheme()
static void setFormatFactory (QFormatScheme *f)
 Compatibility alias for setDefaultFormatScheme()
static int screenLength (const QChar *d, int l, int tabStop)
static QString screenable (const QChar *d, int l, int tabStop)
void clear ()
 Clear the content of the document.
void undo ()
 Undo the last editing operation.
void redo ()
 Redo the last undone editing operation.
void setClean ()
 Set the document to clean state.
void highlight ()
 Update the formatting of the whole document This function is only useful when changing the language definition of a non-empty document. Make sure you do not call it more often than needed.
void print (QPrinter *p)
 Print the content of the document.
void clearWidthConstraint ()
 Clear the width constraint, if any.
void setWidthConstraint (int width)
 Set a new width constraint.

Detailed Description

A class storing a document.

QCE uses an architecture very similar to that of QTextEdit/QTextDocument which closely ressembles model/view. The document holds all the textual and formatting data. It offers some (mostly indirect) ways of modifying its content and is usable without any GUI.

In QCE, a document is merely a list of QDocumentLine objects on which some extra formatting can be applied and which can be wrapped/hidden in various ways.

The document model has been designed with three goals in mind :

QDocument supports Bidi by using QTextLayout on lines that require it and prefers custom rendering in other cases to achieve the above goals.

All the actual text editing is done through QDocumentCursor objects.

See also:
QDocumentLine
QDocumentCursor

Member Function Documentation

void QDocument::addMatch ( int  gid,
int  line,
int  pos,
int  len,
int  format 
)

Highlight the matched sequences.

Note:
Both position are BEFORE the matched characters (cursor position).

References QDocumentPrivate::addMatch().

Referenced by QNFADefinition::match(), QDocumentSearch::next(), and QDocumentSearch::setOption().

QDocumentConstIterator QDocument::begin ( ) const
Returns:
a document iterator pointing to the first line

Referenced by iterator().

void QDocument::beginMacro ( )
bool QDocument::canRedo ( ) const
Returns:
whether there are commands to redo on the command stack

Referenced by QEditor::canRedo().

bool QDocument::canUndo ( ) const
Returns:
whether there commands to undo on the command stack

Referenced by QEditor::canUndo().

QDocumentCursor QDocument::cursor ( int  line,
int  column = 0 
) const
Returns:
A cursor operating on the document, placed at a given position
Parameters:
linetarget line number (text line)
columntarget text column
QDocumentCursor QDocument::cursorAt ( const QPoint &  p) const
Returns:
The cursor nearest to a document (x, y) position

References cursorForDocumentPosition().

Referenced by QEditor::cursorForPosition().

void QDocument::cursorForDocumentPosition ( const QPoint &  p,
int &  line,
int &  column 
) const

Convert a document (or viewport) (x, y) position to a (line, column) cursor position.

Parameters:
pdocument position
linewhere the line number will be stored
columnwhere the column (text position within line) will be stored

References line(), and lineNumber().

Referenced by cursorAt().

QFormatScheme * QDocument::defaultFormatScheme ( )
static
Returns:
The default format scheme used to draw document contents

Referenced by formatFactory().

QDocument::LineEnding QDocument::defaultLineEnding ( )
static
Returns:
The default line ending policy

Referenced by QEditConfig::cancel().

void QDocument::draw ( QPainter *  p,
PaintContext cxt 
)
virtual

Draw the contents of the document.

Parameters:
ppainter to use
cxtpaint context (specifies what part of the document to draw, among other things)

Referenced by print().

QDocumentCursor * QDocument::editCursor ( ) const

Set the edit cursor.

Archaic concept designed for use in QEditor (is it still used???)

QDocumentConstIterator QDocument::end ( ) const
Returns:
a document iterator pointing past the last line

Referenced by iterator().

QDocumentLine QDocument::findLine ( int &  position) const
Returns:
the document line which contains a given (document-wide) text position
Note:
The sole purpose of this method is to have an API close to that of QTextDocument. This method being ridiculously slow it is recommended to avoid it whenever possible.
int QDocument::findNextMark ( int  id,
int  from = 0,
int  until = -1 
) const

Find the next mark of a given type.

Returns:
the line on which a mark was found
Parameters:
idmark identifier to find
fromline from which to start search
untilline until which to search

from and until can be negatives, in which case they indicate positions from the end of the document (i.e -1 is last line, -2 the line before last line and so on).

If until is inferior to from and no matching mark is found in the [from, end] range then the [0, until] range will also be searched.

int QDocument::findPreviousMark ( int  id,
int  from = -1,
int  until = 0 
) const

Find the previous mark of a given type.

Returns:
the line on which a mark was found
Parameters:
idmark identifier to find
fromline from which to start search
untilline until which to search

from and until can be negatives, in which case they indicate positions from the end of the document (i.e -1 is last line, -2 the line before last line and so on).

If until is superior to from and no matching mark is found in the [0, from] range then the [until, end] range will also be searched (both range being searched backward, of course).

void QDocument::flushMatches ( int  gid)
QFont QDocument::font ( )
static
Returns:
the font used by ALL documents to render their content

This font is also used to do calculations (such as converting (line, column) cursor position to (x, y) document position (or the inverse transformation))

Note:
this limitation is historic and may disappear in future versions

Referenced by QEditConfig::cancel(), and QEditor::zoom().

const QFontMetrics & QDocument::fontMetrics ( )
static
Returns:
The font metrics used by ALL documents
Note:
this limitation is historic and may disappear in future versions

Referenced by QEditor::ensureCursorVisible(), QEditor::ensureVisible(), QEditor::isCursorVisible(), QEditor::pageDown(), and QEditor::pageUp().

QFormatScheme * QDocument::formatFactory ( )
static
QFormatScheme * QDocument::formatScheme ( ) const
Returns:
The format scheme used by the document

Referenced by QFormatConfig::apply(), QNFADefinition::match(), QDocumentSearch::next(), and QDocumentSearch::setOption().

bool QDocument::hasLineEverBeenModified ( const QDocumentLine l) const
Returns:
Whether a given line has been modified since last load
int QDocument::height ( ) const
Returns:
the height of the document, in pixels

Referenced by QEditor::load(), and QEditor::setText().

bool QDocument::isClean ( ) const
Returns:
Whether the document is in a clean state

This is undo stak terminology. A clean document is one whose undo stack is at the same index it was upon last save/load. In other words : clean = !modified

Referenced by QEditor::isContentModified().

bool QDocument::isLineModified ( const QDocumentLine l) const
Returns:
Whether a given line has been modified since last save/load
QDocumentConstIterator QDocument::iterator ( int  ln) const
Returns:
a document iterator pointing to a given line

References begin().

Referenced by line(), and setClean().

QDocumentConstIterator QDocument::iterator ( const QDocumentLine l) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Note:
If you can avoid using this method, do so unless performance really isn't an issue

References begin(), and end().

QLanguageDefinition * QDocument::languageDefinition ( ) const
Returns:
the language definition set to the document
QDateTime QDocument::lastModified ( ) const
Returns:
the date/time of the last modification of the document

If the document has not been modified since its load the date/time of last modification (as reported by QFileInfo) will be returned.

QDocumentLine QDocument::line ( int  line) const
QDocumentLine QDocument::line ( QDocumentConstIterator  iterator) const
Returns:
the line object to which an iterator points

References iterator().

QDocumentLine QDocument::lineAt ( const QPoint &  p) const
Returns:
the line at a given document position

References line(), and lineNumber().

Referenced by QEditor::lineAtPosition().

int QDocument::lineCount ( ) const
Returns:
the number of text lines in the document

The number of visual lines may differ from that of text lines as soon as line wrapping and/or folding are enabled.

Referenced by QGotoLinePanel::editorChange(), print(), setText(), and stopChunkLoading().

QDocument::LineEnding QDocument::lineEnding ( ) const
Returns:
The line ending policy of the document

The line ending policy determines how line endings are used when saving the document (which includes fetching the document's text()).

It can either be conservative (auto detect upon loading and do not modify when saving later on) or enforce a particular line ending (either local line ending or a specific value).

Referenced by setText(), and stopChunkLoading().

int QDocument::lineNumber ( int  ypos,
int *  wrap = 0 
) const
Returns:
the line number corresponding to a given document y coordinate
Parameters:
yposY document coordinate of the target
wrapif not null, will be set to the wrap offset (position of the visual line among the sublines of the wrapped text line).

Referenced by cursorForDocumentPosition(), and lineAt().

QRect QDocument::lineRect ( int  line) const
Returns:
the rectangle (in document position) occupied by the line
Parameters:
linetextual line number
Note:
the width of the returned rectangle is the DOCUMENT's width

References line(), width(), and y().

Referenced by QEditor::lineRect(), and QEditor::selectionRect().

QRect QDocument::lineRect ( const QDocumentLine l) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Returns:
the rectangle (in document position) occupied by the line
\note the width of the returned rectangle is the DOCUMENT's width
\note Significantly slower than the line number based version.

References width(), and y().

int QDocument::lines ( ) const
Returns:
the number of text lines in the document

The number of visual lines may differ from that of text lines as soon as line wrapping and/or folding are enabled.

Deprecated:
Use lineCount() instead

Referenced by QLineNumberPanel::editorChange(), highlight(), print(), and QDocumentCommand::updateTarget().

int QDocument::maxMarksPerLine ( ) const
Returns:
the maximum number of marks on a single line

This is meant for the line mark panel to smartly adapt its size.

QDocument::LineEnding QDocument::originalLineEnding ( ) const
Returns:
the lin endings detected upon loading

This should only ever take the the Window of Linux value if a document has been loaded. If no content has been loaded it will fall back to Local.

Referenced by QEditor::load(), and setLineEnding().

void QDocument::print ( QPrinter *  pr)
slot

Print the content of the document.

Parameters:
prprinter to use
Note:
the printer MUST be initialized (probably using a printing dialog)

References draw(), lineCount(), lines(), and width().

Referenced by QEditor::print().

void QDocument::setClean ( )
slot

Set the document to clean state.

This method does not go back to clean state but tell the stack that the current state is to be considered as the clean state.

References iterator().

Referenced by QEditor::save().

void QDocument::setDefaultFormatScheme ( QFormatScheme f)
static

Set the default format scheme.

Note:
Existing documents using the default format scheme will see their format scheme changed

Referenced by setFormatFactory().

void QDocument::setDefaultLineEnding ( QDocument::LineEnding  le)
static

Set the default line ending policy.

Note:
The line ending policy of existing documents is changed accordingly

References setLineEnding().

Referenced by QEditConfig::apply().

void QDocument::setEditCursor ( QDocumentCursor c)

Set the edit cursor.

See also:
editCursor()
void QDocument::setFont ( const QFont &  f)
static

Set the font of ALL documents.

Note:
this limitation is historic and may disappear in future versions

Referenced by QEditConfig::apply(), QEditConfig::loadKeys(), QDocument(), and QEditor::zoom().

void QDocument::setFormatFactory ( QFormatScheme f)
static

Compatibility alias for setDefaultFormatScheme()

Deprecated:

References setDefaultFormatScheme().

void QDocument::setLastModified ( const QDateTime &  d)

set the date/time of the last modification of the document

You should not need to use that EVER. It is only provided for use in QEditor (and possibly in some panels).

Referenced by QEditor::load().

void QDocument::setTabStop ( int  n)
static

Set the default tab stop common to all documents.

Note:
this limitation is historic and may disappear in future versions

Referenced by QEditConfig::apply().

void QDocument::setWidthConstraint ( int  width)
slot

Set a new width constraint.

Parameters:
widthmaximum width to allow

Passing a value inferior (or equal) to zero clear the width constraint, if any.

Referenced by QEditor::setDefaultFlags(), QEditor::setFlag(), and QEditor::setPanelMargins().

QDocument::WhiteSpaceMode QDocument::showSpaces ( )
static
Returns:
the whitesapce display mode

Referenced by QEditConfig::cancel().

void QDocument::startChunkLoading ( )

Start a chunk loading.

It is possible to load document contents in one piece or by chunks. To achieve the later you have to proceed as follows :

QDocument doc;
// fetch data and add it using doc.addChunk();
See also:
addChunk(const QString&)
stopChunkLoading()

Referenced by QEditor::load().

void QDocument::stopChunkLoading ( )

Stop chunk loading.

See also:
startChunkLoading()

References lineCount(), lineEnding(), and setLineEnding().

Referenced by QEditor::load().

int QDocument::tabStop ( )
static
Returns:
The default tab stop common to ALL documents
Note:
this limitation is historic and may disappear in future versions

Referenced by QEditConfig::cancel(), QEditor::indentSelection(), QEditor::insertText(), and QNFADefinition::unindent().

QString QDocument::text ( int  mode) const
Returns:
The content of the document
Parameters:
modeextra processing to perform on text

References line().

Referenced by QEditor::save(), text(), and QEditor::text().

QString QDocument::text ( bool  removeTrailing = false,
bool  preserveIndent = true 
) const
Returns:
The content of the document
Parameters:
removeTrailingwhether to remove trailing whitespaces
preserveIndentwhether to keep trailing whitespaces when they are indent

References text().

int QDocument::textLineNumber ( int  visualLineNumber) const

Convert a visual line number int a text (logical) line number.

Note:
this is not a 1:1 mapping as logical lines can span over several visual lines
int QDocument::visualLineCount ( ) const
Returns:
the number of visual lines in the document
int QDocument::visualLineNumber ( int  textLineNumber) const

Convert a text (logical) line number int a visual line number.

Note:
this is not a 1:1 mapping as logical lines can span over several visual lines
int QDocument::visualLines ( ) const
Returns:
the number of visual lines in the document
Deprecated:
Use visualLineCount() instead
int QDocument::width ( ) const
Returns:
the width of the document, in pixels

The width of the document is that of longest text line.

Referenced by lineRect(), QEditor::load(), print(), and QEditor::setText().

int QDocument::widthConstraint ( ) const
Returns:
The width constraint imposed on that document

Setting a width constraint on a document achieves line wrapping.

Referenced by QDocumentLineHandle::updateWrap().

int QDocument::y ( int  ln) const
Returns:
The Y document coordinate of a given line
Parameters:
lntextual line number

Referenced by QEditor::ensureVisible(), lineRect(), QEditor::selectionRect(), and y().

int QDocument::y ( const QDocumentLine l) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Returns:
The Y document coordinate of a given line
Parameters:
lline object
Note:
Significantly slower than the line number based version.

References QDocumentLine::lineNumber(), and y().


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