Commit a4b2801f authored by hjk's avatar hjk

TreeModel: Make TreeModelVisitor useful

Functions that are meant to be overridden should be virtual.
Also add a convience level() function, seems to be a common need.

Change-Id: I09d452ab12f0ac29fb31de853057511418a47e7e
Reviewed-by: default avatarChristian Stenger <christian.stenger@theqtcompany.com>
parent 10f36ead
......@@ -777,10 +777,13 @@ void TreeItem::setModel(TreeModel *model)
void TreeItem::walkTree(TreeItemVisitor *visitor)
{
if (visitor->preVisit(this)) {
++visitor->m_level;
visitor->visit(this);
foreach (TreeItem *item, m_children)
item->walkTree(visitor);
--visitor->m_level;
}
visitor->postVisit(this);
}
void TreeItem::walkTree(std::function<void (TreeItem *)> f)
......
......@@ -49,11 +49,18 @@ class TreeModel;
class QTCREATOR_UTILS_EXPORT TreeItemVisitor
{
public:
TreeItemVisitor() {}
TreeItemVisitor() : m_level(0) {}
virtual ~TreeItemVisitor() {}
bool preVisit(TreeItem *) { return true; }
void visit(TreeItem *) {}
virtual bool preVisit(TreeItem *) { return true; }
virtual void visit(TreeItem *) {}
virtual void postVisit(TreeItem *) {}
int level() const { return m_level; }
private:
friend class TreeItem;
int m_level;
};
class QTCREATOR_UTILS_EXPORT TreeItem
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment