From 7417f865cd628aa5df78961dc198a9070822ed72 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Wed, 27 May 2020 14:13:15 +0200 Subject: [PATCH] cleanup: un-singletonize ShiftTimesDialog There is no reason that this dialog is a singleton. Since it is modal, it can be created on demand. Apart from removing superfluous global state, this simplifies code, because preparing the widget can now be done in the constructor instead of overriding the showEvent() function. Signed-off-by: Berthold Stoeger --- desktop-widgets/divelistview.cpp | 3 ++- desktop-widgets/simplewidgets.cpp | 9 --------- desktop-widgets/simplewidgets.h | 4 +--- 3 files changed, 3 insertions(+), 13 deletions(-) diff --git a/desktop-widgets/divelistview.cpp b/desktop-widgets/divelistview.cpp index 6d41c7ff1..15c6631bf 100644 --- a/desktop-widgets/divelistview.cpp +++ b/desktop-widgets/divelistview.cpp @@ -860,7 +860,8 @@ void DiveListView::contextMenuEvent(QContextMenuEvent *event) void DiveListView::shiftTimes() { - ShiftTimesDialog::instance()->show(); + ShiftTimesDialog dialog(MainWindow::instance()); + dialog.exec(); } void DiveListView::loadImages() diff --git a/desktop-widgets/simplewidgets.cpp b/desktop-widgets/simplewidgets.cpp index ef7ca71d0..f30b9fc46 100644 --- a/desktop-widgets/simplewidgets.cpp +++ b/desktop-widgets/simplewidgets.cpp @@ -179,12 +179,6 @@ SetpointDialog::SetpointDialog(struct dive *dIn, int dcNrIn, int seconds) : QDia connect(quit, &QShortcut::activated, MainWindow::instance(), &QWidget::close); } -ShiftTimesDialog *ShiftTimesDialog::instance() -{ - static ShiftTimesDialog *self = new ShiftTimesDialog(MainWindow::instance()); - return self; -} - void ShiftTimesDialog::buttonClicked(QAbstractButton *button) { int amount; @@ -196,10 +190,7 @@ void ShiftTimesDialog::buttonClicked(QAbstractButton *button) if (amount != 0) Command::shiftTime(getDiveSelection(), amount); } -} -void ShiftTimesDialog::showEvent(QShowEvent*) -{ ui.timeEdit->setTime(QTime(0, 0, 0, 0)); when = get_times(); //get time of first selected dive ui.currentTime->setText(get_dive_date_string(when)); diff --git a/desktop-widgets/simplewidgets.h b/desktop-widgets/simplewidgets.h index ce8c636f7..ed364e75f 100644 --- a/desktop-widgets/simplewidgets.h +++ b/desktop-widgets/simplewidgets.h @@ -78,15 +78,13 @@ private: class ShiftTimesDialog : public QDialog { Q_OBJECT public: - static ShiftTimesDialog *instance(); - void showEvent(QShowEvent *event); + explicit ShiftTimesDialog(QWidget *parent); private slots: void buttonClicked(QAbstractButton *button); void changeTime(); private: - explicit ShiftTimesDialog(QWidget *parent); int64_t when; Ui::ShiftTimesDialog ui; };