4#include "CoreMinimal.h"
5#include "Widgets/Views/STreeView.h"
8template <
class SelfType>
23 return Parent.Pin()->OnClick();
26 return FReply::Unhandled();
35 return DisplayText.ToString().Contains(InSearch, SearchCase);
49 for (
const TSharedPtr<SelfType>& Child :
Children)
51 if (Child->IsVisible())
53 OutChildren.Add(Child);
57 virtual void AddChild(
const TSharedPtr<SelfType>& ChildNode)
59 ensure(!ChildNode->IsRoot());
60 ChildNode->SetParent(this->AsShared());
63 virtual void SetChildren(
const TArray<TSharedPtr<SelfType>>& InChildren)
66 for (
const TSharedPtr<SelfType>& Child :
Children)
68 ensure(!Child->IsRoot());
69 Child->SetParent(this->AsShared());
95 static constexpr bool bShouldExpandItem =
true;
101 TreeView->SetItemExpansion(this->AsShared(), bShouldExpandItem);
102 for (
const TSharedPtr<SelfType>& ChildNode :
Children)
107 ChildNode->ExpandAllChildren(
TreeView, bRecursive);
112 TreeView->SetItemExpansion(ChildNode, bShouldExpandItem);
122 void GetAllNodes(TArray<TSharedPtr<SelfType>>& OutNodeArray)
const
124 for (
const TSharedPtr<SelfType>& ChildNode :
Children)
126 OutNodeArray.Add(ChildNode);
127 ChildNode->GetAllNodes(OutNodeArray);
138 for (int32 Index = 0, Num =
Children.Num(); Index < Num; Index++)
140 TSharedPtr<SelfType> CurrentChild =
Children[Index];
141 CurrentChild->SetIsVisible(
false);
159 return GrandChild->IsLeaf();
165 return Child->DoesDisplayTextContains(InSearch);
169 const TSharedPtr<SelfType>& Child,
170 const FString& InSearch,
171 TArray<TArray<TSharedPtr<SelfType>>>& OutNodes
175 bool bChildIsVisible;
178 bChildIsVisible =
true;
181 TSharedPtr<SelfType> CurrentNode = Child;
182 TArray<TSharedPtr<SelfType>> ChildOutNodes;
183 while (CurrentNode->HasParent())
185 ChildOutNodes.Add(CurrentNode);
188 TSharedPtr<SelfType> CurrentParentNode = CurrentNode->GetParent().Pin();
189 CurrentParentNode->SetIsVisible(bChildIsVisible);
192 CurrentNode = CurrentParentNode;
198 Algo::Reverse(ChildOutNodes);
199 OutNodes.Emplace(ChildOutNodes);
203 bChildIsVisible =
false;
205 Child->SetIsVisible(bChildIsVisible);
208 for (
const TSharedPtr<SelfType>& GrandChild : Child->GetChildren())
bool DoesDisplayTextContains(const FString &InSearch, ESearchCase::Type SearchCase=ESearchCase::IgnoreCase)
virtual void PostBuildPathToTopMostParent(const TSharedPtr< SelfType > &CurrentParentNode)
void GetVisibleChildren(TArray< TSharedPtr< SelfType > > &OutChildren)
virtual bool FilterDoesChildContainText(const TSharedPtr< SelfType > &Child, const FString &InSearch)
void SetDisplayText(const FText &InText)
const TArray< TSharedPtr< SelfType > > & GetChildren() const
void SetParent(TWeakPtr< SelfType > InParentNode)
virtual ~FDlgTreeViewNode()
FDlgTreeViewNode(const FText &InDisplayText, const TSharedPtr< SelfType > &InParent)
virtual void GetPathToChildThatContainsText(const TSharedPtr< SelfType > &Child, const FString &InSearch, TArray< TArray< TSharedPtr< SelfType > > > &OutNodes)
virtual void PostFilterPathsToNodes(const TSharedPtr< SelfType > &Child)
FText GetDisplayText() const
virtual void SetChildren(const TArray< TSharedPtr< SelfType > > &InChildren)
virtual void AddChild(const TSharedPtr< SelfType > &ChildNode)
TArray< TSharedPtr< SelfType > > Children
virtual bool FilterIsChildVisible(const TSharedPtr< SelfType > &GrandChild)
TWeakPtr< SelfType > Parent
void GetAllNodes(TArray< TSharedPtr< SelfType > > &OutNodeArray) const
virtual void ClearChildren()
virtual void FilterPathsToNodesThatContainText(const FString &InSearch, TArray< TArray< TSharedPtr< SelfType > > > &OutNodes)
void SetIsVisible(bool InIsVisible)
TWeakPtr< SelfType > GetParent() const
void ExpandAllChildren(const TSharedPtr< STreeView< TSharedPtr< SelfType > > > &TreeView, bool bRecursive=true)
FName GetDisplayTextAsFName() const