Qt 4.8
Public Functions | Properties | List of all members
QTreeWidgetItemIteratorPrivate Class Reference

#include <qtreewidgetitemiterator_p.h>

Public Functions

void ensureValidIterator (const QTreeWidgetItem *itemToBeRemoved)
 
QTreeWidgetItemnext (const QTreeWidgetItem *current)
 
QTreeWidgetItemnextSibling (const QTreeWidgetItem *item) const
 
QTreeWidgetItemIteratorPrivateoperator= (const QTreeWidgetItemIteratorPrivate &other)
 
QTreeWidgetItemprevious (const QTreeWidgetItem *current)
 
 QTreeWidgetItemIteratorPrivate (QTreeWidgetItemIterator *q, QTreeModel *model)
 
 QTreeWidgetItemIteratorPrivate (const QTreeWidgetItemIteratorPrivate &other)
 
 ~QTreeWidgetItemIteratorPrivate ()
 

Properties

int m_currentIndex
 
QTreeModelm_model
 
QStack< int > m_parentIndex
 
QTreeWidgetItemIteratorq_ptr
 

Detailed Description

Definition at line 66 of file qtreewidgetitemiterator_p.h.

Constructors and Destructors

◆ QTreeWidgetItemIteratorPrivate() [1/2]

QTreeWidgetItemIteratorPrivate::QTreeWidgetItemIteratorPrivate ( QTreeWidgetItemIterator q,
QTreeModel model 
)
inline

Definition at line 69 of file qtreewidgetitemiterator_p.h.

◆ QTreeWidgetItemIteratorPrivate() [2/2]

QTreeWidgetItemIteratorPrivate::QTreeWidgetItemIteratorPrivate ( const QTreeWidgetItemIteratorPrivate other)
inline

◆ ~QTreeWidgetItemIteratorPrivate()

QTreeWidgetItemIteratorPrivate::~QTreeWidgetItemIteratorPrivate ( )
inline

Definition at line 90 of file qtreewidgetitemiterator_p.h.

91  {
92  }

Functions

◆ ensureValidIterator()

void QTreeWidgetItemIteratorPrivate::ensureValidIterator ( const QTreeWidgetItem itemToBeRemoved)

Definition at line 337 of file qtreewidgetitemiterator.cpp.

Referenced by ~QTreeWidgetItemIteratorPrivate().

338 {
340  Q_ASSERT(itemToBeRemoved);
341 
342  if (!q->current) return;
343  QTreeWidgetItem *nextItem = q->current;
344 
345  // Do not walk to the ancestor to find the other item if they have the same parent.
346  if (nextItem->parent() != itemToBeRemoved->parent()) {
347  while (nextItem->parent() && nextItem != itemToBeRemoved) {
348  nextItem = nextItem->parent();
349  }
350  }
351  // If the item to be removed is an ancestor of the current iterator item,
352  // we need to adjust the iterator.
353  if (nextItem == itemToBeRemoved) {
354  QTreeWidgetItem *parent = nextItem;
355  nextItem = 0;
356  while (parent && !nextItem) {
357  nextItem = nextSibling(parent);
358  parent = parent->parent();
359  }
360  if (nextItem) {
361  // Ooooh... Set the iterator to the next valid item
362  *q = QTreeWidgetItemIterator(nextItem, q->flags);
363  if (!(q->matchesFlags(nextItem))) ++(*q);
364  } else {
365  // set it to null.
366  q->current = 0;
368  return;
369  }
370  }
371  if (nextItem->parent() == itemToBeRemoved->parent()) {
372  // They have the same parent, i.e. we have to adjust the m_currentIndex member of the iterator
373  // if the deleted item is to the left of the nextItem.
374 
375  QTreeWidgetItem *par = itemToBeRemoved->parent(); // We know they both have the same parent.
376  QTreeWidget *tw = itemToBeRemoved->treeWidget(); // ..and widget
377  int indexOfItemToBeRemoved = par ? par->indexOfChild(const_cast<QTreeWidgetItem *>(itemToBeRemoved))
378  : tw->indexOfTopLevelItem(const_cast<QTreeWidgetItem *>(itemToBeRemoved));
379  int indexOfNextItem = par ? par->indexOfChild(nextItem) : tw->indexOfTopLevelItem(nextItem);
380 
381  if (indexOfItemToBeRemoved <= indexOfNextItem) {
382  // A sibling to the left of us was deleted, adjust the m_currentIndex member of the iterator.
383  // Note that the m_currentIndex will be wrong until the item is actually removed!
384  m_currentIndex--;
385  }
386  }
387 }
Qt::ItemFlags flags() const
Returns the flags used to describe the item.
The QTreeWidget class provides a tree view that uses a predefined tree model.
Definition: qtreewidget.h:260
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
int indexOfTopLevelItem(QTreeWidgetItem *item)
QTreeWidgetItem * nextSibling(const QTreeWidgetItem *item) const
#define Q_Q(Class)
Definition: qglobal.h:2483
The QTreeWidgetItemIterator class provides a way to iterate over the items in a QTreeWidget instance...
QTreeWidgetItem * parent() const
Returns the item&#39;s parent.
Definition: qtreewidget.h:183
void clear()
Removes all the elements from the vector and releases the memory used by the vector.
Definition: qvector.h:347
The QTreeWidgetItem class provides an item for use with the QTreeWidget convenience class...
Definition: qtreewidget.h:63
int indexOfChild(QTreeWidgetItem *child) const
Returns the index of the given child in the item&#39;s list of children.
Definition: qtreewidget.h:250
QTreeWidget * treeWidget() const
Returns the tree widget that contains the item.
Definition: qtreewidget.h:85

◆ next()

QTreeWidgetItem * QTreeWidgetItemIteratorPrivate::next ( const QTreeWidgetItem current)

Definition at line 286 of file qtreewidgetitemiterator.cpp.

Referenced by ~QTreeWidgetItemIteratorPrivate().

287 {
288  if (!current) return 0;
289 
290  QTreeWidgetItem *next = 0;
291  if (current->childCount()) {
292  // walk the child
294  m_currentIndex = 0;
295  next = current->child(0);
296  } else {
297  // walk the sibling
298  QTreeWidgetItem *parent = current->parent();
299  next = parent ? parent->child(m_currentIndex + 1)
301  while (!next && parent) {
302  // if we had no sibling walk up the parent and try the sibling of that
303  parent = parent->parent();
305  next = parent ? parent->child(m_currentIndex + 1)
307  }
308  if (next) ++(m_currentIndex);
309  }
310  return next;
311 }
int childCount() const
Returns the number of child items.
Definition: qtreewidget.h:190
T pop()
Removes the top item from the stack and returns it.
Definition: qstack.h:67
QTreeWidgetItem * parent() const
Returns the item&#39;s parent.
Definition: qtreewidget.h:183
QTreeWidgetItem * rootItem
void push(const T &t)
Adds element t to the top of the stack.
Definition: qstack.h:60
QTreeWidgetItem * next(const QTreeWidgetItem *current)
The QTreeWidgetItem class provides an item for use with the QTreeWidget convenience class...
Definition: qtreewidget.h:63
QTreeWidgetItem * child(int index) const
Returns the item at the given index in the list of the item&#39;s children.
Definition: qtreewidget.h:184

◆ nextSibling()

QTreeWidgetItem * QTreeWidgetItemIteratorPrivate::nextSibling ( const QTreeWidgetItem item) const

Definition at line 271 of file qtreewidgetitemiterator.cpp.

Referenced by ~QTreeWidgetItemIteratorPrivate().

272 {
273  Q_ASSERT(item);
274  QTreeWidgetItem *next = 0;
275  if (QTreeWidgetItem *par = item->parent()) {
276  int i = par->indexOfChild(const_cast<QTreeWidgetItem*>(item));
277  next = par->child(i + 1);
278  } else {
279  QTreeWidget *tw = item->treeWidget();
280  int i = tw->indexOfTopLevelItem(const_cast<QTreeWidgetItem*>(item));
281  next = tw->topLevelItem(i + 1);
282  }
283  return next;
284 }
The QTreeWidget class provides a tree view that uses a predefined tree model.
Definition: qtreewidget.h:260
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
int indexOfTopLevelItem(QTreeWidgetItem *item)
QTreeWidgetItem * topLevelItem(int index) const
Returns the top level item at the given index, or 0 if the item does not exist.
QTreeWidgetItem * parent() const
Returns the item&#39;s parent.
Definition: qtreewidget.h:183
QTreeWidgetItem * next(const QTreeWidgetItem *current)
The QTreeWidgetItem class provides an item for use with the QTreeWidget convenience class...
Definition: qtreewidget.h:63
QTreeWidgetItem * child(int index) const
Returns the item at the given index in the list of the item&#39;s children.
Definition: qtreewidget.h:184
int indexOfChild(QTreeWidgetItem *child) const
Returns the index of the given child in the item&#39;s list of children.
Definition: qtreewidget.h:250
QTreeWidget * treeWidget() const
Returns the tree widget that contains the item.
Definition: qtreewidget.h:85

◆ operator=()

QTreeWidgetItemIteratorPrivate& QTreeWidgetItemIteratorPrivate::operator= ( const QTreeWidgetItemIteratorPrivate other)
inline

Definition at line 82 of file qtreewidgetitemiterator_p.h.

◆ previous()

QTreeWidgetItem * QTreeWidgetItemIteratorPrivate::previous ( const QTreeWidgetItem current)

Definition at line 313 of file qtreewidgetitemiterator.cpp.

Referenced by ~QTreeWidgetItemIteratorPrivate().

314 {
315  if (!current) return 0;
316 
317  QTreeWidgetItem *prev = 0;
318  // walk the previous sibling
319  QTreeWidgetItem *parent = current->parent();
320  prev = parent ? parent->child(m_currentIndex - 1)
322  if (prev) {
323  // Yes, we had a previous sibling but we need go down to the last leafnode.
324  --m_currentIndex;
325  while (prev && prev->childCount()) {
327  m_currentIndex = prev->childCount() - 1;
328  prev = prev->child(m_currentIndex);
329  }
330  } else if (parent) {
332  prev = parent;
333  }
334  return prev;
335 }
int childCount() const
Returns the number of child items.
Definition: qtreewidget.h:190
T pop()
Removes the top item from the stack and returns it.
Definition: qstack.h:67
QTreeWidgetItem * parent() const
Returns the item&#39;s parent.
Definition: qtreewidget.h:183
QTreeWidgetItem * rootItem
void push(const T &t)
Adds element t to the top of the stack.
Definition: qstack.h:60
The QTreeWidgetItem class provides an item for use with the QTreeWidget convenience class...
Definition: qtreewidget.h:63
QTreeWidgetItem * child(int index) const
Returns the item at the given index in the list of the item&#39;s children.
Definition: qtreewidget.h:184

Properties

◆ m_currentIndex

int QTreeWidgetItemIteratorPrivate::m_currentIndex
private

Definition at line 100 of file qtreewidgetitemiterator_p.h.

Referenced by operator=().

◆ m_model

QTreeModel* QTreeWidgetItemIteratorPrivate::m_model
private

Definition at line 101 of file qtreewidgetitemiterator_p.h.

Referenced by operator=().

◆ m_parentIndex

QStack<int> QTreeWidgetItemIteratorPrivate::m_parentIndex
private

Definition at line 102 of file qtreewidgetitemiterator_p.h.

Referenced by operator=().

◆ q_ptr

QTreeWidgetItemIterator* QTreeWidgetItemIteratorPrivate::q_ptr
private

Definition at line 103 of file qtreewidgetitemiterator_p.h.


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