cleanup: un-singletonize RenumberDialog

There is no reason that this dialog is a singleton. Since it is modal,
it can be created on demand. This simplifies code, because the mode
(selected-only or all-dives) can be set in the constructor.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2020-05-27 14:00:47 +02:00 committed by Dirk Hohndel
parent 79f90effe9
commit 25f1bc488f
4 changed files with 16 additions and 29 deletions

View file

@ -647,8 +647,8 @@ void DiveListView::splitDives()
void DiveListView::renumberDives() void DiveListView::renumberDives()
{ {
RenumberDialog::instance()->renumberOnlySelected(); RenumberDialog dialog(true, MainWindow::instance());
RenumberDialog::instance()->show(); dialog.exec();
} }
void DiveListView::merge_trip(const QModelIndex &a, int offset) void DiveListView::merge_trip(const QModelIndex &a, int offset)

View file

@ -921,8 +921,8 @@ void MainWindow::on_actionAddDive_triggered()
void MainWindow::on_actionRenumber_triggered() void MainWindow::on_actionRenumber_triggered()
{ {
RenumberDialog::instance()->renumberOnlySelected(false); RenumberDialog dialog(false, this);
RenumberDialog::instance()->show(); dialog.exec();
} }
void MainWindow::on_actionAutoGroup_triggered() void MainWindow::on_actionAutoGroup_triggered()

View file

@ -124,27 +124,6 @@ void MinMaxAvgWidget::setAvgVisibility(bool visible)
avgValue->setVisible(visible); avgValue->setVisible(visible);
} }
RenumberDialog *RenumberDialog::instance()
{
static RenumberDialog *self = new RenumberDialog(MainWindow::instance());
return self;
}
void RenumberDialog::renumberOnlySelected(bool selected)
{
if (selected && amount_selected == 1)
ui.renumberText->setText(tr("New number"));
else
ui.renumberText->setText(tr("New starting number"));
if (selected)
ui.groupBox->setTitle(tr("Renumber selected dives"));
else
ui.groupBox->setTitle(tr("Renumber all dives"));
selectedOnly = selected;
}
void RenumberDialog::buttonClicked(QAbstractButton *button) void RenumberDialog::buttonClicked(QAbstractButton *button)
{ {
if (ui.buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole) { if (ui.buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole) {
@ -163,7 +142,7 @@ void RenumberDialog::buttonClicked(QAbstractButton *button)
} }
} }
RenumberDialog::RenumberDialog(QWidget *parent) : QDialog(parent), selectedOnly(false) RenumberDialog::RenumberDialog(bool selectedOnlyIn, QWidget *parent) : QDialog(parent), selectedOnly(selectedOnlyIn)
{ {
ui.setupUi(this); ui.setupUi(this);
connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton *)), this, SLOT(buttonClicked(QAbstractButton *))); connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton *)), this, SLOT(buttonClicked(QAbstractButton *)));
@ -171,6 +150,16 @@ RenumberDialog::RenumberDialog(QWidget *parent) : QDialog(parent), selectedOnly(
connect(close, SIGNAL(activated()), this, SLOT(close())); connect(close, SIGNAL(activated()), this, SLOT(close()));
QShortcut *quit = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this); QShortcut *quit = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this);
connect(quit, SIGNAL(activated()), parent, SLOT(close())); connect(quit, SIGNAL(activated()), parent, SLOT(close()));
if (selectedOnly && amount_selected == 1)
ui.renumberText->setText(tr("New number"));
else
ui.renumberText->setText(tr("New starting number"));
if (selectedOnly)
ui.groupBox->setTitle(tr("Renumber selected dives"));
else
ui.groupBox->setTitle(tr("Renumber all dives"));
} }
void SetpointDialog::buttonClicked(QAbstractButton *button) void SetpointDialog::buttonClicked(QAbstractButton *button)

View file

@ -50,14 +50,12 @@ public:
class RenumberDialog : public QDialog { class RenumberDialog : public QDialog {
Q_OBJECT Q_OBJECT
public: public:
static RenumberDialog *instance(); explicit RenumberDialog(bool selectedOnly, QWidget *parent);
void renumberOnlySelected(bool selected = true);
private private
slots: slots:
void buttonClicked(QAbstractButton *button); void buttonClicked(QAbstractButton *button);
private: private:
explicit RenumberDialog(QWidget *parent);
Ui::RenumberDialog ui; Ui::RenumberDialog ui;
bool selectedOnly; bool selectedOnly;
}; };