ComposerStateQueryCustom.cpp
1 // Copyright (C) 2025 Radaway Software LLC. All Rights Reserved. 2 3 4 #include "ComposerStateQueryCustom.h" 5 #include "PropertyEditing.h" 6 #include "PropertyCustomizationHelpers.h" 7 #include "ISinglePropertyView.h" 8 #include "IPropertyUtilities.h" 9 10 TMap<FName, TSharedRef<IPropertyTypeCustomization>> ComposerStateQueryCustom::Customizations; 11 12 TSharedRef<IPropertyTypeCustomization> ComposerStateQueryCustom::MakeInstance() 13 { 14 return MakeShareable(new ComposerStateQueryCustom()); 15 } 16 17 void ComposerStateQueryCustom::AddChildCustomization(const FName Name, TSharedRef<IPropertyTypeCustomization> Customization) 18 { 19 Customizations.Add(Name, Customization); 20 } 21 22 void ComposerStateQueryCustom::CustomizeChildren(TSharedRef<IPropertyHandle> StructPropertyHandle, IDetailChildrenBuilder& StructBuilder, IPropertyTypeCustomizationUtils& StructCustomizationUtils) 23 { 24 UObject* Value = nullptr; 25 bool bFallback = false; 26 if (StructPropertyHandle->GetValue(Value) == FPropertyAccess::Success) 27 { 28 if (Value == nullptr) 29 { 30 return; 31 } 32 33 FName ActualClassName = Value->GetClass()->GetFName(); 34 TSharedRef<IPropertyTypeCustomization>* Customization = Customizations.Find(ActualClassName); 35 if (Customization) 36 { 37 (*Customization)->CustomizeChildren(StructPropertyHandle, StructBuilder, StructCustomizationUtils); 38 } 39 else 40 { 41 FAddPropertyParams Params; 42 Params.AllowChildren(true) 43 .HideRootObjectNode(true) 44 .UniqueId(StructPropertyHandle->GetProperty()->GetID()) 45 ; 46 StructBuilder.AddExternalObjects(TArray<UObject*> { Value }, Params); 47 } 48 } 49 50 } 51 52 void ComposerStateQueryCustom::CustomizeHeader(TSharedRef<IPropertyHandle> StructPropertyHandle, FDetailWidgetRow& HeaderRow, IPropertyTypeCustomizationUtils& StructCustomizationUtils) 53 { 54 UObject* Value = nullptr; 55 bool bFallback = false; 56 if (StructPropertyHandle->GetValue(Value) == FPropertyAccess::Success) 57 { 58 if (Value == nullptr) 59 { 60 goto fallback; 61 } 62 63 FName ActualClassName = Value->GetClass()->GetFName(); 64 TSharedRef<IPropertyTypeCustomization>* Customization = Customizations.Find(ActualClassName); 65 if (Customization) 66 { 67 (*Customization)->CustomizeHeader(StructPropertyHandle, HeaderRow, StructCustomizationUtils); 68 } 69 else 70 { 71 goto fallback; 72 } 73 } 74 else 75 { 76 goto fallback; 77 } 78 79 fallback: 80 HeaderRow 81 .NameContent() 82 [ 83 StructPropertyHandle->CreatePropertyNameWidget() 84 ] 85 .ValueContent() 86 [ 87 StructPropertyHandle->CreatePropertyValueWidget() 88 ]; 89 } 90