Skip to content

Commit

Permalink
folder: revise child exists to find child function
Browse files Browse the repository at this point in the history
  • Loading branch information
itsmattkc committed Dec 8, 2022
1 parent b99d1e5 commit af76fbf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
18 changes: 8 additions & 10 deletions app/node/project/folder/folder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; i<n->item_child_count(); i++) {
Node* child = n->item_child(i);

if (child->GetLabel() == s) {
return true;
} else {
Folder* subfolder = dynamic_cast<Folder*>(child);

if (subfolder && ChildExistsWithNameInternal(subfolder, s)) {
return true;
return child;
} else if (Folder* subfolder = dynamic_cast<Folder*>(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
Expand Down
6 changes: 5 additions & 1 deletion app/node/project/folder/folder.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ class Folder : public Node

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;

Expand Down

0 comments on commit af76fbf

Please sign in to comment.