From 063a20a4069a1d4fb20b69a7295bb2779bffec89 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Wed, 18 Jan 2023 01:34:14 +0100 Subject: [PATCH] desktop: pass dive list to ShiftTimesDialog Users report that the ShiftTimesDialog does not work on Mac and Windows. Apparently, get_first_selected_dive returns NULL, which should not be possible because the dialog is only created when dives are selected. Very omninous. Get the selected dives in the caller and pass them down. This bug at least should not happen anylonger. Perhaps now the dialog does not show at all, but that will narrow down the root cause of the problem. Signed-off-by: Berthold Stoeger --- desktop-widgets/divelistview.cpp | 5 ++++- desktop-widgets/simplewidgets.cpp | 15 ++++++--------- desktop-widgets/simplewidgets.h | 4 +++- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/desktop-widgets/divelistview.cpp b/desktop-widgets/divelistview.cpp index b372c2a7e..aa5c04a7f 100644 --- a/desktop-widgets/divelistview.cpp +++ b/desktop-widgets/divelistview.cpp @@ -845,7 +845,10 @@ void DiveListView::contextMenuEvent(QContextMenuEvent *event) void DiveListView::shiftTimes() { - ShiftTimesDialog dialog(MainWindow::instance()); + std::vector dives = getDiveSelection(); + if (dives.empty()) + return; + ShiftTimesDialog dialog(std::move(dives), MainWindow::instance()); dialog.exec(); } diff --git a/desktop-widgets/simplewidgets.cpp b/desktop-widgets/simplewidgets.cpp index aa7337881..5b1c13044 100644 --- a/desktop-widgets/simplewidgets.cpp +++ b/desktop-widgets/simplewidgets.cpp @@ -87,7 +87,7 @@ void ShiftTimesDialog::buttonClicked(QAbstractButton *button) if (ui.backwards->isChecked()) amount *= -1; if (amount != 0) - Command::shiftTime(getDiveSelection(), amount); + Command::shiftTime(dives, amount); } } @@ -102,8 +102,8 @@ void ShiftTimesDialog::changeTime() ui.shiftedTime->setText(get_dive_date_string(amount + when)); } -ShiftTimesDialog::ShiftTimesDialog(QWidget *parent) : QDialog(parent), - when(0) +ShiftTimesDialog::ShiftTimesDialog(std::vector dives_in, QWidget *parent) : QDialog(parent), + when(0), dives(std::move(dives_in)) { ui.setupUi(this); connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton *)), this, SLOT(buttonClicked(QAbstractButton *))); @@ -113,12 +113,9 @@ ShiftTimesDialog::ShiftTimesDialog(QWidget *parent) : QDialog(parent), 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())); - dive *d = first_selected_dive(); - if (d) { - when = d->when; - ui.currentTime->setText(get_dive_date_string(when)); - ui.shiftedTime->setText(get_dive_date_string(when)); - } + when = dives[0]->when; + ui.currentTime->setText(get_dive_date_string(when)); + ui.shiftedTime->setText(get_dive_date_string(when)); } void ShiftImageTimesDialog::syncCameraClicked() diff --git a/desktop-widgets/simplewidgets.h b/desktop-widgets/simplewidgets.h index 0f143d724..72011d71d 100644 --- a/desktop-widgets/simplewidgets.h +++ b/desktop-widgets/simplewidgets.h @@ -55,7 +55,8 @@ private: class ShiftTimesDialog : public QDialog { Q_OBJECT public: - explicit ShiftTimesDialog(QWidget *parent); + // Must be called with non-empty dives vector! + explicit ShiftTimesDialog(std::vector dives, QWidget *parent); private slots: void buttonClicked(QAbstractButton *button); @@ -63,6 +64,7 @@ slots: private: int64_t when; + std::vector dives; Ui::ShiftTimesDialog ui; };