mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-05-27 04:11:05 +00:00
Add RDTreeWidgetItemIterator for depth-first forward-only iteration
This commit is contained in:
@@ -412,6 +412,48 @@ void RDTreeWidgetItem::clear()
|
||||
m_widget->m_model->endRemoveChildren();
|
||||
}
|
||||
|
||||
RDTreeWidgetItemIterator::RDTreeWidgetItemIterator(RDTreeWidget *widget)
|
||||
{
|
||||
if(widget->topLevelItemCount() == 0)
|
||||
m_Current = NULL;
|
||||
else
|
||||
m_Current = widget->topLevelItem(0);
|
||||
}
|
||||
|
||||
RDTreeWidgetItemIterator &RDTreeWidgetItemIterator::operator++()
|
||||
{
|
||||
// depth first
|
||||
if(m_Current->childCount() > 0)
|
||||
{
|
||||
m_Current = m_Current->child(0);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// otherwise check if we have siblings, recursively up
|
||||
RDTreeWidgetItem *parent = m_Current->parent();
|
||||
RDTreeWidgetItem *child = m_Current;
|
||||
while(parent)
|
||||
{
|
||||
// if there's a sibling at this level, move to it
|
||||
int idx = parent->indexOfChild(child);
|
||||
if(idx + 1 < parent->childCount())
|
||||
{
|
||||
m_Current = parent->child(idx + 1);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// if there are no more siblings at this level, move up
|
||||
child = parent;
|
||||
parent = parent->parent();
|
||||
|
||||
// if we just exhausted siblings at the top-level, parent will now be NULL, so we abort.
|
||||
}
|
||||
|
||||
// no more siblings, stop.
|
||||
m_Current = NULL;
|
||||
return *this;
|
||||
}
|
||||
|
||||
RDTreeWidget::RDTreeWidget(QWidget *parent) : RDTreeView(parent)
|
||||
{
|
||||
// we'll call this ourselves in drawBranches()
|
||||
|
||||
@@ -145,6 +145,35 @@ private:
|
||||
QVariant m_tag;
|
||||
};
|
||||
|
||||
class RDTreeWidgetItemIterator
|
||||
{
|
||||
public:
|
||||
RDTreeWidgetItemIterator(RDTreeWidget *widget);
|
||||
|
||||
RDTreeWidgetItemIterator &operator++();
|
||||
inline const RDTreeWidgetItemIterator operator++(int)
|
||||
{
|
||||
RDTreeWidgetItemIterator it = *this;
|
||||
++(*this);
|
||||
return it;
|
||||
}
|
||||
|
||||
// TODO implement operator-- if we need it.
|
||||
/*
|
||||
RDTreeWidgetItemIterator &operator--();
|
||||
inline const RDTreeWidgetItemIterator operator--(int)
|
||||
{
|
||||
RDTreeWidgetItemIterator it = *this;
|
||||
--(*this);
|
||||
return it;
|
||||
}
|
||||
*/
|
||||
|
||||
inline RDTreeWidgetItem *operator*() const { return m_Current; }
|
||||
private:
|
||||
RDTreeWidgetItem *m_Current;
|
||||
};
|
||||
|
||||
class RDTreeWidget : public RDTreeView
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Reference in New Issue
Block a user