Qt 4.8
Public Functions | Public Variables | List of all members
QSyntaxHighlighterPrivate Class Reference
Inheritance diagram for QSyntaxHighlighterPrivate:
QObjectPrivate QObjectData

Public Functions

void _q_delayedRehighlight ()
 
void _q_reformatBlocks (int from, int charsRemoved, int charsAdded)
 
void applyFormatChanges ()
 
 QSyntaxHighlighterPrivate ()
 
void reformatBlock (const QTextBlock &block)
 
void reformatBlocks (int from, int charsRemoved, int charsAdded)
 
void rehighlight (QTextCursor &cursor, QTextCursor::MoveOperation operation)
 
- Public Functions inherited from QObjectPrivate
void _q_reregisterTimers (void *pointer)
 
void addConnection (int signal, Connection *c)
 
void cleanConnectionLists ()
 
void connectNotify (const char *signal)
 
void deleteChildren ()
 
void disconnectNotify (const char *signal)
 
bool isSender (const QObject *receiver, const char *signal) const
 
bool isSignalConnected (uint signalIdx) const
 Returns true if the signal with index signal_index from object sender is connected. More...
 
void moveToThread_helper ()
 
 QObjectPrivate (int version=QObjectPrivateVersion)
 
QObjectList receiverList (const char *signal) const
 
QObjectList senderList () const
 
void setParent_helper (QObject *)
 
void setThreadData_helper (QThreadData *currentData, QThreadData *targetData)
 
int signalIndex (const char *signalName) const
 Returns the signal index used in the internal connectionLists vector. More...
 
virtual ~QObjectPrivate ()
 
- Public Functions inherited from QObjectData
virtual ~QObjectData ()=0
 

Public Variables

QTextBlock currentBlock
 
QPointer< QTextDocumentdoc
 
QVector< QTextCharFormatformatChanges
 
bool inReformatBlocks
 
bool rehighlightPending
 
- Public Variables inherited from QObjectPrivate
union {
   QObject *   currentChildBeingDeleted
 
   QAbstractDeclarativeData *   declarativeData
 
}; 
 
quint32 connectedSignals [2]
 
QObjectConnectionListVectorconnectionLists
 
SendercurrentSender
 
QList< QPointer< QObject > > eventFilters
 
ExtraDataextraData
 
QString objectName
 
Connectionsenders
 
QAtomicPointer< QtSharedPointer::ExternalRefCountData > sharedRefcount
 
QThreadDatathreadData
 
void * unused
 
- Public Variables inherited from QObjectData
uint blockSig: 1
 
QObjectList children
 
uint hasGuards: 1
 
uint inEventHandler: 1
 
uint inThreadChangeEvent: 1
 
uint isWidget: 1
 
QMetaObjectmetaObject
 
uint ownObjectName: 1
 
QObjectparent
 
uint pendTimer: 1
 
int postedEvents
 
QObjectq_ptr
 
uint receiveChildEvents: 1
 
uint sendChildEvents: 1
 
uint unused: 22
 
uint wasDeleted: 1
 

Additional Inherited Members

- Public Types inherited from QObjectPrivate
typedef void(* StaticMetaCallFunction) (QObject *, QMetaObject::Call, int, void **)
 
- Static Public Functions inherited from QObjectPrivate
static void clearGuards (QObject *)
 
static QObjectPrivateget (QObject *o)
 
static void resetCurrentSender (QObject *receiver, Sender *currentSender, Sender *previousSender)
 
static SendersetCurrentSender (QObject *receiver, Sender *sender)
 
static void signalSignature (const QMetaMethod &signal, QVarLengthArray< char > *result)
 

Detailed Description

Definition at line 58 of file qsyntaxhighlighter.cpp.

Constructors and Destructors

◆ QSyntaxHighlighterPrivate()

QSyntaxHighlighterPrivate::QSyntaxHighlighterPrivate ( )
inline

Definition at line 62 of file qsyntaxhighlighter.cpp.

Functions

◆ _q_delayedRehighlight()

void QSyntaxHighlighterPrivate::_q_delayedRehighlight ( )
inline

Definition at line 82 of file qsyntaxhighlighter.cpp.

82  {
83  if (!rehighlightPending)
84  return;
85  rehighlightPending = false;
86  q_func()->rehighlight();
87  }

◆ _q_reformatBlocks()

void QSyntaxHighlighterPrivate::_q_reformatBlocks ( int  from,
int  charsRemoved,
int  charsAdded 
)

Definition at line 180 of file qsyntaxhighlighter.cpp.

181 {
182  if (!inReformatBlocks)
183  reformatBlocks(from, charsRemoved, charsAdded);
184 }
void reformatBlocks(int from, int charsRemoved, int charsAdded)

◆ applyFormatChanges()

void QSyntaxHighlighterPrivate::applyFormatChanges ( )

Definition at line 96 of file qsyntaxhighlighter.cpp.

Referenced by _q_delayedRehighlight(), and reformatBlock().

97 {
98  bool formatsChanged = false;
99 
101 
103 
104  const int preeditAreaStart = layout->preeditAreaPosition();
105  const int preeditAreaLength = layout->preeditAreaText().length();
106 
107  if (preeditAreaLength != 0) {
109  while (it != ranges.end()) {
110  if (it->start >= preeditAreaStart
111  && it->start + it->length <= preeditAreaStart + preeditAreaLength) {
112  ++it;
113  } else {
114  it = ranges.erase(it);
115  formatsChanged = true;
116  }
117  }
118  } else if (!ranges.isEmpty()) {
119  ranges.clear();
120  formatsChanged = true;
121  }
122 
123  QTextCharFormat emptyFormat;
124 
126  r.start = -1;
127 
128  int i = 0;
129  while (i < formatChanges.count()) {
130 
131  while (i < formatChanges.count() && formatChanges.at(i) == emptyFormat)
132  ++i;
133 
134  if (i >= formatChanges.count())
135  break;
136 
137  r.start = i;
138  r.format = formatChanges.at(i);
139 
140  while (i < formatChanges.count() && formatChanges.at(i) == r.format)
141  ++i;
142 
143  if (i >= formatChanges.count())
144  break;
145 
146  r.length = i - r.start;
147 
148  if (preeditAreaLength != 0) {
149  if (r.start >= preeditAreaStart)
150  r.start += preeditAreaLength;
151  else if (r.start + r.length >= preeditAreaStart)
152  r.length += preeditAreaLength;
153  }
154 
155  ranges << r;
156  formatsChanged = true;
157  r.start = -1;
158  }
159 
160  if (r.start != -1) {
161  r.length = formatChanges.count() - r.start;
162 
163  if (preeditAreaLength != 0) {
164  if (r.start >= preeditAreaStart)
165  r.start += preeditAreaLength;
166  else if (r.start + r.length >= preeditAreaStart)
167  r.length += preeditAreaLength;
168  }
169 
170  ranges << r;
171  formatsChanged = true;
172  }
173 
174  if (formatsChanged) {
175  layout->setAdditionalFormats(ranges);
177  }
178 }
void setAdditionalFormats(const QList< FormatRange > &overrides)
Sets the additional formats supported by the text layout to formatList.
The QTextLayout::FormatRange structure is used to apply extra formatting information for a specified ...
Definition: qtextlayout.h:128
The QTextCharFormat class provides formatting information for characters in a QTextDocument.
Definition: qtextformat.h:372
#define it(className, varName)
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
Definition: qlist.h:267
int start
Specifies the beginning of the format range within the text layout&#39;s text.
Definition: qtextlayout.h:129
void markContentsDirty(int from, int length)
Marks the contents specified by the given position and length as "dirty", informing the document that...
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
int position() const
Returns the index of the block&#39;s first character within the document.
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:270
const char * layout
void clear()
Removes all items from the list.
Definition: qlist.h:764
int length() const
Returns the length of the block in characters.
QPointer< QTextDocument > doc
int preeditAreaPosition() const
Returns the position of the area in the text layout that will be processed before editing occurs...
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
QString preeditAreaText() const
Returns the text that is inserted in the layout before editing occurs.
iterator erase(iterator pos)
Removes the item associated with the iterator pos from the list, and returns an iterator to the next ...
Definition: qlist.h:464
The QTextLayout class is used to lay out and render text.
Definition: qtextlayout.h:105
QList< FormatRange > additionalFormats() const
Returns the list of additional formats supported by the text layout.
int length() const
This function is identical to count().
Definition: qlist.h:281
int length
Specifies the numer of characters the format range spans.
Definition: qtextlayout.h:130
QTextCharFormat format
Specifies the format to apply.
Definition: qtextlayout.h:131
QVector< QTextCharFormat > formatChanges
QTextLayout * layout() const
Returns the QTextLayout that is used to lay out and display the block&#39;s contents. ...

◆ reformatBlock()

void QSyntaxHighlighterPrivate::reformatBlock ( const QTextBlock block)

Definition at line 216 of file qsyntaxhighlighter.cpp.

Referenced by reformatBlocks().

217 {
219 
220  Q_ASSERT_X(!currentBlock.isValid(), "QSyntaxHighlighter::reformatBlock()", "reFormatBlock() called recursively");
221 
222  currentBlock = block;
223 
224  formatChanges.fill(QTextCharFormat(), block.length() - 1);
225  q->highlightBlock(block.text());
227 
228  currentBlock = QTextBlock();
229 }
QString text() const
Returns the block&#39;s contents as plain text.
The QTextCharFormat class provides formatting information for characters in a QTextDocument.
Definition: qtextformat.h:372
QVector< T > & fill(const T &t, int size=-1)
Assigns value to all items in the vector.
Definition: qvector.h:665
#define Q_Q(Class)
Definition: qglobal.h:2483
The QTextBlock class provides a container for text fragments in a QTextDocument.
Definition: qtextobject.h:199
int length() const
Returns the length of the block in characters.
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
The QSyntaxHighlighter class allows you to define syntax highlighting rules, and in addition you can ...
bool isValid() const
Returns true if this text block is valid; otherwise returns false.
Definition: qtextobject.h:208
QVector< QTextCharFormat > formatChanges

◆ reformatBlocks()

void QSyntaxHighlighterPrivate::reformatBlocks ( int  from,
int  charsRemoved,
int  charsAdded 
)

Definition at line 186 of file qsyntaxhighlighter.cpp.

Referenced by _q_reformatBlocks(), and rehighlight().

187 {
188  rehighlightPending = false;
189 
190  QTextBlock block = doc->findBlock(from);
191  if (!block.isValid())
192  return;
193 
194  int endPosition;
195  QTextBlock lastBlock = doc->findBlock(from + charsAdded + (charsRemoved > 0 ? 1 : 0));
196  if (lastBlock.isValid())
197  endPosition = lastBlock.position() + lastBlock.length();
198  else
199  endPosition = doc->docHandle()->length();
200 
201  bool forceHighlightOfNextBlock = false;
202 
203  while (block.isValid() && (block.position() < endPosition || forceHighlightOfNextBlock)) {
204  const int stateBeforeHighlight = block.userState();
205 
206  reformatBlock(block);
207 
208  forceHighlightOfNextBlock = (block.userState() != stateBeforeHighlight);
209 
210  block = block.next();
211  }
212 
214 }
QTextBlock next() const
Returns the text block in the document after this block, or an empty text block if this is the last o...
int position() const
Returns the index of the block&#39;s first character within the document.
void clear()
Removes all the elements from the vector and releases the memory used by the vector.
Definition: qvector.h:347
QTextDocumentPrivate * docHandle() const
So that not all classes have to be friends of each other.
The QTextBlock class provides a container for text fragments in a QTextDocument.
Definition: qtextobject.h:199
int length() const
Returns the length of the block in characters.
QPointer< QTextDocument > doc
int userState() const
Returns the integer value previously set with setUserState() or -1.
void reformatBlock(const QTextBlock &block)
QTextBlock findBlock(int pos) const
Returns the text block that contains the {pos}-th character.
bool isValid() const
Returns true if this text block is valid; otherwise returns false.
Definition: qtextobject.h:208
QVector< QTextCharFormat > formatChanges

◆ rehighlight()

void QSyntaxHighlighterPrivate::rehighlight ( QTextCursor cursor,
QTextCursor::MoveOperation  operation 
)
inline

Definition at line 72 of file qsyntaxhighlighter.cpp.

72  {
73  inReformatBlocks = true;
74  cursor.beginEditBlock();
75  int from = cursor.position();
76  cursor.movePosition(operation);
77  reformatBlocks(from, 0, cursor.position() - from);
78  cursor.endEditBlock();
79  inReformatBlocks = false;
80  }
void endEditBlock()
Indicates the end of a block of editing operations on the document that should appear as a single ope...
int position() const
Returns the absolute position of the cursor within the document.
void beginEditBlock()
Indicates the start of a block of editing operations on the document that should appear as a single o...
void reformatBlocks(int from, int charsRemoved, int charsAdded)
bool movePosition(MoveOperation op, MoveMode=MoveAnchor, int n=1)
Moves the cursor by performing the given operation n times, using the specified mode, and returns true if all operations were completed successfully; otherwise returns false.

Properties

◆ currentBlock

QTextBlock QSyntaxHighlighterPrivate::currentBlock

Definition at line 91 of file qsyntaxhighlighter.cpp.

Referenced by applyFormatChanges(), and reformatBlock().

◆ doc

QPointer<QTextDocument> QSyntaxHighlighterPrivate::doc

Definition at line 66 of file qsyntaxhighlighter.cpp.

Referenced by applyFormatChanges(), and reformatBlocks().

◆ formatChanges

QVector<QTextCharFormat> QSyntaxHighlighterPrivate::formatChanges

Definition at line 90 of file qsyntaxhighlighter.cpp.

Referenced by applyFormatChanges(), reformatBlock(), and reformatBlocks().

◆ inReformatBlocks

bool QSyntaxHighlighterPrivate::inReformatBlocks

Definition at line 93 of file qsyntaxhighlighter.cpp.

Referenced by _q_reformatBlocks(), and rehighlight().

◆ rehighlightPending

bool QSyntaxHighlighterPrivate::rehighlightPending

Definition at line 92 of file qsyntaxhighlighter.cpp.

Referenced by _q_delayedRehighlight(), and reformatBlocks().


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