1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

fix(settings): Delete dynamically allocated members on destruction

Fixes #4670
This commit is contained in:
anthony.bilinski 2017-09-21 11:25:27 -07:00
parent b7921ef29a
commit 94cb6ce1c5
2 changed files with 23 additions and 19 deletions

View File

@ -19,10 +19,6 @@
#include "settingswidget.h" #include "settingswidget.h"
#include <QLabel>
#include <QTabWidget>
#include <QWindow>
#include "src/video/camerasource.h" #include "src/video/camerasource.h"
#include "src/widget/contentlayout.h" #include "src/widget/contentlayout.h"
#include "src/widget/form/settings/aboutform.h" #include "src/widget/form/settings/aboutform.h"
@ -34,6 +30,12 @@
#include "src/widget/translator.h" #include "src/widget/translator.h"
#include "src/widget/widget.h" #include "src/widget/widget.h"
#include <QLabel>
#include <QTabWidget>
#include <QWindow>
#include <memory>
SettingsWidget::SettingsWidget(QWidget* parent) SettingsWidget::SettingsWidget(QWidget* parent)
: QWidget(parent, Qt::Window) : QWidget(parent, Qt::Window)
{ {
@ -41,22 +43,22 @@ SettingsWidget::SettingsWidget(QWidget* parent)
QVBoxLayout* bodyLayout = new QVBoxLayout(); QVBoxLayout* bodyLayout = new QVBoxLayout();
settingsWidgets = new QTabWidget(this); settingsWidgets = std::unique_ptr<QTabWidget>(new QTabWidget(this));
settingsWidgets->setTabPosition(QTabWidget::North); settingsWidgets->setTabPosition(QTabWidget::North);
bodyLayout->addWidget(settingsWidgets); bodyLayout->addWidget(settingsWidgets.get());
GeneralForm* gfrm = new GeneralForm(this); std::unique_ptr<GeneralForm> gfrm(new GeneralForm(this));
UserInterfaceForm* uifrm = new UserInterfaceForm(this); std::unique_ptr<UserInterfaceForm> uifrm(new UserInterfaceForm(this));
PrivacyForm* pfrm = new PrivacyForm(); std::unique_ptr<PrivacyForm> pfrm(new PrivacyForm());
AVForm* avfrm = new AVForm(); std::unique_ptr<AVForm> avfrm(new AVForm());
AdvancedForm* expfrm = new AdvancedForm(); std::unique_ptr<AdvancedForm> expfrm(new AdvancedForm());
AboutForm* abtfrm = new AboutForm(); std::unique_ptr<AboutForm> abtfrm(new AboutForm());
cfgForms = {{gfrm, uifrm, pfrm, avfrm, expfrm, abtfrm}}; cfgForms = {{std::move(gfrm), std::move(uifrm), std::move(pfrm), std::move(avfrm), std::move(expfrm), std::move(abtfrm)}};
for (GenericForm* cfgForm : cfgForms) for (auto& cfgForm : cfgForms)
settingsWidgets->addTab(cfgForm, cfgForm->getFormIcon(), cfgForm->getFormName()); settingsWidgets->addTab(cfgForm.get(), cfgForm->getFormIcon(), cfgForm->getFormName());
connect(settingsWidgets, &QTabWidget::currentChanged, this, &SettingsWidget::onTabChanged); connect(settingsWidgets.get(), &QTabWidget::currentChanged, this, &SettingsWidget::onTabChanged);
Translator::registerHandler(std::bind(&SettingsWidget::retranslateUi, this), this); Translator::registerHandler(std::bind(&SettingsWidget::retranslateUi, this), this);
} }
@ -88,7 +90,7 @@ bool SettingsWidget::isShown() const
void SettingsWidget::show(ContentLayout* contentLayout) void SettingsWidget::show(ContentLayout* contentLayout)
{ {
contentLayout->mainContent->layout()->addWidget(settingsWidgets); contentLayout->mainContent->layout()->addWidget(settingsWidgets.get());
settingsWidgets->show(); settingsWidgets->show();
onTabChanged(settingsWidgets->currentIndex()); onTabChanged(settingsWidgets->currentIndex());
} }

View File

@ -23,7 +23,9 @@
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QPushButton> #include <QPushButton>
#include <QStyleFactory> #include <QStyleFactory>
#include <array> #include <array>
#include <memory>
class Camera; class Camera;
class GenericForm; class GenericForm;
@ -54,8 +56,8 @@ private:
void retranslateUi(); void retranslateUi();
private: private:
QTabWidget* settingsWidgets; std::unique_ptr<QTabWidget> settingsWidgets;
std::array<GenericForm*, 6> cfgForms; std::array<std::unique_ptr<GenericForm>, 6> cfgForms;
int currentIndex; int currentIndex;
}; };