Qt: Cleanup deletion of CopyFromProfileMenu

Set the push button as parent to the profile list menu so it will
be deleted when that parent is destroyed.

Change-Id: Ide4a234e039a3e27d9ee4732a3800906c80be173
Reviewed-on: https://code.wireshark.org/review/31446
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
This commit is contained in:
Stig Bjørlykke 2019-01-08 17:48:21 +01:00 committed by Anders Broman
parent 6739523a02
commit d50bd39b85
10 changed files with 19 additions and 35 deletions

View File

@ -42,7 +42,6 @@
ColoringRulesDialog::ColoringRulesDialog(QWidget *parent, QString add_filter) : ColoringRulesDialog::ColoringRulesDialog(QWidget *parent, QString add_filter) :
GeometryStateDialog(parent), GeometryStateDialog(parent),
ui(new Ui::ColoringRulesDialog), ui(new Ui::ColoringRulesDialog),
copy_from_menu_(NULL),
colorRuleModel_(palette().color(QPalette::Text), palette().color(QPalette::Base), this), colorRuleModel_(palette().color(QPalette::Text), palette().color(QPalette::Base), this),
colorRuleDelegate_(this) colorRuleDelegate_(this)
{ {
@ -85,11 +84,11 @@ ColoringRulesDialog::ColoringRulesDialog(QWidget *parent, QString add_filter) :
export_button_->setToolTip(tr("Save filters in a file.")); export_button_->setToolTip(tr("Save filters in a file."));
QPushButton *copy_button = ui->buttonBox->addButton(tr("Copy from"), QDialogButtonBox::ActionRole); QPushButton *copy_button = ui->buttonBox->addButton(tr("Copy from"), QDialogButtonBox::ActionRole);
copy_from_menu_ = new CopyFromProfileMenu(COLORFILTERS_FILE_NAME); CopyFromProfileMenu *copy_from_menu = new CopyFromProfileMenu(COLORFILTERS_FILE_NAME, copy_button);
copy_button->setMenu(copy_from_menu_); copy_button->setMenu(copy_from_menu);
copy_button->setToolTip(tr("Copy coloring rules from another profile.")); copy_button->setToolTip(tr("Copy coloring rules from another profile."));
copy_button->setEnabled(copy_from_menu_->haveProfiles()); copy_button->setEnabled(copy_from_menu->haveProfiles());
connect(copy_from_menu_, SIGNAL(triggered(QAction *)), this, SLOT(copyFromProfile(QAction *))); connect(copy_from_menu, SIGNAL(triggered(QAction *)), this, SLOT(copyFromProfile(QAction *)));
QString abs_path = gchar_free_to_qstring(get_persconffile_path(COLORFILTERS_FILE_NAME, TRUE)); QString abs_path = gchar_free_to_qstring(get_persconffile_path(COLORFILTERS_FILE_NAME, TRUE));
if (file_exists(abs_path.toUtf8().constData())) { if (file_exists(abs_path.toUtf8().constData())) {
@ -118,7 +117,6 @@ ColoringRulesDialog::ColoringRulesDialog(QWidget *parent, QString add_filter) :
ColoringRulesDialog::~ColoringRulesDialog() ColoringRulesDialog::~ColoringRulesDialog()
{ {
delete copy_from_menu_;
delete ui; delete ui;
} }

View File

@ -19,7 +19,6 @@
#include <QMap> #include <QMap>
class QAbstractButton; class QAbstractButton;
class CopyFromProfileMenu;
namespace Ui { namespace Ui {
class ColoringRulesDialog; class ColoringRulesDialog;
@ -60,7 +59,6 @@ private:
Ui::ColoringRulesDialog *ui; Ui::ColoringRulesDialog *ui;
QPushButton *import_button_; QPushButton *import_button_;
QPushButton *export_button_; QPushButton *export_button_;
CopyFromProfileMenu *copy_from_menu_;
ColoringRulesModel colorRuleModel_; ColoringRulesModel colorRuleModel_;
ColoringRulesDelegate colorRuleDelegate_; ColoringRulesDelegate colorRuleDelegate_;

View File

@ -289,7 +289,6 @@ static void io_graph_free_cb(void* p) {
IOGraphDialog::IOGraphDialog(QWidget &parent, CaptureFile &cf) : IOGraphDialog::IOGraphDialog(QWidget &parent, CaptureFile &cf) :
WiresharkDialog(parent, cf), WiresharkDialog(parent, cf),
ui(new Ui::IOGraphDialog), ui(new Ui::IOGraphDialog),
copy_from_menu_(NULL),
uat_model_(NULL), uat_model_(NULL),
uat_delegate_(NULL), uat_delegate_(NULL),
base_graph_(NULL), base_graph_(NULL),
@ -316,11 +315,11 @@ IOGraphDialog::IOGraphDialog(QWidget &parent, CaptureFile &cf) :
connect (copy_bt, SIGNAL(clicked()), this, SLOT(copyAsCsvClicked())); connect (copy_bt, SIGNAL(clicked()), this, SLOT(copyAsCsvClicked()));
QPushButton *copy_from_bt = ui->buttonBox->addButton(tr("Copy from"), QDialogButtonBox::ActionRole); QPushButton *copy_from_bt = ui->buttonBox->addButton(tr("Copy from"), QDialogButtonBox::ActionRole);
copy_from_menu_ = new CopyFromProfileMenu("io_graphs"); CopyFromProfileMenu *copy_from_menu = new CopyFromProfileMenu("io_graphs", copy_from_bt);
copy_from_bt->setMenu(copy_from_menu_); copy_from_bt->setMenu(copy_from_menu);
copy_from_bt->setToolTip(tr("Copy graphs from another profile.")); copy_from_bt->setToolTip(tr("Copy graphs from another profile."));
copy_from_bt->setEnabled(copy_from_menu_->haveProfiles()); copy_from_bt->setEnabled(copy_from_menu->haveProfiles());
connect(copy_from_menu_, SIGNAL(triggered(QAction *)), this, SLOT(copyFromProfile(QAction *))); connect(copy_from_menu, SIGNAL(triggered(QAction *)), this, SLOT(copyFromProfile(QAction *)));
QPushButton *close_bt = ui->buttonBox->button(QDialogButtonBox::Close); QPushButton *close_bt = ui->buttonBox->button(QDialogButtonBox::Close);
if (close_bt) { if (close_bt) {
@ -414,7 +413,6 @@ IOGraphDialog::~IOGraphDialog()
foreach(IOGraph* iog, ioGraphs_) { foreach(IOGraph* iog, ioGraphs_) {
delete iog; delete iog;
} }
delete copy_from_menu_;
delete ui; delete ui;
ui = NULL; ui = NULL;
} }

View File

@ -34,7 +34,6 @@ class QCPBars;
class QCPGraph; class QCPGraph;
class QCPItemTracer; class QCPItemTracer;
class QCustomPlot; class QCustomPlot;
class CopyFromProfileMenu;
// GTK+ sets this to 100000 (NUM_IO_ITEMS) // GTK+ sets this to 100000 (NUM_IO_ITEMS)
const int max_io_items_ = 250000; const int max_io_items_ = 250000;
@ -159,7 +158,6 @@ signals:
private: private:
Ui::IOGraphDialog *ui; Ui::IOGraphDialog *ui;
CopyFromProfileMenu *copy_from_menu_;
//Model and delegate were chosen over UatFrame because add/remove/copy //Model and delegate were chosen over UatFrame because add/remove/copy
//buttons would need realignment (UatFrame has its own) //buttons would need realignment (UatFrame has its own)

View File

@ -32,7 +32,6 @@ UatDialog::UatDialog(QWidget *parent, epan_uat *uat) :
ui(new Ui::UatDialog), ui(new Ui::UatDialog),
uat_model_(NULL), uat_model_(NULL),
uat_delegate_(NULL), uat_delegate_(NULL),
copy_from_menu_(NULL),
uat_(uat) uat_(uat)
{ {
ui->setupUi(this); ui->setupUi(this);
@ -77,7 +76,6 @@ UatDialog::~UatDialog()
delete ui; delete ui;
delete uat_delegate_; delete uat_delegate_;
delete uat_model_; delete uat_model_;
delete copy_from_menu_;
} }
void UatDialog::setUat(epan_uat *uat) void UatDialog::setUat(epan_uat *uat)
@ -97,11 +95,11 @@ void UatDialog::setUat(epan_uat *uat)
if (uat->from_profile) { if (uat->from_profile) {
QPushButton *copy_button = ui->buttonBox->addButton(tr("Copy from"), QDialogButtonBox::ActionRole); QPushButton *copy_button = ui->buttonBox->addButton(tr("Copy from"), QDialogButtonBox::ActionRole);
copy_from_menu_ = new CopyFromProfileMenu(uat->filename); CopyFromProfileMenu *copy_from_menu = new CopyFromProfileMenu(uat->filename, copy_button);
copy_button->setMenu(copy_from_menu_); copy_button->setMenu(copy_from_menu);
copy_button->setToolTip(tr("Copy entries from another profile.")); copy_button->setToolTip(tr("Copy entries from another profile."));
copy_button->setEnabled(copy_from_menu_->haveProfiles()); copy_button->setEnabled(copy_from_menu->haveProfiles());
connect(copy_from_menu_, SIGNAL(triggered(QAction *)), this, SLOT(copyFromProfile(QAction *))); connect(copy_from_menu, SIGNAL(triggered(QAction *)), this, SLOT(copyFromProfile(QAction *)));
} }
QString abs_path = gchar_free_to_qstring(uat_get_actual_filename(uat_, FALSE)); QString abs_path = gchar_free_to_qstring(uat_get_actual_filename(uat_, FALSE));

View File

@ -20,7 +20,6 @@
class QComboBox; class QComboBox;
class QPushButton; class QPushButton;
class CopyFromProfileMenu;
struct epan_uat; struct epan_uat;
@ -60,7 +59,6 @@ private:
UatDelegate *uat_delegate_; UatDelegate *uat_delegate_;
QPushButton *ok_button_; QPushButton *ok_button_;
QPushButton *help_button_; QPushButton *help_button_;
CopyFromProfileMenu *copy_from_menu_;
struct epan_uat *uat_; struct epan_uat *uat_;
void checkForErrorHint(const QModelIndex &current, const QModelIndex &previous); void checkForErrorHint(const QModelIndex &current, const QModelIndex &previous);

View File

@ -34,7 +34,6 @@ UatFrame::UatFrame(QWidget *parent) :
ui(new Ui::UatFrame), ui(new Ui::UatFrame),
uat_model_(NULL), uat_model_(NULL),
uat_delegate_(NULL), uat_delegate_(NULL),
copy_from_menu_(NULL),
uat_(NULL) uat_(NULL)
{ {
ui->setupUi(this); ui->setupUi(this);
@ -68,7 +67,6 @@ UatFrame::~UatFrame()
delete ui; delete ui;
delete uat_delegate_; delete uat_delegate_;
delete uat_model_; delete uat_model_;
delete copy_from_menu_;
} }
void UatFrame::setUat(epan_uat *uat) void UatFrame::setUat(epan_uat *uat)
@ -86,10 +84,10 @@ void UatFrame::setUat(epan_uat *uat)
} }
if (uat->from_profile) { if (uat->from_profile) {
copy_from_menu_ = new CopyFromProfileMenu(uat_->filename); CopyFromProfileMenu *copy_from_menu = new CopyFromProfileMenu(uat_->filename, ui->copyFromProfileButton);
ui->copyFromProfileButton->setMenu(copy_from_menu_); ui->copyFromProfileButton->setMenu(copy_from_menu);
ui->copyFromProfileButton->setEnabled(copy_from_menu_->haveProfiles()); ui->copyFromProfileButton->setEnabled(copy_from_menu->haveProfiles());
connect(copy_from_menu_, SIGNAL(triggered(QAction *)), this, SLOT(copyFromProfile(QAction *))); connect(copy_from_menu, SIGNAL(triggered(QAction *)), this, SLOT(copyFromProfile(QAction *)));
} }
QString abs_path = gchar_free_to_qstring(uat_get_actual_filename(uat_, FALSE)); QString abs_path = gchar_free_to_qstring(uat_get_actual_filename(uat_, FALSE));

View File

@ -16,8 +16,6 @@
#include <ui/qt/models/uat_model.h> #include <ui/qt/models/uat_model.h>
#include <ui/qt/models/uat_delegate.h> #include <ui/qt/models/uat_delegate.h>
class CopyFromProfileMenu;
namespace Ui { namespace Ui {
class UatFrame; class UatFrame;
} }
@ -43,7 +41,6 @@ private:
UatModel *uat_model_; UatModel *uat_model_;
UatDelegate *uat_delegate_; UatDelegate *uat_delegate_;
CopyFromProfileMenu *copy_from_menu_;
struct epan_uat *uat_; struct epan_uat *uat_;
void checkForErrorHint(const QModelIndex &current, const QModelIndex &previous); void checkForErrorHint(const QModelIndex &current, const QModelIndex &previous);

View File

@ -11,7 +11,8 @@
#include <ui/profile.h> #include <ui/profile.h>
#include <wsutil/filesystem.h> #include <wsutil/filesystem.h>
CopyFromProfileMenu::CopyFromProfileMenu(QString filename) : CopyFromProfileMenu::CopyFromProfileMenu(QString filename, QWidget *parent) :
QMenu(parent),
filename_(filename), filename_(filename),
have_profiles_(false) have_profiles_(false)
{ {

View File

@ -20,7 +20,7 @@ class CopyFromProfileMenu : public QMenu
Q_OBJECT Q_OBJECT
public: public:
explicit CopyFromProfileMenu(QString filename); explicit CopyFromProfileMenu(QString filename, QWidget *parent = 0);
~CopyFromProfileMenu() { } ~CopyFromProfileMenu() { }
bool haveProfiles(); bool haveProfiles();