From 17c64e27f8b47a03fee3c748d0caf20d24c1cce6 Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Tue, 23 Jan 2018 10:22:45 +0100 Subject: [PATCH] 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 Reviewed-by: Eike Ziller --- src/libs/utils/treemodel.cpp | 4 ++-- src/libs/utils/treemodel.h | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/libs/utils/treemodel.cpp b/src/libs/utils/treemodel.cpp index 61a6a8974c1..6c182ba48e6 100644 --- a/src/libs/utils/treemodel.cpp +++ b/src/libs/utils/treemodel.cpp @@ -866,10 +866,10 @@ TreeItem *TreeItem::reverseFindAnyChild(const std::function & { 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; } diff --git a/src/libs/utils/treemodel.h b/src/libs/utils/treemodel.h index 41300b7dbc4..1cef3645111 100644 --- a/src/libs/utils/treemodel.h +++ b/src/libs/utils/treemodel.h @@ -82,7 +82,8 @@ public: void forSelectedChildren(const std::function &pred) const; void forAllChildren(const std::function &pred) const; TreeItem *findAnyChild(const std::function &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 &pred) const; // Levels are 1-based: Child at Level 1 is an immediate child.