Files
UnrealEngineUWP/Engine/Plugins/Runtime/ModelViewViewModel/Source/ModelViewViewModelBlueprint/Public/MVVMBlueprintViewModelContext.h
henrik karlsson 3c9aacb1ad [Engine/Plugins]
* Updated public headers for ~170 engine plugins using iwyu to remove includes not needed. Removed includes are still available behind UE_ENABLE_INCLUDE_ORDER_DEPRECATED_IN_5_2

#preflight 63c08f4a2a6acaf1622bcc73
#rb none

[CL 23674775 by henrik karlsson in ue5-main branch]
2023-01-13 01:54:01 -05:00

137 lines
3.8 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "Templates/SubclassOf.h"
#include "MVVMViewModelBase.h"
#include "MVVMBlueprintViewModelContext.generated.h"
/**
*
*/
UENUM()
enum class EMVVMBlueprintViewModelContextCreationType : uint8
{
// The viewmodel will be assigned later.
Manual,
// A new instance of the viewmodel will be created when the widget is created.
CreateInstance,
// The viewmodel exists and is added to the MVVMSubsystem. It will be fetched there.
GlobalViewModelCollection,
// The viewmodel will be fetched by evaluating a function or a property path.
PropertyPath,
};
/**
*
*/
USTRUCT(BlueprintType)
struct MODELVIEWVIEWMODELBLUEPRINT_API FMVVMBlueprintViewModelContext
{
GENERATED_BODY()
public:
FMVVMBlueprintViewModelContext() = default;
FMVVMBlueprintViewModelContext(const UClass* InClass, FName InViewModelName);
FGuid GetViewModelId() const
{
return ViewModelContextId;
}
FName GetViewModelName() const
{
return ViewModelName;
}
FText GetDisplayName() const;
UClass* GetViewModelClass() const
{
return NotifyFieldValueClass;
}
void PostSerialize(const FArchive& Ar)
{
if (Ar.IsLoading())
{
if (ViewModelName.IsNone())
{
ViewModelName = *OverrideDisplayName_DEPRECATED.ToString();
}
if (ViewModelName.IsNone() )
{
ViewModelName = *ViewModelContextId.ToString();
}
if (ViewModelClass_DEPRECATED.Get())
{
NotifyFieldValueClass = ViewModelClass_DEPRECATED.Get();
}
}
}
bool IsValid() const
{
return NotifyFieldValueClass != nullptr;
}
private:
/** When the view is spawn, create an instance of the viewmodel. */
UPROPERTY(VisibleAnywhere, AdvancedDisplay, Category = "MVVM")
FGuid ViewModelContextId;
UPROPERTY(VisibleAnywhere, Category = "MVVM", NoClear, meta = (AllowedClasses = "/Script/UMG.NotifyFieldValueChanged", DisallowedClasses = "/Script/UMG.Widget"))
TObjectPtr<UClass> NotifyFieldValueClass = nullptr;
UPROPERTY()
TSubclassOf<UMVVMViewModelBase> ViewModelClass_DEPRECATED;
UPROPERTY()
FText OverrideDisplayName_DEPRECATED;
public:
/** Property name that will be generated. */
UPROPERTY(EditAnywhere, Category = "MVVM")
FName ViewModelName;
/** When the view is spawn, create an instance of the viewmodel. */
UPROPERTY(EditAnywhere, Category = "MVVM")
EMVVMBlueprintViewModelContextCreationType CreationType = EMVVMBlueprintViewModelContextCreationType::CreateInstance;
/** Identifier of an already registered viewmodel. */
UPROPERTY(EditAnywhere, Category = "MVVM", AdvancedDisplay, meta = (EditCondition = "CreationType == EMVVMBlueprintViewModelContextCreationType::GlobalViewModelCollection"))
FName GlobalViewModelIdentifier;
/** The Path to get the viewmodel instance. */
UPROPERTY(EditAnywhere, Category = "MVVM", AdvancedDisplay, meta = (EditCondition = "CreationType == EMVVMBlueprintViewModelContextCreationType::PropertyPath"))
FString ViewModelPropertyPath;
/**
* Generate a setter function for this viewmodel.
* @note Always true when the Creation Type is Manual.
*/
UPROPERTY(EditAnywhere, Category = "MVVM", AdvancedDisplay, meta = (EditCondition = "CreationType != EMVVMBlueprintViewModelContextCreationType::Manual"))
bool bCreateSetterFunction = false;
/**
* Optional. Will not warn if the instance is not set or found.
* @note Always true when the Creation Type is Manual.
*/
UPROPERTY(EditAnywhere, Category = "MVVM", AdvancedDisplay, meta = (EditCondition = "CreationType == EMVVMBlueprintViewModelContextCreationType::GlobalViewModelCollection || CreationType == EMVVMBlueprintViewModelContextCreationType::PropertyPath"))
bool bOptional = false;
};
template<>
struct TStructOpsTypeTraits<FMVVMBlueprintViewModelContext> : public TStructOpsTypeTraitsBase2<FMVVMBlueprintViewModelContext>
{
enum
{
WithPostSerialize = true,
};
};
#if UE_ENABLE_INCLUDE_ORDER_DEPRECATED_IN_5_2
#include "CoreMinimal.h"
#endif