Qt 4.8
Public Functions | Protected Functions | Private Types | Private Functions | Properties | List of all members
QScriptSyntaxHighlighter Class Reference

#include <qscriptsyntaxhighlighter_p.h>

Inheritance diagram for QScriptSyntaxHighlighter:
QSyntaxHighlighter QObject

Public Functions

 QScriptSyntaxHighlighter (QTextDocument *document=0)
 
 ~QScriptSyntaxHighlighter ()
 
- Public Functions inherited from QSyntaxHighlighter
QTextDocumentdocument () const
 Returns the QTextDocument on which this syntax highlighter is installed. More...
 
 QSyntaxHighlighter (QObject *parent)
 Constructs a QSyntaxHighlighter with the given parent. More...
 
 QSyntaxHighlighter (QTextDocument *parent)
 Constructs a QSyntaxHighlighter and installs it on parent. More...
 
 QSyntaxHighlighter (QTextEdit *parent)
 Constructs a QSyntaxHighlighter and installs it on parent 's QTextDocument. More...
 
void setDocument (QTextDocument *doc)
 Installs the syntax highlighter on the given QTextDocument doc. More...
 
virtual ~QSyntaxHighlighter ()
 Destructor. More...
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool event (QEvent *)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Protected Functions

void highlightBlock (const QString &text)
 Highlights the given text block. More...
 
- Protected Functions inherited from QSyntaxHighlighter
QTextBlock currentBlock () const
 Returns the current text block. More...
 
int currentBlockState () const
 Returns the state of the current text block. More...
 
QTextBlockUserDatacurrentBlockUserData () const
 Returns the QTextBlockUserData object previously attached to the current text block. More...
 
QTextCharFormat format (int pos) const
 Returns the format at position inside the syntax highlighter's current text block. More...
 
int previousBlockState () const
 Returns the end state of the text block previous to the syntax highlighter's current block. More...
 
void setCurrentBlockState (int newState)
 Sets the state of the current text block to newState. More...
 
void setCurrentBlockUserData (QTextBlockUserData *data)
 Attaches the given data to the current text block. More...
 
void setFormat (int start, int count, const QTextCharFormat &format)
 This function is applied to the syntax highlighter's current text block (i.e. More...
 
void setFormat (int start, int count, const QColor &color)
 The specified color is applied to the current text block from the start position for a length of count characters. More...
 
void setFormat (int start, int count, const QFont &font)
 The specified font is applied to the current text block from the start position for a length of count characters. More...
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 

Private Types

enum  ScriptFormats {
  ScriptTextFormat, ScriptNumberFormat, ScriptStringFormat, ScriptTypeFormat,
  ScriptKeywordFormat, ScriptPreprocessorFormat, ScriptLabelFormat, ScriptCommentFormat,
  NumScriptFormats
}
 

Private Functions

void highlightWord (int currentPos, const QString &buffer)
 

Properties

QTextCharFormat m_formats [NumScriptFormats]
 

Additional Inherited Members

- Public Slots inherited from QSyntaxHighlighter
void rehighlight ()
 Reapplies the highlighting to the whole document. More...
 
void rehighlightBlock (const QTextBlock &block)
 Reapplies the highlighting to the given QTextBlock block. More...
 
- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 
- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

Definition at line 66 of file qscriptsyntaxhighlighter_p.h.

Enumerations

◆ ScriptFormats

Constructors and Destructors

◆ QScriptSyntaxHighlighter()

QScriptSyntaxHighlighter::QScriptSyntaxHighlighter ( QTextDocument document = 0)

Definition at line 151 of file qscriptsyntaxhighlighter.cpp.

152  : QSyntaxHighlighter(document)
153 {
154 
163 }
void setFontItalic(bool italic)
If italic is true, sets the text format&#39;s font to be italic; otherwise the font will be non-italic...
Definition: qtextformat.h:415
QSyntaxHighlighter(QObject *parent)
Constructs a QSyntaxHighlighter with the given parent.
void setForeground(const QBrush &brush)
Sets the foreground brush to the specified brush.
Definition: qtextformat.h:350
QTextCharFormat m_formats[NumScriptFormats]

◆ ~QScriptSyntaxHighlighter()

QScriptSyntaxHighlighter::~QScriptSyntaxHighlighter ( )

Definition at line 165 of file qscriptsyntaxhighlighter.cpp.

166 {
167 }

Functions

◆ highlightBlock()

void QScriptSyntaxHighlighter::highlightBlock ( const QString text)
protectedvirtual

Highlights the given text block.

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

To provide your own syntax highlighting, you must subclass QSyntaxHighlighter and reimplement highlightBlock(). In your reimplementation you should parse the block's text and call setFormat() as often as necessary to apply any font and color changes that you require. For example:

void MyHighlighter::highlightBlock(const QString &text)
{
QTextCharFormat myClassFormat;
myClassFormat.setFontWeight(QFont::Bold);
QString pattern = "\\bMy[A-Za-z]+\\b";
QRegExp expression(pattern);
int index = text.indexOf(expression);
while (index >= 0) {
int length = expression.matchedLength();
setFormat(index, length, myClassFormat);
index = text.indexOf(expression, index + length);
}
}

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

Inside your highlightBlock() implementation you can query the end state of the previous text block using the previousBlockState() function. After parsing the block you can save the last state using setCurrentBlockState().

The currentBlockState() and previousBlockState() functions return an int value. If no state is set, the returned value is -1. You can designate any other value to identify any given state using the setCurrentBlockState() function. Once the state is set the QTextBlock keeps that value until it is set set again or until the corresponding paragraph of text gets deleted.

For example, if you're writing a simple C++ syntax highlighter, you might designate 1 to signify "in comment". For a text block that ended in the middle of a comment you'd set 1 using setCurrentBlockState, and for other paragraphs you'd set 0. In your parsing code if the return value of previousBlockState() is 1, you would highlight the text as a C++ comment until you reached the closing */.

See also
previousBlockState(), setFormat(), setCurrentBlockState()

Implements QSyntaxHighlighter.

Definition at line 169 of file qscriptsyntaxhighlighter.cpp.

170 {
171 
172  // states
173  enum States { StateStandard, StateCommentStart1, StateCCommentStart2,
174  StateScriptCommentStart2, StateCComment, StateScriptComment, StateCCommentEnd1,
175  StateCCommentEnd2, StateStringStart, StateString, StateStringEnd,
176  StateString2Start, StateString2, StateString2End,
177  StateNumber, StatePreProcessor, NumStates };
178 
179  // tokens
180  enum Tokens { InputAlpha, InputNumber, InputAsterix, InputSlash, InputParen,
181  InputSpace, InputHash, InputQuotation, InputApostrophe, InputSep, NumTokens };
182 
183  static uchar table[NumStates][NumTokens] = {
184  { StateStandard, StateNumber, StateStandard, StateCommentStart1, StateStandard, StateStandard, StatePreProcessor, StateStringStart, StateString2Start, StateStandard }, // StateStandard
185  { StateStandard, StateNumber, StateCCommentStart2, StateScriptCommentStart2, StateStandard, StateStandard, StatePreProcessor, StateStringStart, StateString2Start, StateStandard }, // StateCommentStart1
186  { StateCComment, StateCComment, StateCCommentEnd1, StateCComment, StateCComment, StateCComment, StateCComment, StateCComment, StateCComment, StateCComment }, // StateCCommentStart2
187  { StateScriptComment, StateScriptComment, StateScriptComment, StateScriptComment, StateScriptComment, StateScriptComment, StateScriptComment, StateScriptComment, StateScriptComment, StateScriptComment }, // ScriptCommentStart2
188  { StateCComment, StateCComment, StateCCommentEnd1, StateCComment, StateCComment, StateCComment, StateCComment, StateCComment, StateCComment, StateCComment }, // StateCComment
189  { StateScriptComment, StateScriptComment, StateScriptComment, StateScriptComment, StateScriptComment, StateScriptComment, StateScriptComment, StateScriptComment, StateScriptComment, StateScriptComment }, // StateScriptComment
190  { StateCComment, StateCComment, StateCCommentEnd1, StateCCommentEnd2, StateCComment, StateCComment, StateCComment, StateCComment, StateCComment, StateCComment }, // StateCCommentEnd1
191  { StateStandard, StateNumber, StateStandard, StateCommentStart1, StateStandard, StateStandard, StatePreProcessor, StateStringStart, StateString2Start, StateStandard }, // StateCCommentEnd2
192  { StateString, StateString, StateString, StateString, StateString, StateString, StateString, StateStringEnd, StateString, StateString }, // StateStringStart
193  { StateString, StateString, StateString, StateString, StateString, StateString, StateString, StateStringEnd, StateString, StateString }, // StateString
194  { StateStandard, StateStandard, StateStandard, StateCommentStart1, StateStandard, StateStandard, StatePreProcessor, StateStringStart, StateString2Start, StateStandard }, // StateStringEnd
195  { StateString2, StateString2, StateString2, StateString2, StateString2, StateString2, StateString2, StateString2, StateString2End, StateString2 }, // StateString2Start
196  { StateString2, StateString2, StateString2, StateString2, StateString2, StateString2, StateString2, StateString2, StateString2End, StateString2 }, // StateString2
197  { StateStandard, StateStandard, StateStandard, StateCommentStart1, StateStandard, StateStandard, StatePreProcessor, StateStringStart, StateString2Start, StateStandard }, // StateString2End
198  { StateNumber, StateNumber, StateStandard, StateCommentStart1, StateStandard, StateStandard, StatePreProcessor, StateStringStart, StateString2Start, StateStandard }, // StateNumber
199  { StatePreProcessor, StateStandard, StateStandard, StateCommentStart1, StateStandard, StateStandard, StatePreProcessor, StateStringStart, StateString2Start, StateStandard } // StatePreProcessor
200  };
201 
202  QString buffer;
203  buffer.reserve(text.length());
204 
205  QTextCharFormat emptyFormat;
206 
207  int state = StateStandard;
208  int braceDepth = 0;
209  const int previousState = previousBlockState();
210  if (previousState != -1) {
211  state = previousState & 0xff;
212  braceDepth = previousState >> 8;
213  }
214 
215  if (text.isEmpty()) {
216  setCurrentBlockState(previousState);
217 #if 0
218  TextEditDocumentLayout::clearParentheses(currentBlock());
219 #endif
220  return;
221  }
222 #if 0
223  Parentheses parentheses;
224  parentheses.reserve(20); // assume wizard level ;-)
225 #endif
226  int input = -1;
227  int i = 0;
228  bool lastWasBackSlash = false;
229  bool makeLastStandard = false;
230 
231  static const QString alphabeth = QLatin1String("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
232  static const QString mathChars = QLatin1String("xXeE");
233  static const QString numbers = QLatin1String("0123456789");
234  bool questionMark = false;
235  QChar lastChar;
236 
237  int firstNonSpace = -1;
238 
239  for (;;) {
240  const QChar c = text.at(i);
241 
242  if (lastWasBackSlash) {
243  input = InputSep;
244  } else {
245  switch (c.toAscii()) {
246  case '*':
247  input = InputAsterix;
248  break;
249  case '/':
250  input = InputSlash;
251  break;
252  case '{':
253  braceDepth++;
254  // fall through
255  case '(': case '[':
256  input = InputParen;
257  switch (state) {
258  case StateStandard:
259  case StateNumber:
260  case StatePreProcessor:
261  case StateCCommentEnd2:
262  case StateCCommentEnd1:
263  case StateString2End:
264  case StateStringEnd:
265 // parentheses.push_back(Parenthesis(Parenthesis::Opened, c, i));
266  break;
267  default:
268  break;
269  }
270  break;
271  case '}':
272  if (--braceDepth < 0)
273  braceDepth = 0;
274  // fall through
275  case ')': case ']':
276  input = InputParen;
277  switch (state) {
278  case StateStandard:
279  case StateNumber:
280  case StatePreProcessor:
281  case StateCCommentEnd2:
282  case StateCCommentEnd1:
283  case StateString2End:
284  case StateStringEnd:
285 // parentheses.push_back(Parenthesis(Parenthesis::Closed, c, i));
286  break;
287  default:
288  break;
289  }
290  break;
291  case '#':
292  input = InputHash;
293  break;
294  case '"':
295  input = InputQuotation;
296  break;
297  case '\'':
298  input = InputApostrophe;
299  break;
300  case ' ':
301  input = InputSpace;
302  break;
303  case '1': case '2': case '3': case '4': case '5':
304  case '6': case '7': case '8': case '9': case '0':
305  if (alphabeth.contains(lastChar)
306  && (!mathChars.contains(lastChar) || !numbers.contains(text.at(i - 1)))
307  ) {
308  input = InputAlpha;
309  } else {
310  if (input == InputAlpha && numbers.contains(lastChar))
311  input = InputAlpha;
312  else
313  input = InputNumber;
314  }
315  break;
316  case ':': {
317  input = InputAlpha;
318  const QChar colon = QLatin1Char(':');
319  if (state == StateStandard && !questionMark && lastChar != colon) {
320  const QChar nextChar = i < text.length() - 1 ? text.at(i + 1) : QLatin1Char(' ');
321  if (nextChar != colon)
322  for (int j = 0; j < i; ++j) {
323  if (format(j) == emptyFormat )
325  }
326  }
327  } break;
328  default:
329  if (!questionMark && c == QLatin1Char('?'))
330  questionMark = true;
331  if (c.isLetter() || c == QLatin1Char('_'))
332  input = InputAlpha;
333  else
334  input = InputSep;
335  break;
336  }
337  }
338 
339  if (input != InputSpace && firstNonSpace < 0)
340  firstNonSpace = i;
341 
342  lastWasBackSlash = !lastWasBackSlash && c == QLatin1Char('\\');
343 
344  if (input == InputAlpha)
345  buffer += c;
346 
347  state = table[state][input];
348 
349  switch (state) {
350  case StateStandard: {
351  setFormat(i, 1, emptyFormat);
352  if (makeLastStandard)
353  setFormat(i - 1, 1, emptyFormat);
354  makeLastStandard = false;
355  if (input != InputAlpha) {
356  highlightWord(i, buffer);
357  buffer = QString::null;
358  }
359  } break;
360  case StateCommentStart1:
361  if (makeLastStandard)
362  setFormat(i - 1, 1, emptyFormat);
363  makeLastStandard = true;
364  buffer = QString::null;
365  break;
366  case StateCCommentStart2:
368  makeLastStandard = false;
369 // parentheses.push_back(Parenthesis(Parenthesis::Opened, QLatin1Char('/'), i-1));
370  buffer = QString::null;
371  break;
372  case StateScriptCommentStart2:
374  makeLastStandard = false;
375  buffer = QString::null;
376  break;
377  case StateCComment:
378  if (makeLastStandard)
379  setFormat(i - 1, 1, emptyFormat);
380  makeLastStandard = false;
382  buffer = QString::null;
383  break;
384  case StateScriptComment:
385  if (makeLastStandard)
386  setFormat(i - 1, 1, emptyFormat);
387  makeLastStandard = false;
389  buffer = QString::null;
390  break;
391  case StateCCommentEnd1:
392  if (makeLastStandard)
393  setFormat(i - 1, 1, emptyFormat);
394  makeLastStandard = false;
396  buffer = QString::null;
397  break;
398  case StateCCommentEnd2:
399  if (makeLastStandard)
400  setFormat(i - 1, 1, emptyFormat);
401  makeLastStandard = false;
403 // parentheses.push_back(Parenthesis(Parenthesis::Closed, QLatin1Char('/'), i));
404  buffer = QString::null;
405  break;
406  case StateStringStart:
407  if (makeLastStandard)
408  setFormat(i - 1, 1, emptyFormat);
409  makeLastStandard = false;
410  setFormat(i, 1, emptyFormat);
411  buffer = QString::null;
412  break;
413  case StateString:
414  if (makeLastStandard)
415  setFormat(i - 1, 1, emptyFormat);
416  makeLastStandard = false;
418  buffer = QString::null;
419  break;
420  case StateStringEnd:
421  if (makeLastStandard)
422  setFormat(i - 1, 1, emptyFormat);
423  makeLastStandard = false;
424  setFormat(i, 1, emptyFormat);
425  buffer = QString::null;
426  break;
427  case StateString2Start:
428  if (makeLastStandard)
429  setFormat(i - 1, 1, emptyFormat);
430  makeLastStandard = false;
431  setFormat(i, 1, emptyFormat);
432  buffer = QString::null;
433  break;
434  case StateString2:
435  if (makeLastStandard)
436  setFormat(i - 1, 1, emptyFormat);
437  makeLastStandard = false;
439  buffer = QString::null;
440  break;
441  case StateString2End:
442  if (makeLastStandard)
443  setFormat(i - 1, 1, emptyFormat);
444  makeLastStandard = false;
445  setFormat(i, 1, emptyFormat);
446  buffer = QString::null;
447  break;
448  case StateNumber:
449  if (makeLastStandard)
450  setFormat(i - 1, 1, emptyFormat);
451  makeLastStandard = false;
453  buffer = QString::null;
454  break;
455  case StatePreProcessor:
456  if (makeLastStandard)
457  setFormat(i - 1, 1, emptyFormat);
458  makeLastStandard = false;
460  buffer = QString::null;
461  break;
462  }
463 
464  lastChar = c;
465  i++;
466  if (i >= text.length()) {
467 #if 0
468  if (TextBlockUserData *userData = TextEditDocumentLayout::testUserData(currentBlock())) {
469  userData->setHasClosingCollapse(false);
470  userData->setCollapseMode(TextBlockUserData::NoCollapse);
471  }
472  int collapse = Parenthesis::collapseAtPos(parentheses);
473  if (collapse >= 0) {
474  if (collapse == firstNonSpace)
475  TextEditDocumentLayout::userData(currentBlock())->setCollapseMode(TextBlockUserData::CollapseThis);
476  else
477  TextEditDocumentLayout::userData(currentBlock())->setCollapseMode(TextBlockUserData::CollapseAfter);
478  }
479  if (Parenthesis::hasClosingCollapse(parentheses)) {
480  TextEditDocumentLayout::userData(currentBlock())->setHasClosingCollapse(true);
481  }
482 #endif
483 
484  break;
485  }
486  }
487 
488  highlightWord(text.length(), buffer);
489 
490  switch (state) {
491  case StateCComment:
492  case StateCCommentEnd1:
493  case StateCCommentStart2:
494  state = StateCComment;
495  break;
496  case StateString:
497  // quotes cannot span multiple lines, so if somebody starts
498  // typing a quoted string we don't need to look for the ending
499  // quote in another line (or highlight until the end of the
500  // document) and therefore slow down editing.
501  state = StateStandard;
502  break;
503  case StateString2:
504  state = StateStandard;
505  break;
506  default:
507  state = StateStandard;
508  break;
509  }
510 
511 #if 0
512  TextEditDocumentLayout::setParentheses(currentBlock(), parentheses);
513 #endif
514 
515  setCurrentBlockState((braceDepth << 8) | state);
516 }
QBool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.h:904
bool isLetter() const
Returns true if the character is a letter (Letter_* categories); otherwise returns false...
Definition: qchar.cpp:653
The QTextCharFormat class provides formatting information for characters in a QTextDocument.
Definition: qtextformat.h:372
unsigned char c[8]
Definition: qnumeric_p.h:62
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
QObjectUserData * userData(uint id) const
Definition: qobject.cpp:4016
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void setFormat(int start, int count, const QTextCharFormat &format)
This function is applied to the syntax highlighter&#39;s current text block (i.e.
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
int previousBlockState() const
Returns the end state of the text block previous to the syntax highlighter&#39;s current block...
void reserve(int size)
Attempts to allocate memory for at least size characters.
Definition: qstring.h:881
unsigned char uchar
Definition: qglobal.h:994
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QTextBlock currentBlock() const
Returns the current text block.
void highlightWord(int currentPos, const QString &buffer)
char toAscii() const
Returns the character value of the QChar obtained using the current codec used to read C strings...
Definition: qchar.cpp:1490
void setCurrentBlockState(int newState)
Sets the state of the current text block to newState.
QTextCharFormat m_formats[NumScriptFormats]
QTextCharFormat format(int pos) const
Returns the format at position inside the syntax highlighter&#39;s current text block.
static const Null null
Definition: qstring.h:502
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ highlightWord()

void QScriptSyntaxHighlighter::highlightWord ( int  currentPos,
const QString buffer 
)
private

Definition at line 518 of file qscriptsyntaxhighlighter.cpp.

Referenced by highlightBlock().

519 {
520  if (buffer.isEmpty())
521  return;
522 
523  // try to highlight Qt 'identifiers' like QObject and buffer.length() >; == QLatin1Char('Q')
524  && (buffer.at(1).isUpper()
525  || buffer.at(1) == QLatin1Char('_')
526  || buffer.at(1) == QLatin1Char('t'))) {
527  setFormat(currentPos - buffer.length(), buffer.length(), m_formats[ScriptTypeFormat]);
528  } else {
529  if (isKeyword(buffer))
530  setFormat(currentPos - buffer.length(), buffer.length(), m_formats[ScriptKeywordFormat]);
531  }
532 }
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
void setFormat(int start, int count, const QTextCharFormat &format)
This function is applied to the syntax highlighter&#39;s current text block (i.e.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
static bool isKeyword(const QString &word)
bool isUpper() const
Returns true if the character is an uppercase letter, i.
Definition: qchar.h:273
QTextCharFormat m_formats[NumScriptFormats]
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

Properties

◆ m_formats

QTextCharFormat QScriptSyntaxHighlighter::m_formats[NumScriptFormats]
private

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