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

View File

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

View File

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

View File

@ -34,7 +34,6 @@ class QCPBars;
class QCPGraph;
class QCPItemTracer;
class QCustomPlot;
class CopyFromProfileMenu;
// GTK+ sets this to 100000 (NUM_IO_ITEMS)
const int max_io_items_ = 250000;
@ -159,7 +158,6 @@ signals:
private:
Ui::IOGraphDialog *ui;
CopyFromProfileMenu *copy_from_menu_;
//Model and delegate were chosen over UatFrame because add/remove/copy
//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),
uat_model_(NULL),
uat_delegate_(NULL),
copy_from_menu_(NULL),
uat_(uat)
{
ui->setupUi(this);
@ -77,7 +76,6 @@ UatDialog::~UatDialog()
delete ui;
delete uat_delegate_;
delete uat_model_;
delete copy_from_menu_;
}
void UatDialog::setUat(epan_uat *uat)
@ -97,11 +95,11 @@ void UatDialog::setUat(epan_uat *uat)
if (uat->from_profile) {
QPushButton *copy_button = ui->buttonBox->addButton(tr("Copy from"), QDialogButtonBox::ActionRole);
copy_from_menu_ = new CopyFromProfileMenu(uat->filename);
copy_button->setMenu(copy_from_menu_);
CopyFromProfileMenu *copy_from_menu = new CopyFromProfileMenu(uat->filename, copy_button);
copy_button->setMenu(copy_from_menu);
copy_button->setToolTip(tr("Copy entries from another profile."));
copy_button->setEnabled(copy_from_menu_->haveProfiles());
connect(copy_from_menu_, SIGNAL(triggered(QAction *)), this, SLOT(copyFromProfile(QAction *)));
copy_button->setEnabled(copy_from_menu->haveProfiles());
connect(copy_from_menu, SIGNAL(triggered(QAction *)), this, SLOT(copyFromProfile(QAction *)));
}
QString abs_path = gchar_free_to_qstring(uat_get_actual_filename(uat_, FALSE));

View File

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

View File

@ -34,7 +34,6 @@ UatFrame::UatFrame(QWidget *parent) :
ui(new Ui::UatFrame),
uat_model_(NULL),
uat_delegate_(NULL),
copy_from_menu_(NULL),
uat_(NULL)
{
ui->setupUi(this);
@ -68,7 +67,6 @@ UatFrame::~UatFrame()
delete ui;
delete uat_delegate_;
delete uat_model_;
delete copy_from_menu_;
}
void UatFrame::setUat(epan_uat *uat)
@ -86,10 +84,10 @@ void UatFrame::setUat(epan_uat *uat)
}
if (uat->from_profile) {
copy_from_menu_ = new CopyFromProfileMenu(uat_->filename);
ui->copyFromProfileButton->setMenu(copy_from_menu_);
ui->copyFromProfileButton->setEnabled(copy_from_menu_->haveProfiles());
connect(copy_from_menu_, SIGNAL(triggered(QAction *)), this, SLOT(copyFromProfile(QAction *)));
CopyFromProfileMenu *copy_from_menu = new CopyFromProfileMenu(uat_->filename, ui->copyFromProfileButton);
ui->copyFromProfileButton->setMenu(copy_from_menu);
ui->copyFromProfileButton->setEnabled(copy_from_menu->haveProfiles());
connect(copy_from_menu, SIGNAL(triggered(QAction *)), this, SLOT(copyFromProfile(QAction *)));
}
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_delegate.h>
class CopyFromProfileMenu;
namespace Ui {
class UatFrame;
}
@ -43,7 +41,6 @@ private:
UatModel *uat_model_;
UatDelegate *uat_delegate_;
CopyFromProfileMenu *copy_from_menu_;
struct epan_uat *uat_;
void checkForErrorHint(const QModelIndex &current, const QModelIndex &previous);

View File

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

View File

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