forked from qt-creator/qt-creator
TreeModel: Rework tree iteration
Use function objects to apply directly during a depth-first walk of the tree instead of faking a flat container of tree nodes. Less code, and allows even some non-const operations. Change-Id: I804ab11df358fe937b40809cbcb772e6f3ff8dc5 Reviewed-by: David Schulz <david.schulz@theqtcompany.com> Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -1074,41 +1074,4 @@ TreeItem *TreeModel::takeItem(TreeItem *item)
|
||||
return item;
|
||||
}
|
||||
|
||||
//
|
||||
// TreeLevelItems
|
||||
//
|
||||
|
||||
UntypedTreeLevelItems::UntypedTreeLevelItems(TreeItem *item, int level)
|
||||
: m_item(item), m_level(level)
|
||||
{}
|
||||
|
||||
UntypedTreeLevelItems::const_iterator::const_iterator(TreeItem *base, int level)
|
||||
: m_level(level)
|
||||
{
|
||||
QTC_ASSERT(level > 0, return);
|
||||
if (base) {
|
||||
// "begin()"
|
||||
m_depth = 0;
|
||||
// Level x: The item m_item[x] is the m_pos[x]'th child of its
|
||||
// parent, out of m_size[x].
|
||||
m_pos[0] = 0;
|
||||
m_size[0] = 1;
|
||||
m_item[0] = base;
|
||||
goDown();
|
||||
} else {
|
||||
// "end()"
|
||||
m_depth = -1;
|
||||
}
|
||||
}
|
||||
|
||||
UntypedTreeLevelItems::const_iterator UntypedTreeLevelItems::begin() const
|
||||
{
|
||||
return const_iterator(m_item, m_level);
|
||||
}
|
||||
|
||||
UntypedTreeLevelItems::const_iterator UntypedTreeLevelItems::end() const
|
||||
{
|
||||
return const_iterator(0, m_level);
|
||||
}
|
||||
|
||||
} // namespace Utils
|
||||
|
||||
Reference in New Issue
Block a user