From 8d6df4207982474069f3aca6ffa9b02f03712c73 Mon Sep 17 00:00:00 2001 From: Raul Radu <raul.radu@mail.polimi.it> Date: Wed, 7 Feb 2024 22:45:34 +0100 Subject: [PATCH] [Modules] CommandPad using smart pointers --- src/shared/Modules/CommandPad/CommandPad.cpp | 13 ++++--------- src/shared/Modules/CommandPad/CommandPad.h | 4 ++-- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/shared/Modules/CommandPad/CommandPad.cpp b/src/shared/Modules/CommandPad/CommandPad.cpp index 85e8d638..78e95049 100644 --- a/src/shared/Modules/CommandPad/CommandPad.cpp +++ b/src/shared/Modules/CommandPad/CommandPad.cpp @@ -24,12 +24,7 @@ CommandPad::CommandPad() : Module(ModuleId::COMMAND_PAD) { setupUi(); } -CommandPad::~CommandPad() -{ - delete messagesListComboBox; - for (auto key : formElements.keys()) - delete formElements[key]; -} +CommandPad::~CommandPad() {} XmlObject CommandPad::toXmlObject() { @@ -61,11 +56,11 @@ void CommandPad::setupUi() QVBoxLayout *outerLayout = new QVBoxLayout; outerLayout->addStretch(); - messagesListComboBox = new QComboBox; + messagesListComboBox = std::make_unique<QComboBox>(); messagesListComboBox->setSizePolicy( QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed)); messagesListComboBox->addItems(MessagesList::messagesList); - outerLayout->addWidget(messagesListComboBox); + outerLayout->addWidget(messagesListComboBox.get()); QGridLayout *formGridLayout = new QGridLayout; outerLayout->addLayout(formGridLayout); @@ -81,7 +76,7 @@ void CommandPad::setupUi() currentMessage = "PING_TC"; messagesListComboBox->setCurrentText(currentMessage); - connect(messagesListComboBox, &QComboBox::currentTextChanged, this, + connect(messagesListComboBox.get(), &QComboBox::currentTextChanged, this, [=](QString key) { if (formElements.contains(key)) diff --git a/src/shared/Modules/CommandPad/CommandPad.h b/src/shared/Modules/CommandPad/CommandPad.h index ec9e2450..e1f03a83 100644 --- a/src/shared/Modules/CommandPad/CommandPad.h +++ b/src/shared/Modules/CommandPad/CommandPad.h @@ -38,6 +38,6 @@ private: void setupUi(); QString currentMessage; - QComboBox* messagesListComboBox; - QMap<QString, MessageFormElement*> formElements; + std::unique_ptr<QComboBox> messagesListComboBox; + QMap<QString, std::unique_ptr<MessageFormElement>> formElements; }; -- GitLab