From 02e910c4efa44b2fa408cf592ceffe8d2d3c3bba Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 25 Aug 2019 20:50:17 -0400 Subject: [PATCH] General: Use unique_ptr for UI instances Gets rid of the need for manual new and delete. --- hecl-gui/ArgumentEditor.cpp | 7 ++----- hecl-gui/ArgumentEditor.hpp | 7 +++++-- hecl-gui/MainWindow.cpp | 3 +-- hecl-gui/MainWindow.hpp | 20 ++++++++++++-------- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/hecl-gui/ArgumentEditor.cpp b/hecl-gui/ArgumentEditor.cpp index f4cb3c793..0c4deb47c 100644 --- a/hecl-gui/ArgumentEditor.cpp +++ b/hecl-gui/ArgumentEditor.cpp @@ -6,16 +6,13 @@ ArgumentEditor::ArgumentEditor(QWidget* parent) : QDialog(parent) -, m_ui(new Ui::ArgumentEditor) { +, m_ui(std::make_unique()) { m_ui->setupUi(this); m_model.setStringList(QSettings().value("urde_arguments").toStringList()); m_ui->argumentEditor->setModel(&m_model); } -ArgumentEditor::~ArgumentEditor() { - delete m_ui; - m_ui = nullptr; -} +ArgumentEditor::~ArgumentEditor() = default; void ArgumentEditor::on_addButton_clicked() { QInputDialog input(this); diff --git a/hecl-gui/ArgumentEditor.hpp b/hecl-gui/ArgumentEditor.hpp index deff4ae87..3c0eb40f4 100644 --- a/hecl-gui/ArgumentEditor.hpp +++ b/hecl-gui/ArgumentEditor.hpp @@ -1,5 +1,7 @@ #pragma once +#include + #include #include @@ -11,10 +13,11 @@ class ArgumentEditor; class ArgumentEditor : public QDialog { Q_OBJECT - Ui::ArgumentEditor* m_ui; + + std::unique_ptr m_ui; QStringListModel m_model; public: - explicit ArgumentEditor(QWidget* parent = 0); + explicit ArgumentEditor(QWidget* parent = nullptr); virtual ~ArgumentEditor(); private slots: diff --git a/hecl-gui/MainWindow.cpp b/hecl-gui/MainWindow.cpp index 2bcd49797..9bcfd7ecf 100644 --- a/hecl-gui/MainWindow.cpp +++ b/hecl-gui/MainWindow.cpp @@ -57,10 +57,10 @@ const QStringList MainWindow::skUpdateTracks = QStringList() << "stable" << "dev MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) +, m_ui(std::make_unique()) , m_fileMgr(_SYS_STR("urde")) , m_cvarManager(m_fileMgr) , m_cvarCommons(m_cvarManager) -, m_ui(new Ui::MainWindow) , m_heclProc(this) , m_dlManager(this) , m_launchMenu(m_cvarCommons, this) { @@ -109,7 +109,6 @@ MainWindow::MainWindow(QWidget* parent) MainWindow::~MainWindow() { KillProcessTree(m_heclProc); - delete m_ui; } void MainWindow::onExtract() { diff --git a/hecl-gui/MainWindow.hpp b/hecl-gui/MainWindow.hpp index 120fb3e8b..af85f1ad7 100644 --- a/hecl-gui/MainWindow.hpp +++ b/hecl-gui/MainWindow.hpp @@ -1,17 +1,21 @@ #pragma once +#include + #include #include #include -#include + +#include "Common.hpp" #include "DownloadManager.hpp" #include "LaunchMenu.hpp" -#include "Common.hpp" -#include "hecl/Runtime.hpp" -#include "hecl/CVarCommons.hpp" -class QTextEdit; -class QTextCharFormat; + +#include +#include + class QPushButton; +class QTextCharFormat; +class QTextEdit; class QuaZip; namespace Ui { @@ -21,10 +25,10 @@ class MainWindow; class MainWindow : public QMainWindow { static const QStringList skUpdateTracks; Q_OBJECT + std::unique_ptr m_ui; hecl::Runtime::FileStoreManager m_fileMgr; hecl::CVarManager m_cvarManager; hecl::CVarCommons m_cvarCommons; - Ui::MainWindow* m_ui; QTextCursor m_cursor; QString m_path; QString m_urdePath; @@ -38,7 +42,7 @@ class MainWindow : public QMainWindow { bool m_inContinueNote = false; public: - explicit MainWindow(QWidget* parent = 0); + explicit MainWindow(QWidget* parent = nullptr); ~MainWindow(); void setTextTermFormatting(const QString& text); void insertContinueNote(const QString& text);