Utils: Change processing of children in reverseFindAnyChild()

This changes the processing of children to step down into the children
first (and their children recursively) instead of just processing direct
children in reverse.
Fixes an issue with AutoTest plugin where results of data tags got a
new intermediate although there was already one present.

Change-Id: I1fe42942db975c7a1aa3ddb0b6596979c1164dd7
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Christian Stenger
2018-01-23 10:22:45 +01:00
parent 6b38c73205
commit 17c64e27f8
2 changed files with 4 additions and 3 deletions

View File

@@ -866,10 +866,10 @@ TreeItem *TreeItem::reverseFindAnyChild(const std::function<bool (TreeItem *)> &
{
auto end = m_children.rend();
for (auto it = m_children.rbegin(); it != end; ++it) {
if (pred(*it))
return *it;
if (TreeItem *found = (*it)->reverseFindAnyChild(pred))
return found;
if (pred(*it))
return *it;
}
return nullptr;
}

View File

@@ -82,7 +82,8 @@ public:
void forSelectedChildren(const std::function<bool(TreeItem *)> &pred) const;
void forAllChildren(const std::function<void(TreeItem *)> &pred) const;
TreeItem *findAnyChild(const std::function<bool(TreeItem *)> &pred) const;
// like findAnyChild() but processes children from bottom to top
// like findAnyChild() but processes children in exact reverse order
// (bottom to top, most inner children first)
TreeItem *reverseFindAnyChild(const std::function<bool(TreeItem *)> &pred) const;
// Levels are 1-based: Child at Level 1 is an immediate child.