From d70c9faea034bad3ec919b2fb5982b7341b0f2d7 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 28 Jun 2020 05:57:22 -0400 Subject: [PATCH] CStringEditor: Make use of in-class initializers where applicable --- src/Editor/StringEditor/CStringEditor.cpp | 26 ++++++++--------------- src/Editor/StringEditor/CStringEditor.h | 26 ++++++++++++----------- 2 files changed, 23 insertions(+), 29 deletions(-) diff --git a/src/Editor/StringEditor/CStringEditor.cpp b/src/Editor/StringEditor/CStringEditor.cpp index 558afb14..6334ead2 100644 --- a/src/Editor/StringEditor/CStringEditor.cpp +++ b/src/Editor/StringEditor/CStringEditor.cpp @@ -9,7 +9,7 @@ #include /** Settings strings */ -const char* gkpLanguageSetting = "StringEditor/EditLanguage"; +constexpr char gkpLanguageSetting[] = "StringEditor/EditLanguage"; /** Command classes */ class CSetStringIndexCommand : public IUndoCommand @@ -21,9 +21,9 @@ public: : IUndoCommand("Select String"), mpEditor(pEditor), mOldIndex(OldIndex), mNewIndex(NewIndex) {} - virtual void undo() override { mpEditor->SetActiveString(mOldIndex); } - virtual void redo() override { mpEditor->SetActiveString(mNewIndex); } - virtual bool AffectsCleanState() const override { return false; } + void undo() override { mpEditor->SetActiveString(mOldIndex); } + void redo() override { mpEditor->SetActiveString(mNewIndex); } + bool AffectsCleanState() const override { return false; } }; class CSetLanguageCommand : public IUndoCommand @@ -35,30 +35,22 @@ public: : IUndoCommand("Select Language"), mpEditor(pEditor), mOldLanguage(OldLanguage), mNewLanguage(NewLanguage) {} - virtual void undo() override { mpEditor->SetActiveLanguage(mOldLanguage); } - virtual void redo() override { mpEditor->SetActiveLanguage(mNewLanguage); } - virtual bool AffectsCleanState() const override { return false; } + void undo() override { mpEditor->SetActiveLanguage(mOldLanguage); } + void redo() override { mpEditor->SetActiveLanguage(mNewLanguage); } + bool AffectsCleanState() const override { return false; } }; /** Constructor */ CStringEditor::CStringEditor(CStringTable* pStringTable, QWidget* pParent) : IEditor(pParent) - , mpUI(new Ui::CStringEditor) + , mpUI(std::make_unique()) , mpStringTable(pStringTable) - , mCurrentLanguage(ELanguage::English) - , mCurrentStringIndex(-1) - , mCurrentStringCount(0) - , mIsEditingStringName(false) - , mIsEditingStringData(false) { InitUI(); // LoadSettings(); // Disabled for now } -CStringEditor::~CStringEditor() -{ - delete mpUI; -} +CStringEditor::~CStringEditor() = default; bool CStringEditor::Save() { diff --git a/src/Editor/StringEditor/CStringEditor.h b/src/Editor/StringEditor/CStringEditor.h index bf89c097..6b68764c 100644 --- a/src/Editor/StringEditor/CStringEditor.h +++ b/src/Editor/StringEditor/CStringEditor.h @@ -8,6 +8,8 @@ #include +#include + namespace Ui { class CStringEditor; } @@ -18,33 +20,33 @@ class CStringEditor : public IEditor Q_OBJECT /** Qt UI */ - Ui::CStringEditor* mpUI; + std::unique_ptr mpUI; /** String table asset being edited */ TResPtr mpStringTable; /** Language being edited */ - ELanguage mCurrentLanguage; + ELanguage mCurrentLanguage{ELanguage::English}; /** Index of the string being edited */ - uint mCurrentStringIndex; + uint32 mCurrentStringIndex = UINT32_MAX; /** Current string count */ - uint mCurrentStringCount; + uint32 mCurrentStringCount = 0; /** Model for the string list view */ - CStringListModel* mpListModel; + CStringListModel* mpListModel = nullptr; /** Editor state flags */ - bool mIsEditingStringName; - bool mIsEditingStringData; + bool mIsEditingStringName = false; + bool mIsEditingStringData = false; public: - explicit CStringEditor(CStringTable* pStringTable, QWidget* pParent = 0); - ~CStringEditor(); + explicit CStringEditor(CStringTable* pStringTable, QWidget* pParent = nullptr); + ~CStringEditor() override; - virtual bool Save() override; - virtual bool eventFilter(QObject* pWatched, QEvent* pEvent) override; + bool Save() override; + bool eventFilter(QObject* pWatched, QEvent* pEvent) override; void InitUI(); void UpdateStatusBar(); @@ -55,7 +57,7 @@ public: void SaveSettings(); // Accessors - inline CStringTable* StringTable() const { return mpStringTable; } + CStringTable* StringTable() const { return mpStringTable; } public slots: void UpdateUI();