Files
UnrealEngineUWP/Engine/Source/Editor/DeviceProfileEditor/Private/DeviceProfileConsoleVariableColumn.cpp
aurel cordonnier a12d56ff31 Merge from Release-Engine-Staging @ 17791557 to Release-Engine-Test
This represents UE4/Main @17774255, Release-5.0 @17791557 and Dev-PerfTest @17789485

[CL 17794212 by aurel cordonnier in ue5-release-engine-test branch]
2021-10-12 21:21:22 -04:00

173 lines
4.4 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
// Module includes
#include "DeviceProfileConsoleVariableColumn.h"
#include "UObject/UnrealType.h"
#include "DeviceProfiles/DeviceProfile.h"
#include "Widgets/Images/SImage.h"
#include "Widgets/Input/SButton.h"
#include "EditorStyleSet.h"
#include "IPropertyTableCellPresenter.h"
// Property table includes
#include "IPropertyTable.h"
#include "IPropertyTableCell.h"
// Misc includes
#define LOCTEXT_NAMESPACE "DeviceProfileEditor"
/**
* Formatter of the console variable property for a device profile.
*/
class FConsoleVariableCellPresenter : public TSharedFromThis< FConsoleVariableCellPresenter > , public IPropertyTableCellPresenter
{
public:
/**
* Constructor
*/
FConsoleVariableCellPresenter(TWeakObjectPtr<UDeviceProfile> InOwnerProfile, const FOnEditDeviceProfileCVarsRequestDelegate& OnCVarsEditRequest )
: OwnerProfile(InOwnerProfile)
, OnEditCVarsRequest(OnCVarsEditRequest)
{
}
virtual ~FConsoleVariableCellPresenter() {}
/**
* Event handler triggered when the user presses the edit CVars button
*
* @return Whether the event was handled.
*/
FReply HandleEditCVarsButtonPressed()
{
OnEditCVarsRequest.ExecuteIfBound(OwnerProfile);
return FReply::Handled();
}
public:
/** Begin IPropertyTableCellPresenter interface */
virtual TSharedRef<class SWidget> ConstructDisplayWidget() override;
virtual bool RequiresDropDown() override
{
return false;
}
virtual TSharedRef< class SWidget > ConstructEditModeCellWidget() override
{
return ConstructDisplayWidget();
}
virtual TSharedRef< class SWidget > ConstructEditModeDropDownWidget() override
{
return SNullWidget::NullWidget;
}
virtual TSharedRef< class SWidget > WidgetToFocusOnEdit() override
{
return SNullWidget::NullWidget;
}
virtual bool HasReadOnlyEditMode() override
{
return true;
}
virtual FString GetValueAsString() override
{
return TEXT("");
}
virtual FText GetValueAsText() override
{
return FText::FromString(TEXT(""));
}
/** End IPropertyTableCellPresenter interface */
private:
/** The object we will link to */
TWeakObjectPtr<UDeviceProfile> OwnerProfile;
/** Delegate triggered when the user opts to edit the CVars from the button in this cell */
FOnEditDeviceProfileCVarsRequestDelegate OnEditCVarsRequest;
};
TSharedRef<class SWidget> FConsoleVariableCellPresenter::ConstructDisplayWidget()
{
return SNew(SBorder)
.Padding(0.0f)
.VAlign(VAlign_Center)
.HAlign(HAlign_Center)
.BorderImage(FEditorStyle::GetBrush("NoBorder"))
.Content()
[
SNew(SButton)
.OnClicked(this, &FConsoleVariableCellPresenter::HandleEditCVarsButtonPressed)
.ContentPadding(2.0f)
.ButtonStyle(FAppStyle::Get(), "DeviceDetails.EditButton")
[
SNew(SImage)
.Image(FEditorStyle::GetBrush("Icons.Edit"))
.ColorAndOpacity(FSlateColor::UseForeground())
]
];
}
FDeviceProfileConsoleVariableColumn::FDeviceProfileConsoleVariableColumn()
{
}
bool FDeviceProfileConsoleVariableColumn::Supports(const TSharedRef< IPropertyTableColumn >& Column, const TSharedRef< IPropertyTableUtilities >& Utilities) const
{
if( Column->GetDataSource()->IsValid() )
{
TSharedPtr< FPropertyPath > PropertyPath = Column->GetDataSource()->AsPropertyPath();
if( PropertyPath.IsValid() && PropertyPath->GetNumProperties() > 0 )
{
const FPropertyInfo& PropertyInfo = PropertyPath->GetRootProperty();
FProperty* Property = PropertyInfo.Property.Get();
if (Property->GetName() == TEXT("CVars") && Property->IsA(FArrayProperty::StaticClass()))
{
return true;
}
}
}
return false;
}
TSharedPtr< SWidget > FDeviceProfileConsoleVariableColumn::CreateColumnLabel(const TSharedRef< IPropertyTableColumn >& Column, const TSharedRef< IPropertyTableUtilities >& Utilities, const FName& Style) const
{
return NULL;
}
TSharedPtr< IPropertyTableCellPresenter > FDeviceProfileConsoleVariableColumn::CreateCellPresenter(const TSharedRef< IPropertyTableCell >& Cell, const TSharedRef< IPropertyTableUtilities >& Utilities, const FName& Style) const
{
TSharedPtr< IPropertyHandle > PropertyHandle = Cell->GetPropertyHandle();
if( PropertyHandle.IsValid() )
{
TArray<UObject*> OuterObjects;
PropertyHandle->GetOuterObjects(OuterObjects);
if (OuterObjects.Num() == 1)
{
return MakeShareable(new FConsoleVariableCellPresenter(CastChecked<UDeviceProfile>(OuterObjects[0]),OnEditCVarsRequestDelegate));
}
}
return NULL;
}
#undef LOCTEXT_NAMESPACE