Files
UnrealEngineUWP/Engine/Source/Developer/Settings/Private/SettingsContainer.h
Max Preussner 3aece47882 Docs: Removed file comments and added missing code documentation
Please note that file comments had no purpose in nearly all cases and just added visual clutter. The two files that had meaningful file comments had their comments moved into the corresponding classes. There are still hundreds of file comments left in other files that will be removed over time.

Also cleaned up some random stuff along the way:
- relative paths to public headers within the same module are no longer necessary (automatically discovered by UBT now)
- header guards are deprecated, use #pragma once instead (all compilers support it now)
- space between multiple template brackets is no longer required (all compilers support >> now)
- NULL to nullptr, OVERRIDE to override
- spelling errors, whitespace, line breaks

[CL 2104067 by Max Preussner in Main branch]
2014-06-12 23:22:18 -04:00

200 lines
5.7 KiB
C++

// Copyright 1998-2014 Epic Games, Inc. All Rights Reserved.
#pragma once
/**
* Implements a settings container.
*/
class FSettingsContainer
: public ISettingsContainer
{
public:
/**
* Creates and initializes a new instance.
*
* @param InName The container's name.
*/
FSettingsContainer( const FName& InName )
: Name(InName)
{ }
public:
/**
* Adds a settings section to the specified settings category (using a settings object).
*
* If a section with the specified settings objects already exists, the existing section will be replaced.
*
* @param CategoryName The name of the category to add the section to.
* @param SectionName The name of the settings section to add.
* @param DisplayName The section's localized display name.
* @param Description The section's localized description text.
* @param SettingsObject The object that holds the section's settings.
* @param Delegates The section's optional callback delegates.
* @return The added settings section, or nullptr if the category does not exist.
*/
ISettingsSectionPtr AddSection( const FName& CategoryName, const FName& SectionName, const FText& InDisplayName, const FText& InDescription, const TWeakObjectPtr<UObject>& SettingsObject, const FSettingsSectionDelegates& Delegates )
{
TSharedPtr<FSettingsCategory> Category = Categories.FindRef(CategoryName);
if (!Category.IsValid())
{
return nullptr;
}
ISettingsSectionRef Section = Category->AddSection(SectionName, InDisplayName, InDescription, SettingsObject, Delegates);
CategoryModifiedDelegate.Broadcast(CategoryName);
return Section;
}
/**
* Adds a settings section to the specified category (using a custom settings widget).
*
* If a section with the specified settings objects already exists, the existing section will be replaced.
*
* @param CategoryName The name of the category to add the section to.
* @param SectionName The name of the settings section to add.
* @param DisplayName The section's localized display name.
* @param Description The section's localized description text.
* @param CustomWidget A custom settings widget.
* @param Delegates The section's optional callback delegates.
* @return The added settings section, or nullptr if the category does not exist.
*/
ISettingsSectionPtr AddSection( const FName& CategoryName, const FName& SectionName, const FText& InDisplayName, const FText& InDescription, const TSharedRef<SWidget>& CustomWidget, const FSettingsSectionDelegates& Delegates )
{
TSharedPtr<FSettingsCategory> Category = Categories.FindRef(CategoryName);
if (!Category.IsValid())
{
return nullptr;
}
ISettingsSectionRef Section = Category->AddSection(SectionName, InDisplayName, InDescription, CustomWidget, Delegates);
CategoryModifiedDelegate.Broadcast(CategoryName);
return Section;
}
/**
* Removes a settings section.
*
* @param CategoryName The name of the category that contains the section.
* @param SectionName The name of the section to remove.
*/
void RemoveSection( const FName& CategoryName, const FName& SectionName )
{
TSharedPtr<FSettingsCategory> Category = Categories.FindRef(CategoryName);
if (Category.IsValid())
{
ISettingsSectionPtr Section = Category->GetSection(SectionName);
if (Section.IsValid())
{
Category->RemoveSection(SectionName);
SectionRemovedDelegate.Broadcast(Section.ToSharedRef());
CategoryModifiedDelegate.Broadcast(CategoryName);
}
}
}
public:
// ISettingsContainer interface
virtual void Describe( const FText& InDisplayName, const FText& InDescription, const FName& InIconName ) override
{
Description = InDescription;
DisplayName = InDisplayName;
IconName = InIconName;
}
virtual void DescribeCategory( const FName& CategoryName, const FText& InDisplayName, const FText& InDescription, const FName& InIconName ) override
{
TSharedPtr<FSettingsCategory>& Category = Categories.FindOrAdd(CategoryName);
if (!Category.IsValid())
{
Category = MakeShareable(new FSettingsCategory(CategoryName));
}
Category->Describe(InDisplayName, InDescription, InIconName);
CategoryModifiedDelegate.Broadcast(CategoryName);
}
virtual int32 GetCategories( TArray<ISettingsCategoryPtr>& OutCategories ) const override
{
OutCategories.Empty(Categories.Num());
for (TMap<FName, TSharedPtr<FSettingsCategory> >::TConstIterator It(Categories); It; ++It)
{
OutCategories.Add(It.Value());
}
return OutCategories.Num();
}
virtual ISettingsCategoryPtr GetCategory( const FName& CategoryName ) const override
{
return Categories.FindRef(CategoryName);
}
virtual const FText& GetDescription( ) const override
{
return Description;
}
virtual const FText& GetDisplayName( ) const override
{
return DisplayName;
}
virtual const FName& GetIconName( ) const override
{
return IconName;
}
virtual const FName& GetName( ) const override
{
return Name;
}
virtual FOnSettingsContainerCategoryModified& OnCategoryModified( ) override
{
return CategoryModifiedDelegate;
}
virtual FOnSettingsContainerSectionRemoved& OnSectionRemoved( ) override
{
return SectionRemovedDelegate;
}
private:
// Holds the collection of setting categories
TMap<FName, TSharedPtr<FSettingsCategory>> Categories;
// Holds the container's description text.
FText Description;
// Holds the container's localized display name.
FText DisplayName;
// Holds the name of the container's icon.
FName IconName;
// Holds the container's name.
FName Name;
private:
// Holds a delegate that is executed when a settings category has been added or modified.
FOnSettingsContainerCategoryModified CategoryModifiedDelegate;
// Holds a delegate that is executed when a settings section has been removed.
FOnSettingsContainerSectionRemoved SectionRemovedDelegate;
};