Files
o3de/Code/Editor/ConfigGroup.cpp
T
Artur K a322d9e2b8 Small Code/Editor cleanup pass (#4909)
* Clean-up in ConfigGroup

Removed unused templated AddVar and related code.
Replaced legacy types with `AZ::` ones.
Cleaned up cpp file.

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* Add a few missing Q_OBJECT macros, remove some unused variables.

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* Apply some of clazy suggestions + simplifications

* removed `emit` from non-signal function calls.
* replaced `QStringLiteral("")` with a constexpr friendly
`QLatin1String()`

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* Fix a CNewLevelDialog focus bug

Fixed an incorrect QTimer::singleShot invocation.

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* match lambda to `messageChanged` signature

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* vs compilation fix + applied review

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* apply reviewer recommendation

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>
2021-10-29 09:59:18 +01:00

196 lines
4.7 KiB
C++

/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#include "EditorDefs.h"
#include "ConfigGroup.h"
namespace Config
{
CConfigGroup::CConfigGroup()
{
}
CConfigGroup::~CConfigGroup()
{
for (IConfigVar* var : m_vars)
{
delete var;
}
}
void CConfigGroup::AddVar(IConfigVar* var)
{
m_vars.push_back(var);
}
AZ::u32 CConfigGroup::GetVarCount()
{
return aznumeric_cast<AZ::u32>(m_vars.size());
}
IConfigVar* CConfigGroup::GetVar(const char* szName)
{
for (IConfigVar* var : m_vars)
{
if (0 == _stricmp(szName, var->GetName().c_str()))
{
return var;
}
}
return nullptr;
}
const IConfigVar* CConfigGroup::GetVar(const char* szName) const
{
for (const IConfigVar* var : m_vars)
{
if (0 == _stricmp(szName, var->GetName().c_str()))
{
return var;
}
}
return nullptr;
}
IConfigVar* CConfigGroup::GetVar(AZ::u32 index)
{
if (index < m_vars.size())
{
return m_vars[index];
}
return nullptr;
}
const IConfigVar* CConfigGroup::GetVar(AZ::u32 index) const
{
if (index < m_vars.size())
{
return m_vars[index];
}
return nullptr;
}
void CConfigGroup::SaveToXML(XmlNodeRef node)
{
// save only values that don't have default values
for (const IConfigVar* var : m_vars)
{
if (var->IsFlagSet(IConfigVar::eFlag_DoNotSave) || var->IsDefault())
{
continue;
}
const char* szName = var->GetName().c_str();
switch (var->GetType())
{
case IConfigVar::eType_BOOL:
{
bool currentValue = false;
var->Get(&currentValue);
node->setAttr(szName, currentValue);
break;
}
case IConfigVar::eType_INT:
{
int currentValue = 0;
var->Get(&currentValue);
node->setAttr(szName, currentValue);
break;
}
case IConfigVar::eType_FLOAT:
{
float currentValue = 0;
var->Get(&currentValue);
node->setAttr(szName, currentValue);
break;
}
case IConfigVar::eType_STRING:
{
AZStd::string currentValue;
var->Get(&currentValue);
node->setAttr(szName, currentValue.c_str());
break;
}
}
}
}
void CConfigGroup::LoadFromXML(XmlNodeRef node)
{
// load values that are save-able
for (IConfigVar* var : m_vars)
{
if (var->IsFlagSet(IConfigVar::eFlag_DoNotSave))
{
continue;
}
const char* szName = var->GetName().c_str();
switch (var->GetType())
{
case IConfigVar::eType_BOOL:
{
bool currentValue = false;
var->GetDefault(&currentValue);
if (node->getAttr(szName, currentValue))
{
var->Set(&currentValue);
}
break;
}
case IConfigVar::eType_INT:
{
int currentValue = 0;
var->GetDefault(&currentValue);
if (node->getAttr(szName, currentValue))
{
var->Set(&currentValue);
}
break;
}
case IConfigVar::eType_FLOAT:
{
float currentValue = 0;
var->GetDefault(&currentValue);
if (node->getAttr(szName, currentValue))
{
var->Set(&currentValue);
}
break;
}
case IConfigVar::eType_STRING:
{
AZStd::string currentValue;
var->GetDefault(&currentValue);
QString readValue(currentValue.c_str());
if (node->getAttr(szName, readValue))
{
currentValue = readValue.toUtf8().data();
var->Set(&currentValue);
}
break;
}
}
}
}
}