From af76fbf0e189b73663fe2b5d20007fe7c69b6081 Mon Sep 17 00:00:00 2001 From: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Thu, 8 Dec 2022 11:25:03 -0800 Subject: [PATCH] folder: revise child exists to find child function --- app/node/project/folder/folder.cpp | 18 ++++++++---------- app/node/project/folder/folder.h | 6 +++++- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/app/node/project/folder/folder.cpp b/app/node/project/folder/folder.cpp index 4bcd7cabc..d39c2e9e5 100644 --- a/app/node/project/folder/folder.cpp +++ b/app/node/project/folder/folder.cpp @@ -49,28 +49,26 @@ void Folder::Retranslate() SetInputName(kChildInput, tr("Children")); } -bool ChildExistsWithNameInternal(const Folder* n, const QString& s) +Node *GetChildWithNameInternal(const Folder* n, const QString& s) { for (int i=0; iitem_child_count(); i++) { Node* child = n->item_child(i); if (child->GetLabel() == s) { - return true; - } else { - Folder* subfolder = dynamic_cast(child); - - if (subfolder && ChildExistsWithNameInternal(subfolder, s)) { - return true; + return child; + } else if (Folder* subfolder = dynamic_cast(child)) { + if (Node *n2 = GetChildWithNameInternal(subfolder, s)) { + return n2; } } } - return false; + return nullptr; } -bool Folder::ChildExistsWithName(const QString &s) const +Node *Folder::GetChildWithName(const QString &s) const { - return ChildExistsWithNameInternal(this, s); + return GetChildWithNameInternal(this, s); } bool Folder::HasChildRecursive(Node *child) const diff --git a/app/node/project/folder/folder.h b/app/node/project/folder/folder.h index 22d25f110..2afb0ac1c 100644 --- a/app/node/project/folder/folder.h +++ b/app/node/project/folder/folder.h @@ -63,7 +63,11 @@ public: virtual void Retranslate() override; - bool ChildExistsWithName(const QString& s) const; + Node *GetChildWithName(const QString& s) const; + bool ChildExistsWithName(const QString& s) const + { + return GetChildWithName(s); + } bool HasChildRecursive(Node *child) const;