Eneboo - Documentación para desarrolladores
Métodos públicos | Amigas
Referencia de la Clase QSyntaxHighlighter

The QSyntaxHighlighter class is a base class for implementing QTextEdit syntax highlighters. Más...

#include <qsyntaxhighlighter.h>

Diagrama de herencias de QSyntaxHighlighter
Qt Qt

Lista de todos los miembros.

Métodos públicos

 QSyntaxHighlighter (QTextEdit *textEdit)
virtual ~QSyntaxHighlighter ()
virtual int highlightParagraph (const QString &text, int endStateOfLastPara)=0
void setFormat (int start, int count, const QFont &font, const QColor &color)
void setFormat (int start, int count, const QColor &color)
void setFormat (int start, int count, const QFont &font)
QTextEdittextEdit () const
void rehighlight ()
int currentParagraph () const
 QSyntaxHighlighter (QTextEdit *textEdit)
virtual ~QSyntaxHighlighter ()
virtual int highlightParagraph (const QString &text, int endStateOfLastPara)=0
void setFormat (int start, int count, const QFont &font, const QColor &color)
void setFormat (int start, int count, const QColor &color)
void setFormat (int start, int count, const QFont &font)
QTextEdittextEdit () const
void rehighlight ()
int currentParagraph () const

Amigas

class QSyntaxHighlighterInternal

Descripción detallada

The QSyntaxHighlighter class is a base class for implementing QTextEdit syntax highlighters.

A syntax highligher automatically highlights parts of the text in a QTextEdit. Syntax highlighters are often used when the user is entering text in a specific format (for example, source code) and help the user to read the text and identify syntax errors.

To provide your own syntax highlighting for QTextEdit, you must subclass QSyntaxHighlighter and reimplement highlightParagraph().

When you create an instance of your QSyntaxHighlighter subclass, pass it the QTextEdit that you want the syntax highlighting to be applied to. After this your highlightParagraph() function will be called automatically whenever necessary. Use your highlightParagraph() function to apply formatting (e.g. setting the font and color) to the text that is passed to it.


Documentación del constructor y destructor

QSyntaxHighlighter::QSyntaxHighlighter ( QTextEdit textEdit)

Constructs the QSyntaxHighlighter and installs it on textEdit.

It is the caller's responsibility to delete the QSyntaxHighlighter when it is no longer needed.

QSyntaxHighlighter::~QSyntaxHighlighter ( ) [virtual]

Destructor. Uninstalls this syntax highlighter from the textEdit()

QSyntaxHighlighter::QSyntaxHighlighter ( QTextEdit textEdit)
virtual QSyntaxHighlighter::~QSyntaxHighlighter ( ) [virtual]

Documentación de las funciones miembro

int QSyntaxHighlighter::currentParagraph ( ) const

Returns the id of the paragraph which is highlighted, or -1 of no paragraph is currently highlighted.

Usually this function is called from within highlightParagraph().

int QSyntaxHighlighter::currentParagraph ( ) const
virtual int QSyntaxHighlighter::highlightParagraph ( const QString text,
int  endStateOfLastPara 
) [pure virtual]
int QSyntaxHighlighter::highlightParagraph ( const QString text,
int  endStateOfLastPara 
) [pure virtual]

This function is called when necessary by the rich text engine, i.e. on paragraphs which have changed.

In your reimplementation you should parse the paragraph's text and call setFormat() as often as necessary to apply any font and color changes that you require. Your function must return a value which indicates the paragraph's end state: see below.

Some syntaxes can have constructs that span paragraphs. For example, a C++ syntax highlighter should be able to cope with {/}{*...*}{/} comments that span paragraphs. To deal with these cases it is necessary to know the end state of the previous paragraph (e.g. "in comment").

If your syntax does not have paragraph spanning constructs, simply ignore the endStateOfLastPara parameter and always return 0.

Whenever highlightParagraph() is called it is passed a value for endStateOfLastPara. For the very first paragraph this value is always -2. For any other paragraph the value is the value returned by the most recent highlightParagraph() call that applied to the preceding paragraph.

The value you return is up to you. We recommend only returning 0 (to signify that this paragraph's syntax highlighting does not affect the following paragraph), or a positive integer (to signify that this paragraph has ended in the middle of a paragraph spanning construct).

To find out which paragraph is highlighted, call currentParagraph().

For example, if you're writing a simple C++ syntax highlighter, you might designate 1 to signify "in comment". For a paragraph that ended in the middle of a comment you'd return 1, and for other paragraphs you'd return 0. In your parsing code if endStateOfLastPara was 1, you would highlight the text as a C++ comment until you reached the closing {*}{/}.

void QSyntaxHighlighter::rehighlight ( )
void QSyntaxHighlighter::rehighlight ( )

Redoes the highlighting of the whole document.

void QSyntaxHighlighter::setFormat ( int  start,
int  count,
const QFont font,
const QColor color 
)
void QSyntaxHighlighter::setFormat ( int  start,
int  count,
const QFont font 
)

Esta es una función miembro sobrecargada que se suministra por conveniencia. Difiere de la anterior función solamente en los argumentos que acepta.

void QSyntaxHighlighter::setFormat ( int  start,
int  count,
const QColor color 
)

Esta es una función miembro sobrecargada que se suministra por conveniencia. Difiere de la anterior función solamente en los argumentos que acepta.

void QSyntaxHighlighter::setFormat ( int  start,
int  count,
const QFont font,
const QColor color 
)

This function is applied to the syntax highlighter's current paragraph (the text of which is passed to the highlightParagraph() function).

The specified font and color are applied to the text from position start for count characters. (If count is 0, nothing is done.)

void QSyntaxHighlighter::setFormat ( int  start,
int  count,
const QColor color 
)
void QSyntaxHighlighter::setFormat ( int  start,
int  count,
const QFont font 
)
QTextEdit * QSyntaxHighlighter::textEdit ( ) const [inline]

Returns the QTextEdit on which this syntax highlighter is installed

QTextEdit* QSyntaxHighlighter::textEdit ( ) const [inline]

Documentación de las funciones relacionadas y clases amigas


La documentación para esta clase fue generada a partir de los siguientes ficheros:
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'