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

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

#include <qtextobject.h>

Public Functions

bool atEnd () const
 Returns true if the current item is the last item in the text frame. More...
 
QTextBlock currentBlock () const
 Returns the current block the iterator points to. More...
 
QTextFramecurrentFrame () const
 Returns the current frame pointed to by the iterator, or 0 if the iterator currently points to a block. More...
 
 iterator ()
 Constructs an invalid iterator. More...
 
 iterator (const iterator &o)
 Copy constructor. More...
 
bool operator!= (const iterator &o) const
 Retuns true if the iterator is different from the other iterator; otherwise returns false. More...
 
iteratoroperator++ ()
 Moves the iterator to the next frame or block. More...
 
iterator operator++ (int)
 The postfix ++ operator (i++) advances the iterator to the next item in the text frame, and returns an iterator to the old item. More...
 
iteratoroperator-- ()
 Moves the iterator to the previous frame or block. More...
 
iterator operator-- (int)
 The postfix – operator (i–) makes the preceding item in the current frame, and returns an iterator to the old item. More...
 
iteratoroperator= (const iterator &o)
 Assigns other to this iterator and returns a reference to this iterator. More...
 
bool operator== (const iterator &o) const
 Retuns true if the iterator is the same as the other iterator; otherwise returns false. More...
 
QTextFrameparentFrame () const
 Returns the parent frame of the current frame. More...
 

Private Functions

 iterator (QTextFrame *frame, int block, int begin, int end)
 

Properties

int b
 
int cb
 
QTextFramecf
 
int e
 
QTextFramef
 

Friends

class QTextDocumentLayoutPrivate
 
class QTextFrame
 
class QTextTableCell
 

Detailed Description

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

Note
This class or function is reentrant.

A frame consists of an arbitrary sequence of QTextBlock and child QTextFrame. This class provides a way to iterate over the child objects of a frame, and read their contents. It does not provide a way to modify the contents of the frame.

Definition at line 144 of file qtextobject.h.

Constructors and Destructors

◆ iterator() [1/3]

QTextFrame::iterator::iterator ( QTextFrame frame,
int  block,
int  begin,
int  end 
)
private
Warning
This function is not part of the public interface.

Definition at line 695 of file qtextobject.cpp.

696 {
697  f = frame;
698  b = begin;
699  e = end;
700  cf = 0;
701  cb = block;
702 }
iterator end() const
Returns an iterator pointing to the position past the last document element inside the frame...
iterator begin() const
Returns an iterator pointing to the first document element inside the frame.

◆ iterator() [2/3]

QTextFrame::iterator::iterator ( )

Constructs an invalid iterator.

Definition at line 683 of file qtextobject.cpp.

684 {
685  f = 0;
686  b = 0;
687  e = 0;
688  cf = 0;
689  cb = 0;
690 }

◆ iterator() [3/3]

QTextFrame::iterator::iterator ( const iterator other)

Copy constructor.

Constructs a copy of the other iterator.

Definition at line 707 of file qtextobject.cpp.

708 {
709  f = other.f;
710  b = other.b;
711  e = other.e;
712  cf = other.cf;
713  cb = other.cb;
714 }

Functions

◆ atEnd()

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

◆ currentBlock()

QTextBlock QTextFrame::iterator::currentBlock ( ) const

Returns the current block the iterator points to.

If the iterator points to a child frame, the returned block is invalid.

See also
currentFrame()

Definition at line 747 of file qtextobject.cpp.

Referenced by QTextDocumentLayoutPrivate::drawFlow(), QTextHtmlExporter::emitFrame(), flowPosition(), QTextDocumentLayoutPrivate::hitTest(), isEmptyBlockBeforeTable(), QTextDocumentLayoutPrivate::layoutFlow(), and QTextOdfWriter::writeFrame().

748 {
749  if (!f)
750  return QTextBlock();
751  return QTextBlock(f->docHandle(), cb);
752 }
QTextDocumentPrivate * docHandle() const
The QTextBlock class provides a container for text fragments in a QTextDocument.
Definition: qtextobject.h:199

◆ currentFrame()

QTextFrame * QTextFrame::iterator::currentFrame ( ) const

Returns the current frame pointed to by the iterator, or 0 if the iterator currently points to a block.

See also
currentBlock()

Definition at line 736 of file qtextobject.cpp.

Referenced by QTextDocumentLayoutPrivate::drawFlow(), QTextHtmlExporter::emitFrame(), flowPosition(), QTextDocumentLayoutPrivate::hitTest(), isEmptyBlockBeforeTable(), QTextDocumentLayoutPrivate::layoutFlow(), and QTextOdfWriter::writeFrame().

737 {
738  return cf;
739 }

◆ operator!=()

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

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

Definition at line 168 of file qtextobject.h.

168 { return f != o.f || cf != o.cf || cb != o.cb; }

◆ operator++() [1/2]

QTextFrame::iterator & QTextFrame::iterator::operator++ ( )

Moves the iterator to the next frame or block.

See also
currentBlock() currentFrame()

Definition at line 759 of file qtextobject.cpp.

760 {
761  const QTextDocumentPrivate *priv = f->docHandle();
763  if (cf) {
764  int end = cf->lastPosition() + 1;
765  cb = map.findNode(end);
766  cf = 0;
767  } else if (cb) {
768  cb = map.next(cb);
769  if (cb == e)
770  return *this;
771 
772  if (!f->d_func()->childFrames.isEmpty()) {
773  int pos = map.position(cb);
774  // check if we entered a frame
775  QTextDocumentPrivate::FragmentIterator frag = priv->find(pos-1);
776  if (priv->buffer().at(frag->stringPosition) != QChar::ParagraphSeparator) {
777  QTextFrame *nf = qobject_cast<QTextFrame *>(priv->objectForFormat(frag->format));
778  if (nf) {
779  if (priv->buffer().at(frag->stringPosition) == QTextBeginningOfFrame && nf != f) {
780  cf = nf;
781  cb = 0;
782  } else {
783  Q_ASSERT(priv->buffer().at(frag->stringPosition) != QTextEndOfFrame);
784  }
785  }
786  }
787  }
788  }
789  return *this;
790 }
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
The QTextFrame class represents a frame in a QTextDocument.
Definition: qtextobject.h:122
#define QTextBeginningOfFrame
T * qobject_cast(QObject *object)
Definition: qobject.h:375
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
FragmentMap::ConstIterator FragmentIterator
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
FragmentIterator find(int pos) const
int lastPosition() const
Returns the last document position inside the frame.
QTextDocumentPrivate * docHandle() const
QTextObject * objectForFormat(int formatIndex) const
uint position(uint node, uint field=0) const
const BlockMap & blockMap() const
uint next(uint n) const
QList< QTextFrame * > childFrames() const
Returns a (possibly empty) list of the frame&#39;s child frames.
QString buffer() const
uint findNode(int k, uint field=0) const
static const QMetaObjectPrivate * priv(const uint *data)
iterator end() const
Returns an iterator pointing to the position past the last document element inside the frame...
#define QTextEndOfFrame

◆ operator++() [2/2]

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

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

Definition at line 170 of file qtextobject.h.

Referenced by operator++().

170 { iterator tmp = *this; operator++(); return tmp; }
iterator()
Constructs an invalid iterator.
iterator & operator++()
Moves the iterator to the next frame or block.

◆ operator--() [1/2]

QTextFrame::iterator & QTextFrame::iterator::operator-- ( )

Moves the iterator to the previous frame or block.

See also
currentBlock() currentFrame()

Definition at line 797 of file qtextobject.cpp.

798 {
799  const QTextDocumentPrivate *priv = f->docHandle();
801  if (cf) {
802  int start = cf->firstPosition() - 1;
803  cb = map.findNode(start);
804  cf = 0;
805  } else {
806  if (cb == b)
807  goto end;
808  if (cb != e) {
809  int pos = map.position(cb);
810  // check if we have to enter a frame
811  QTextDocumentPrivate::FragmentIterator frag = priv->find(pos-1);
812  if (priv->buffer().at(frag->stringPosition) != QChar::ParagraphSeparator) {
813  QTextFrame *pf = qobject_cast<QTextFrame *>(priv->objectForFormat(frag->format));
814  if (pf) {
815  if (priv->buffer().at(frag->stringPosition) == QTextBeginningOfFrame) {
816  Q_ASSERT(pf == f);
817  } else if (priv->buffer().at(frag->stringPosition) == QTextEndOfFrame) {
818  Q_ASSERT(pf != f);
819  cf = pf;
820  cb = 0;
821  goto end;
822  }
823  }
824  }
825  }
826  cb = map.previous(cb);
827  }
828  end:
829  return *this;
830 }
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
The QTextFrame class represents a frame in a QTextDocument.
Definition: qtextobject.h:122
#define QTextBeginningOfFrame
T * qobject_cast(QObject *object)
Definition: qobject.h:375
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
int firstPosition() const
Returns the first document position inside the frame.
FragmentMap::ConstIterator FragmentIterator
FragmentIterator find(int pos) const
QTextDocumentPrivate * docHandle() const
QTextObject * objectForFormat(int formatIndex) const
uint position(uint node, uint field=0) const
const BlockMap & blockMap() const
QString buffer() const
uint previous(uint n) const
uint findNode(int k, uint field=0) const
static const QMetaObjectPrivate * priv(const uint *data)
iterator end() const
Returns an iterator pointing to the position past the last document element inside the frame...
#define QTextEndOfFrame

◆ operator--() [2/2]

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

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

Definition at line 172 of file qtextobject.h.

Referenced by operator--().

172 { iterator tmp = *this; operator--(); return tmp; }
iterator()
Constructs an invalid iterator.
iterator & operator--()
Moves the iterator to the previous frame or block.

◆ operator=()

QTextFrame::iterator & QTextFrame::iterator::operator= ( const iterator o)

Assigns other to this iterator and returns a reference to this iterator.

Definition at line 720 of file qtextobject.cpp.

721 {
722  f = other.f;
723  b = other.b;
724  e = other.e;
725  cf = other.cf;
726  cb = other.cb;
727  return *this;
728 }

◆ operator==()

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

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

Definition at line 167 of file qtextobject.h.

167 { return f == o.f && cf == o.cf && cb == o.cb; }

◆ parentFrame()

QTextFrame * QTextFrame::iterator::parentFrame ( ) const
inline

Friends and Related Functions

◆ QTextDocumentLayoutPrivate

Definition at line 153 of file qtextobject.h.

◆ QTextFrame

friend class QTextFrame
friend

Definition at line 151 of file qtextobject.h.

◆ QTextTableCell

friend class QTextTableCell
friend

Definition at line 152 of file qtextobject.h.

Properties

◆ b

int QTextFrame::iterator::b
private

Definition at line 146 of file qtextobject.h.

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

◆ cb

int QTextFrame::iterator::cb
private

◆ cf

QTextFrame* QTextFrame::iterator::cf
private

◆ e

int QTextFrame::iterator::e
private

Definition at line 147 of file qtextobject.h.

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

◆ f

QTextFrame* QTextFrame::iterator::f
private

Definition at line 145 of file qtextobject.h.

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


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