📄 qtreewidgetitemiterator.cpp
字号:
if ((flags & NotEditable) && (itemFlags & Qt::ItemIsEditable)) return false; } { // ### We only test the check state for column 0 Qt::CheckState check = item->checkState(0); // PartiallyChecked matches as Checked. if ((flags & Checked) && (check == Qt::Unchecked)) return false; if ((flags & NotChecked) && (check != Qt::Unchecked)) return false; } if ((flags & HasChildren) && !item->childCount()) return false; if ((flags & NoChildren) && item->childCount()) return false; { QTreeWidget *widget = item->view; Q_ASSERT(widget); bool hidden = widget->isItemHidden(item); if ((flags & Hidden) && !hidden) return false; if ((flags & NotHidden) && hidden) return false; bool selected = widget->isItemSelected(item); if ((flags & Selected) && !selected) return false; if ((flags & Unselected) && selected) return false; } return true;}/* * Implementation of QTreeWidgetItemIteratorPrivate */QTreeWidgetItem* QTreeWidgetItemIteratorPrivate::nextSibling(const QTreeWidgetItem* item) const{ Q_ASSERT(item); QTreeWidgetItem *next = 0; if (QTreeWidgetItem *par = item->parent()) { int i = par->indexOfChild(const_cast<QTreeWidgetItem*>(item)); next = par->child(i + 1); } else { QTreeWidget *tw = item->treeWidget(); int i = tw->indexOfTopLevelItem(const_cast<QTreeWidgetItem*>(item)); next = tw->topLevelItem(i + 1); } return next;}QTreeWidgetItem *QTreeWidgetItemIteratorPrivate::next(const QTreeWidgetItem *current){ if (!current) return 0; QTreeWidgetItem *next = 0; if (current->childCount()) { // walk the child m_parentIndex.push(m_currentIndex); m_currentIndex = 0; next = current->child(0); } else { // walk the sibling QTreeWidgetItem *parent = current->parent(); next = parent ? parent->child(m_currentIndex + 1) : m_model->rootItem->child(m_currentIndex + 1); while (!next && parent) { // if we had no sibling walk up the parent and try the sibling of that parent = parent->parent(); m_currentIndex = m_parentIndex.pop(); next = parent ? parent->child(m_currentIndex + 1) : m_model->rootItem->child(m_currentIndex + 1); } if (next) ++(m_currentIndex); } return next;}QTreeWidgetItem *QTreeWidgetItemIteratorPrivate::previous(const QTreeWidgetItem *current){ if (!current) return 0; QTreeWidgetItem *prev = 0; // walk the previous sibling QTreeWidgetItem *parent = current->parent(); prev = parent ? parent->child(m_currentIndex - 1) : m_model->rootItem->child(m_currentIndex - 1); if (prev) { // Yes, we had a previous sibling but we need go down to the last leafnode. --m_currentIndex; while (prev && prev->childCount()) { m_parentIndex.push(m_currentIndex); m_currentIndex = prev->childCount() - 1; prev = prev->child(m_currentIndex); } } else if (parent) { m_currentIndex = m_parentIndex.pop(); prev = parent; } return prev;}void QTreeWidgetItemIteratorPrivate::ensureValidIterator(const QTreeWidgetItem *itemToBeRemoved){ Q_Q(QTreeWidgetItemIterator); Q_ASSERT(itemToBeRemoved); if (!q->current) return; QTreeWidgetItem *nextItem = q->current; // Do not walk to the ancestor to find the other item if they have the same parent. if (nextItem->parent() != itemToBeRemoved->parent()) { while (nextItem->parent() && nextItem != itemToBeRemoved) { nextItem = nextItem->parent(); } } // If the item to be removed is an ancestor of the current iterator item, // we need to adjust the iterator. if (nextItem == itemToBeRemoved) { QTreeWidgetItem *parent = nextItem; nextItem = 0; while (parent && !nextItem) { nextItem = nextSibling(parent); parent = parent->parent(); } if (nextItem) { // Ooooh... Set the iterator to the next valid item *q = QTreeWidgetItemIterator(nextItem, q->flags); if (!(q->matchesFlags(nextItem))) ++(*q); } else { // set it to null. q->current = 0; m_parentIndex.clear(); return; } } if (nextItem->parent() == itemToBeRemoved->parent()) { // They have the same parent, i.e. we have to adjust the m_currentIndex member of the iterator // if the deleted item is to the left of the nextItem. QTreeWidgetItem *par = itemToBeRemoved->parent(); // We know they both have the same parent. QTreeWidget *tw = itemToBeRemoved->treeWidget(); // ..and widget int indexOfItemToBeRemoved = par ? par->indexOfChild(const_cast<QTreeWidgetItem *>(itemToBeRemoved)) : tw->indexOfTopLevelItem(const_cast<QTreeWidgetItem *>(itemToBeRemoved)); int indexOfNextItem = par ? par->indexOfChild(nextItem) : tw->indexOfTopLevelItem(nextItem); if (indexOfItemToBeRemoved <= indexOfNextItem) { // A sibling to the left of us was deleted, adjust the m_currentIndex member of the iterator. // Note that the m_currentIndex will be wrong until the item is actually removed! m_currentIndex--; } }}/*! \fn const QTreeWidgetItemIterator QTreeWidgetItemIterator::operator++(int) The postfix ++ operator (it++) advances the iterator to the next matching item and returns an iterator to the previously current item.*//*! \fn QTreeWidgetItemIterator &QTreeWidgetItemIterator::operator+=(int n) Makes the iterator go forward by \a n matching items. (If n is negative, the iterator goes backward.) If the current item is beyond the last item, the current item pointer is set to 0. Returns the resulting iterator.*//*! \fn const QTreeWidgetItemIterator QTreeWidgetItemIterator::operator--(int) The postfix -- operator (it--) makes the preceding matching item current and returns an iterator to the previously current item.*//*! \fn QTreeWidgetItemIterator &QTreeWidgetItemIterator::operator-=(int n) Makes the iterator go backward by \a n matching items. (If n is negative, the iterator goes forward.) If the current item is ahead of the last item, the current item pointer is set to 0. Returns the resulting iterator.*//*! \fn QTreeWidgetItem *QTreeWidgetItemIterator::operator*() const Dereference operator. Returns a pointer to the current item.*//*! \enum QTreeWidgetItemIterator::IteratorFlag These flags can be passed to a QTreeWidgetItemIterator constructor (OR-ed together if more than one is used), so that the iterator will only iterate over items that match the given flags. \value All \value Hidden \value NotHidden \value Selected \value Unselected \value Selectable \value NotSelectable \value DragEnabled \value DragDisabled \value DropEnabled \value DropDisabled \value HasChildren \value NoChildren \value Checked \value NotChecked \value Enabled \value Disabled \value Editable \value NotEditable \value UserFlag*/#endif // QT_NO_TREEWIDGET
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -