From 25f1bc488f68395390a3a87328b31dfa7deac11c Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Wed, 27 May 2020 14:00:47 +0200 Subject: 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 --- desktop-widgets/simplewidgets.cpp | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) (limited to 'desktop-widgets/simplewidgets.cpp') diff --git a/desktop-widgets/simplewidgets.cpp b/desktop-widgets/simplewidgets.cpp index ba3dc67ee..ef7ca71d0 100644 --- a/desktop-widgets/simplewidgets.cpp +++ b/desktop-widgets/simplewidgets.cpp @@ -124,27 +124,6 @@ void MinMaxAvgWidget::setAvgVisibility(bool 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) { 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); 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())); QShortcut *quit = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this); 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) -- cgit v1.2.3-70-g09d2