Qt 4.8
Public Functions | Private Functions | Properties | Friends | List of all members
QTextBlock::iterator Class Reference

The QTextBlock::iterator class provides an iterator for reading the contents of a QTextBlock. More...

#include <qtextobject.h>

Public Functions

bool atEnd () const
 Returns true if the current item is the last item in the text block. More...
 
QTextFragment fragment () const
 Returns the text fragment the iterator currently points to. More...
 
 iterator ()
 Constructs an iterator for this text block. More...
 
 iterator (const iterator &o)
 Copy constructor. More...
 
bool operator!= (const iterator &o) const
 Retuns true if this iterator is different from the other iterator; otherwise returns false. More...
 
iteratoroperator++ ()
 The prefix ++ operator (++i) advances the iterator to the next item in the hash and returns an iterator to the new current item. More...
 
iterator operator++ (int)
 The postfix ++ operator (i++) advances the iterator to the next item in the text block and returns an iterator to the old current item. More...
 
iteratoroperator-- ()
 The prefix – operator (–i) makes the preceding item current and returns an iterator pointing to the new current item. More...
 
iterator operator-- (int)
 The postfix – operator (i–) makes the preceding item current and returns an iterator to the old current item. More...
 
bool operator== (const iterator &o) const
 Retuns true if this iterator is the same as the other iterator; otherwise returns false. More...
 

Private Functions

 iterator (const QTextDocumentPrivate *priv, int begin, int end, int f)
 

Properties

int b
 
int e
 
int n
 
const QTextDocumentPrivatep
 

Friends

class QTextBlock
 

Detailed Description

The QTextBlock::iterator class provides an iterator for reading the contents of a QTextBlock.

Note
This class or function is reentrant.

A block consists of a sequence of text fragments. This class provides a way to iterate over these, and read their contents. It does not provide a way to modify the internal structure or contents of the block.

An iterator can be constructed and used to access the fragments within a text block in the following way:

for (it = currentBlock.begin(); !(it.atEnd()); ++it) {
QTextFragment currentFragment = it.fragment();
if (currentFragment.isValid())
processFragment(currentFragment);
}
See also
QTextFragment

Definition at line 251 of file qtextobject.h.

Constructors and Destructors

◆ iterator() [1/3]

QTextBlock::iterator::iterator ( const QTextDocumentPrivate priv,
int  begin,
int  end,
int  f 
)
inlineprivate

Definition at line 257 of file qtextobject.h.

257 : p(priv), b(begin), e(end), n(f) {}
iterator end() const
Returns a text block iterator pointing to the end of the text block.
iterator begin() const
Returns a text block iterator pointing to the beginning of the text block.
const QTextDocumentPrivate * p
Definition: qtextobject.h:252

◆ iterator() [2/3]

QTextBlock::iterator::iterator ( )
inline

Constructs an iterator for this text block.

Definition at line 259 of file qtextobject.h.

259 : p(0), b(0), e(0), n(0) {}
const QTextDocumentPrivate * p
Definition: qtextobject.h:252

◆ iterator() [3/3]

QTextBlock::iterator::iterator ( const iterator other)
inline

Copy constructor.

Constructs a copy of the other iterator.

Definition at line 260 of file qtextobject.h.

260 : p(o.p), b(o.b), e(o.e), n(o.n) {}
const QTextDocumentPrivate * p
Definition: qtextobject.h:252

Functions

◆ atEnd()

bool QTextBlock::iterator::atEnd ( ) const
inline

◆ fragment()

QTextFragment QTextBlock::iterator::fragment ( ) const

Returns the text fragment the iterator currently points to.

Definition at line 1640 of file qtextobject.cpp.

Referenced by QTextControlPrivate::activateLinkUnderCursor(), QTextHtmlExporter::emitBlock(), and QTextControl::findNextPrevAnchor().

1641 {
1642  int ne = n;
1643  int formatIndex = p->fragmentMap().fragment(n)->format;
1644  do {
1645  ne = p->fragmentMap().next(ne);
1646  } while (ne != e && p->fragmentMap().fragment(ne)->format == formatIndex);
1647  return QTextFragment(p, n, ne);
1648 }
const QTextDocumentPrivate * p
Definition: qtextobject.h:252
The QTextFragment class holds a piece of text in a QTextDocument with a single QTextCharFormat.
Definition: qtextobject.h:297
uint next(uint n) const
Fragment * fragment(uint index)
const FragmentMap & fragmentMap() const

◆ operator!=()

bool QTextBlock::iterator::operator!= ( const iterator o) const
inline

Retuns true if this iterator is different from the other iterator; otherwise returns false.

Definition at line 267 of file qtextobject.h.

267 { return p != o.p || n != o.n; }
const QTextDocumentPrivate * p
Definition: qtextobject.h:252

◆ operator++() [1/2]

QTextBlock::iterator & QTextBlock::iterator::operator++ ( )

The prefix ++ operator (++i) advances the iterator to the next item in the hash and returns an iterator to the new current item.

Definition at line 1656 of file qtextobject.cpp.

1657 {
1658  int ne = n;
1659  int formatIndex = p->fragmentMap().fragment(n)->format;
1660  do {
1661  ne = p->fragmentMap().next(ne);
1662  } while (ne != e && p->fragmentMap().fragment(ne)->format == formatIndex);
1663  n = ne;
1664  return *this;
1665 }
const QTextDocumentPrivate * p
Definition: qtextobject.h:252
uint next(uint n) const
Fragment * fragment(uint index)
const FragmentMap & fragmentMap() const

◆ operator++() [2/2]

QTextBlock::iterator QTextBlock::iterator::operator++ ( int  )
inline

The postfix ++ operator (i++) advances the iterator to the next item in the text block and returns an iterator to the old current item.

Definition at line 269 of file qtextobject.h.

Referenced by operator++().

269 { iterator tmp = *this; operator++(); return tmp; }
iterator & operator++()
The prefix ++ operator (++i) advances the iterator to the next item in the hash and returns an iterat...
iterator()
Constructs an iterator for this text block.
Definition: qtextobject.h:259

◆ operator--() [1/2]

QTextBlock::iterator & QTextBlock::iterator::operator-- ( )

The prefix – operator (–i) makes the preceding item current and returns an iterator pointing to the new current item.

Definition at line 1672 of file qtextobject.cpp.

1673 {
1674  n = p->fragmentMap().previous(n);
1675 
1676  if (n == b)
1677  return *this;
1678 
1679  int formatIndex = p->fragmentMap().fragment(n)->format;
1680  int last = n;
1681 
1682  while (n != b && p->fragmentMap().fragment(n)->format != formatIndex) {
1683  last = n;
1684  n = p->fragmentMap().previous(n);
1685  }
1686 
1687  n = last;
1688  return *this;
1689 }
const QTextDocumentPrivate * p
Definition: qtextobject.h:252
Fragment * fragment(uint index)
uint previous(uint n) const
const FragmentMap & fragmentMap() const

◆ operator--() [2/2]

QTextBlock::iterator QTextBlock::iterator::operator-- ( int  )
inline

The postfix – operator (i–) makes the preceding item current and returns an iterator to the old current item.

Definition at line 271 of file qtextobject.h.

Referenced by operator--().

271 { iterator tmp = *this; operator--(); return tmp; }
iterator & operator--()
The prefix – operator (–i) makes the preceding item current and returns an iterator pointing to the...
iterator()
Constructs an iterator for this text block.
Definition: qtextobject.h:259

◆ operator==()

bool QTextBlock::iterator::operator== ( const iterator o) const
inline

Retuns true if this iterator is the same as the other iterator; otherwise returns false.

Definition at line 266 of file qtextobject.h.

266 { return p == o.p && n == o.n; }
const QTextDocumentPrivate * p
Definition: qtextobject.h:252

Friends and Related Functions

◆ QTextBlock

friend class QTextBlock
friend

Definition at line 256 of file qtextobject.h.

Properties

◆ b

int QTextBlock::iterator::b
private

Definition at line 253 of file qtextobject.h.

◆ e

int QTextBlock::iterator::e
private

Definition at line 254 of file qtextobject.h.

◆ n

int QTextBlock::iterator::n
private

Definition at line 255 of file qtextobject.h.

Referenced by operator!=(), and operator==().

◆ p

const QTextDocumentPrivate* QTextBlock::iterator::p
private

Definition at line 252 of file qtextobject.h.

Referenced by operator!=(), and operator==().


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