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>
This commit is contained in:
Artur K
2021-10-29 10:59:18 +02:00
committed by GitHub
parent 37381489ee
commit a322d9e2b8
15 changed files with 169 additions and 221 deletions
+3
View File
@@ -16,9 +16,12 @@
#include <AzCore/std/containers/vector.h>
#include <AzCore/std/utils.h>
struct ICVar;
class CVarMenu
: public QMenu
{
Q_OBJECT
public:
// CVar that can be toggled on and off
struct CVarToggle
+87 -95
View File
@@ -19,10 +19,9 @@ namespace Config
CConfigGroup::~CConfigGroup()
{
for (TConfigVariables::const_iterator it = m_vars.begin();
it != m_vars.end(); ++it)
for (IConfigVar* var : m_vars)
{
delete (*it);
delete var;
}
}
@@ -31,17 +30,15 @@ namespace Config
m_vars.push_back(var);
}
uint32 CConfigGroup::GetVarCount()
AZ::u32 CConfigGroup::GetVarCount()
{
return static_cast<uint32>(m_vars.size());
return aznumeric_cast<AZ::u32>(m_vars.size());
}
IConfigVar* CConfigGroup::GetVar(const char* szName)
{
for (TConfigVariables::const_iterator it = m_vars.begin();
it != m_vars.end(); ++it)
for (IConfigVar* var : m_vars)
{
IConfigVar* var = (*it);
if (0 == _stricmp(szName, var->GetName().c_str()))
{
return var;
@@ -53,20 +50,19 @@ namespace Config
const IConfigVar* CConfigGroup::GetVar(const char* szName) const
{
for (TConfigVariables::const_iterator it = m_vars.begin();
it != m_vars.end(); ++it)
for (const IConfigVar* var : m_vars)
{
IConfigVar* var = (*it);
if (0 == _stricmp(szName, var->GetName().c_str()))
{
return var;
}
}
return nullptr;
}
IConfigVar* CConfigGroup::GetVar(uint index)
IConfigVar* CConfigGroup::GetVar(AZ::u32 index)
{
if (index < m_vars.size())
{
@@ -76,7 +72,7 @@ namespace Config
return nullptr;
}
const IConfigVar* CConfigGroup::GetVar(uint index) const
const IConfigVar* CConfigGroup::GetVar(AZ::u32 index) const
{
if (index < m_vars.size())
{
@@ -89,114 +85,110 @@ namespace Config
void CConfigGroup::SaveToXML(XmlNodeRef node)
{
// save only values that don't have default values
for (TConfigVariables::const_iterator it = m_vars.begin();
it != m_vars.end(); ++it)
for (const IConfigVar* var : m_vars)
{
IConfigVar* var = (*it);
if (!var->IsFlagSet(IConfigVar::eFlag_DoNotSave))
if (var->IsFlagSet(IConfigVar::eFlag_DoNotSave) || var->IsDefault())
{
if (!var->IsDefault())
{
const char* szName = var->GetName().c_str();
continue;
}
switch (var->GetType())
{
case IConfigVar::eType_BOOL:
{
bool currentValue = false;
var->Get(&currentValue);
node->setAttr(szName, currentValue);
break;
}
const char* szName = var->GetName().c_str();
case IConfigVar::eType_INT:
{
int currentValue = 0;
var->Get(&currentValue);
node->setAttr(szName, currentValue);
break;
}
switch (var->GetType())
{
case IConfigVar::eType_BOOL:
{
bool currentValue = false;
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_INT:
{
int 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;
}
}
}
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)
{
// save only values that don't have default values
for (TConfigVariables::const_iterator it = m_vars.begin();
it != m_vars.end(); ++it)
// load values that are save-able
for (IConfigVar* var : m_vars)
{
IConfigVar* var = (*it);
if (!var->IsFlagSet(IConfigVar::eFlag_DoNotSave))
if (var->IsFlagSet(IConfigVar::eFlag_DoNotSave))
{
const char* szName = var->GetName().c_str();
continue;
}
const char* szName = var->GetName().c_str();
switch (var->GetType())
switch (var->GetType())
{
case IConfigVar::eType_BOOL:
{
bool currentValue = false;
var->GetDefault(&currentValue);
if (node->getAttr(szName, currentValue))
{
case IConfigVar::eType_BOOL:
{
bool currentValue = false;
var->GetDefault(&currentValue);
if (node->getAttr(szName, currentValue))
{
var->Set(&currentValue);
}
break;
var->Set(&currentValue);
}
break;
}
case IConfigVar::eType_INT:
case IConfigVar::eType_INT:
{
int currentValue = 0;
var->GetDefault(&currentValue);
if (node->getAttr(szName, currentValue))
{
int currentValue = 0;
var->GetDefault(&currentValue);
if (node->getAttr(szName, currentValue))
{
var->Set(&currentValue);
}
break;
var->Set(&currentValue);
}
break;
}
case IConfigVar::eType_FLOAT:
case IConfigVar::eType_FLOAT:
{
float currentValue = 0;
var->GetDefault(&currentValue);
if (node->getAttr(szName, currentValue))
{
float currentValue = 0;
var->GetDefault(&currentValue);
if (node->getAttr(szName, currentValue))
{
var->Set(&currentValue);
}
break;
var->Set(&currentValue);
}
break;
}
case IConfigVar::eType_STRING:
case IConfigVar::eType_STRING:
{
AZStd::string currentValue;
var->GetDefault(&currentValue);
QString readValue(currentValue.c_str());
if (node->getAttr(szName, readValue))
{
AZStd::string currentValue;
var->GetDefault(&currentValue);
QString readValue(currentValue.c_str());
if (node->getAttr(szName, readValue))
{
currentValue = readValue.toUtf8().data();
var->Set(&currentValue);
}
break;
}
currentValue = readValue.toUtf8().data();
var->Set(&currentValue);
}
break;
}
}
}
}
+21 -69
View File
@@ -8,8 +8,12 @@
#pragma once
#ifndef CRYINCLUDE_EDITOR_CONFIGGROUP_H
#define CRYINCLUDE_EDITOR_CONFIGGROUP_H
#include <AzCore/base.h>
#include <AzCore/std/containers/vector.h>
#include <AzCore/std/string/string.h>
struct ICVar;
class XmlNodeRef;
namespace Config
{
@@ -32,7 +36,7 @@ namespace Config
eFlag_DoNotSave = 1 << 2,
};
IConfigVar(const char* szName, const char* szDescription, EType varType, uint8 flags)
IConfigVar(const char* szName, const char* szDescription, EType varType, AZ::u8 flags)
: m_name(szName)
, m_description(szDescription)
, m_type(varType)
@@ -42,22 +46,22 @@ namespace Config
virtual ~IConfigVar() = default;
ILINE EType GetType() const
AZ_FORCE_INLINE EType GetType() const
{
return m_type;
}
ILINE const AZStd::string& GetName() const
AZ_FORCE_INLINE const AZStd::string& GetName() const
{
return m_name;
}
ILINE const AZStd::string& GetDescription() const
AZ_FORCE_INLINE const AZStd::string& GetDescription() const
{
return m_description;
}
ILINE bool IsFlagSet(EFlags flag) const
AZ_FORCE_INLINE bool IsFlagSet(EFlags flag) const
{
return 0 != (m_flags & flag);
}
@@ -68,73 +72,28 @@ namespace Config
virtual void GetDefault(void* outPtr) const = 0;
virtual void Reset() = 0;
static EType TranslateType(const bool&) { return eType_BOOL; }
static EType TranslateType(const int&) { return eType_INT; }
static EType TranslateType(const float&) { return eType_FLOAT; }
static EType TranslateType(const AZStd::string&) { return eType_STRING; }
static constexpr EType TranslateType(const bool&) { return eType_BOOL; }
static constexpr EType TranslateType(const int&) { return eType_INT; }
static constexpr EType TranslateType(const float&) { return eType_FLOAT; }
static constexpr EType TranslateType(const AZStd::string&) { return eType_STRING; }
protected:
EType m_type;
uint8 m_flags;
AZ::u8 m_flags;
AZStd::string m_name;
AZStd::string m_description;
void* m_ptr;
ICVar* m_pCVar;
};
// Typed wrapper for config variable
template<class T>
class TConfigVar
: public IConfigVar
{
private:
T m_default;
public:
TConfigVar(const char* szName, const char* szDescription, uint8 flags, T& ptr, const T& defaultValue)
: IConfigVar(szName, szDescription, IConfigVar::TranslateType(ptr), flags)
, m_default(defaultValue)
{
m_ptr = &ptr;
// reset to default value on initializations
ptr = defaultValue;
}
virtual void Get(void* outPtr) const
{
*reinterpret_cast<T*>(outPtr) = *reinterpret_cast<const T*>(m_ptr);
}
virtual void Set(const void* ptr)
{
*reinterpret_cast<T*>(m_ptr) = *reinterpret_cast<const T*>(ptr);
}
virtual void Reset()
{
*reinterpret_cast<T*>(m_ptr) = m_default;
}
virtual void GetDefault(void* outPtr) const
{
*reinterpret_cast<T*>(outPtr) = m_default;
}
virtual bool IsDefault() const
{
return *reinterpret_cast<const T*>(m_ptr) == m_default;
}
};
// Group of configuration variables with optional mapping to CVars
class CConfigGroup
{
private:
typedef std::vector<IConfigVar*> TConfigVariables;
using TConfigVariables = AZStd::vector<IConfigVar*> ;
TConfigVariables m_vars;
typedef std::vector<ICVar*> TConsoleVariables;
using TConsoleVariables = AZStd::vector<ICVar*>;
TConsoleVariables m_consoleVars;
public:
@@ -142,20 +101,13 @@ namespace Config
virtual ~CConfigGroup();
void AddVar(IConfigVar* var);
uint32 GetVarCount();
AZ::u32 GetVarCount();
IConfigVar* GetVar(const char* szName);
IConfigVar* GetVar(uint index);
IConfigVar* GetVar(AZ::u32 index);
const IConfigVar* GetVar(const char* szName) const;
const IConfigVar* GetVar(uint index) const;
const IConfigVar* GetVar(AZ::u32 index) const;
void SaveToXML(XmlNodeRef node);
void LoadFromXML(XmlNodeRef node);
template<class T>
void AddVar(const char* szName, const char* szDescription, T& var, const T& defaultValue, uint8 flags = 0)
{
AddVar(new TConfigVar<T>(szName, szDescription, flags, var, defaultValue));
}
};
};
#endif // CRYINCLUDE_EDITOR_CONFIGGROUP_H
@@ -6,8 +6,6 @@
*
*/
#ifndef CRYINCLUDE_EDITOR_UTILS_PROPERTYMISCCTRL_H
#define CRYINCLUDE_EDITOR_UTILS_PROPERTYMISCCTRL_H
#pragma once
#if !defined(Q_MOC_RUN)
@@ -53,6 +51,7 @@ private:
class UserPopupWidgetHandler : public QObject, public AzToolsFramework::PropertyHandler < CReflectedVarUser, UserPropertyEditor>
{
Q_OBJECT
public:
AZ_CLASS_ALLOCATOR(UserPopupWidgetHandler, AZ::SystemAllocator, 0);
bool IsDefaultHandler() const override { return false; }
@@ -67,6 +66,7 @@ public:
class FloatCurveHandler : public QObject, public AzToolsFramework::PropertyHandler < CReflectedVarSpline, CSplineCtrl>
{
Q_OBJECT
public:
AZ_CLASS_ALLOCATOR(FloatCurveHandler, AZ::SystemAllocator, 0);
bool IsDefaultHandler() const override { return false; }
@@ -80,5 +80,3 @@ public:
void OnSplineChange(CSplineCtrl*);
};
#endif // CRYINCLUDE_EDITOR_UTILS_PROPERTYMISCCTRL_H
@@ -58,17 +58,9 @@ private:
void OnClicked() override
{
QString tempValue("");
QString ext("");
if (m_path.isEmpty() == false)
if (!m_path.isEmpty() && !Path::GetExt(m_path).isEmpty())
{
if (Path::GetExt(m_path) == "")
{
tempValue = "";
}
else
{
tempValue = m_path;
}
tempValue = m_path;
}
AssetSelectionModel selection;
@@ -99,6 +99,7 @@ class FileResourceSelectorWidgetHandler
: QObject
, public AzToolsFramework::PropertyHandler < CReflectedVarResource, FileResourceSelectorWidget >
{
Q_OBJECT
public:
AZ_CLASS_ALLOCATOR(FileResourceSelectorWidgetHandler, AZ::SystemAllocator, 0);
@@ -446,41 +446,54 @@ void ReflectedVarUserAdapter::SetVariable(IVariable *pVariable)
m_reflectedVar.reset(new CReflectedVarUser( pVariable->GetHumanName().toUtf8().data()));
}
void ReflectedVarUserAdapter::SyncReflectedVarToIVar(IVariable *pVariable)
void ReflectedVarUserAdapter::SyncReflectedVarToIVar(IVariable* pVariable)
{
QString value;
pVariable->Get(value);
m_reflectedVar->m_value = value.toUtf8().data();
//extract the list of custom items from the IVariable user data
IVariable::IGetCustomItems* pGetCustomItems = static_cast<IVariable::IGetCustomItems*> (pVariable->GetUserData().value<void *>());
if (pGetCustomItems != nullptr)
{
std::vector<IVariable::IGetCustomItems::SItem> items;
QString dlgTitle;
// call the user supplied callback to fill-in items and get dialog title
bool bShowIt = pGetCustomItems->GetItems(pVariable, items, dlgTitle);
if (bShowIt) // if func didn't veto, show the dialog
{
m_reflectedVar->m_enableEdit = true;
m_reflectedVar->m_useTree = pGetCustomItems->UseTree();
m_reflectedVar->m_treeSeparator = pGetCustomItems->GetTreeSeparator();
m_reflectedVar->m_dialogTitle = dlgTitle.toUtf8().data();
m_reflectedVar->m_itemNames.resize(items.size());
m_reflectedVar->m_itemDescriptions.resize(items.size());
QByteArray ba;
int i = -1;
std::generate(m_reflectedVar->m_itemNames.begin(), m_reflectedVar->m_itemNames.end(), [&items, &i, &ba]() { ++i; ba = items[i].name.toUtf8(); return ba.data(); });
i = -1;
std::generate(m_reflectedVar->m_itemDescriptions.begin(), m_reflectedVar->m_itemDescriptions.end(), [&items, &i, &ba]() { ++i; ba = items[i].desc.toUtf8(); return ba.data(); });
}
}
else
// extract the list of custom items from the IVariable user data
IVariable::IGetCustomItems* pGetCustomItems = static_cast<IVariable::IGetCustomItems*>(pVariable->GetUserData().value<void*>());
if (pGetCustomItems == nullptr)
{
m_reflectedVar->m_enableEdit = false;
return;
}
std::vector<IVariable::IGetCustomItems::SItem> items;
QString dlgTitle;
// call the user supplied callback to fill-in items and get dialog title
bool bShowIt = pGetCustomItems->GetItems(pVariable, items, dlgTitle);
if (!bShowIt) // if func vetoed it, don't show the dialog
{
return;
}
m_reflectedVar->m_enableEdit = true;
m_reflectedVar->m_useTree = pGetCustomItems->UseTree();
m_reflectedVar->m_treeSeparator = pGetCustomItems->GetTreeSeparator();
m_reflectedVar->m_dialogTitle = dlgTitle.toUtf8().data();
m_reflectedVar->m_itemNames.resize(items.size());
m_reflectedVar->m_itemDescriptions.resize(items.size());
QByteArray ba;
int i = -1;
AZStd::generate(
m_reflectedVar->m_itemNames.begin(), m_reflectedVar->m_itemNames.end(),
[&items, &i, &ba]()
{
++i;
ba = items[i].name.toUtf8();
return ba.data();
});
i = -1;
AZStd::generate(
m_reflectedVar->m_itemDescriptions.begin(), m_reflectedVar->m_itemDescriptions.end(),
[&items, &i, &ba]()
{
++i;
ba = items[i].desc.toUtf8();
return ba.data();
});
}
void ReflectedVarUserAdapter::SyncIVarToReflectedVar(IVariable *pVariable)
-2
View File
@@ -126,7 +126,6 @@ void TimelineWidget::DrawTicks(QPainter* painter)
const QPen pOldPen = painter->pen();
const QPen ltgray(QColor(110, 110, 110));
const QPen black(palette().color(QPalette::Normal, QPalette::Text));
const QPen redpen(QColor(255, 0, 255));
// Draw time ticks every tick step seconds.
@@ -598,7 +597,6 @@ void TimelineWidget::DrawSecondTicks(QPainter* painter)
{
const QPen ltgray(QColor(110, 110, 110));
const QPen black(palette().color(QPalette::Normal, QPalette::Text));
const QPen redpen(QColor(255, 0, 255));
for (int gx = m_grid.firstGridLine.x(); gx < m_grid.firstGridLine.x() + m_grid.numGridLines.x() + 1; gx++)
{
+1
View File
@@ -431,6 +431,7 @@ public:
class CCrySingleDocTemplate
: public QObject
{
Q_OBJECT
private:
explicit CCrySingleDocTemplate(const QMetaObject* pDocClass)
: QObject()
+1 -4
View File
@@ -12,8 +12,6 @@
// Notice : Refer to ViewportTitleDlg.cpp for a use case.
#ifndef CRYINCLUDE_EDITOR_CUSTOMRESOLUTIONDLG_H
#define CRYINCLUDE_EDITOR_CUSTOMRESOLUTIONDLG_H
#pragma once
#if !defined(Q_MOC_RUN)
@@ -28,6 +26,7 @@ namespace Ui
class CCustomResolutionDlg
: public QDialog
{
Q_OBJECT
public:
CCustomResolutionDlg(int w, int h, QWidget* pParent = nullptr);
~CCustomResolutionDlg();
@@ -42,5 +41,3 @@ protected:
QScopedPointer<Ui::CustomResolutionDlg> m_ui;
};
#endif // CRYINCLUDE_EDITOR_CUSTOMRESOLUTIONDLG_H
+3 -3
View File
@@ -211,9 +211,9 @@ public:
void Reset(QAction& action)
{
emit beginResetModel();
beginResetModel();
m_action = &action;
emit endResetModel();
endResetModel();
}
private:
@@ -266,7 +266,7 @@ QStringList CustomizeKeyboardDialog::BuildModels(QWidget* parent)
categories.append(category);
QMenu* menu = menuAction->menu();
m_menuActions[category] = GetAllActionsForMenu(menu, QStringLiteral(""));
m_menuActions[category] = GetAllActionsForMenu(menu, QString());
}
return categories;
+2 -2
View File
@@ -25,9 +25,9 @@ namespace SandboxEditor
connect(m_ui->okButton, &QPushButton::clicked, this, &ErrorDialog::OnOK);
connect(
m_ui->messages,
SIGNAL(itemSelectionChanged()),
&QTreeWidget::itemSelectionChanged,
this,
SLOT(MessageSelectionChanged()));
&ErrorDialog::MessageSelectionChanged);
}
ErrorDialog::~ErrorDialog()
@@ -240,7 +240,7 @@ QJsonObject KeyboardCustomizationSettings::ExportGroup()
void KeyboardCustomizationSettings::ImportFromFile(QWidget* parent)
{
QString fileName = QFileDialog::getOpenFileName(parent, QObject::tr("Export Keyboard Shortcuts"), QStringLiteral(""), QObject::tr("Keyboard Settings (*.keys)"));
QString fileName = QFileDialog::getOpenFileName(parent, QObject::tr("Export Keyboard Shortcuts"), QString(), QObject::tr("Keyboard Settings (*.keys)"));
if (fileName.isEmpty())
{
return;
+1 -1
View File
@@ -419,7 +419,7 @@ void MemoryStatusItem::updateStatus()
GeneralStatusItem::GeneralStatusItem(QString name, MainStatusBar* parent)
: StatusBarItem(name, parent)
{
connect(parent, SIGNAL(messageChanged(QString)), this, SLOT(update()));
connect(parent, &MainStatusBar::messageChanged, this, [this](const QString&) { update(); });
}
QString GeneralStatusItem::CurrentText() const
+4 -3
View File
@@ -100,9 +100,10 @@ CNewLevelDialog::CNewLevelDialog(QWidget* pParent /*=nullptr*/)
m_level = "";
// First of all, keyboard focus is related to widget tab order, and the default tab order is based on the order in which
// widgets are constructed. Therefore, creating more widgets changes the keyboard focus. That is why setFocus() is called last.
// Secondly, using singleShot() allows setFocus() slot of the QLineEdit instance to be invoked right after the event system
// is ready to do so. Therefore, it is better to use singleShot() than directly call setFocus().
QTimer::singleShot(0, ui->LEVEL, SLOT(OnStartup()));
// in OnStartup()
// Secondly, using singleShot() allows OnStartup() slot of the QLineEdit instance to be invoked right after the event system
// is ready to do so. Therefore, it is better to use singleShot() than directly call OnStartup().
QTimer::singleShot(0, this, &CNewLevelDialog::OnStartup);
ReloadLevelFolder();
}