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 <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2023-01-18 01:34:14 +01:00 committed by Dirk Hohndel
parent f45379e97c
commit 063a20a406
3 changed files with 13 additions and 11 deletions

View file

@ -845,7 +845,10 @@ void DiveListView::contextMenuEvent(QContextMenuEvent *event)
void DiveListView::shiftTimes() void DiveListView::shiftTimes()
{ {
ShiftTimesDialog dialog(MainWindow::instance()); std::vector<dive *> dives = getDiveSelection();
if (dives.empty())
return;
ShiftTimesDialog dialog(std::move(dives), MainWindow::instance());
dialog.exec(); dialog.exec();
} }

View file

@ -87,7 +87,7 @@ void ShiftTimesDialog::buttonClicked(QAbstractButton *button)
if (ui.backwards->isChecked()) if (ui.backwards->isChecked())
amount *= -1; amount *= -1;
if (amount != 0) 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)); ui.shiftedTime->setText(get_dive_date_string(amount + when));
} }
ShiftTimesDialog::ShiftTimesDialog(QWidget *parent) : QDialog(parent), ShiftTimesDialog::ShiftTimesDialog(std::vector<dive *> dives_in, QWidget *parent) : QDialog(parent),
when(0) when(0), dives(std::move(dives_in))
{ {
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 *)));
@ -113,12 +113,9 @@ ShiftTimesDialog::ShiftTimesDialog(QWidget *parent) : QDialog(parent),
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()));
dive *d = first_selected_dive(); when = dives[0]->when;
if (d) { ui.currentTime->setText(get_dive_date_string(when));
when = d->when; ui.shiftedTime->setText(get_dive_date_string(when));
ui.currentTime->setText(get_dive_date_string(when));
ui.shiftedTime->setText(get_dive_date_string(when));
}
} }
void ShiftImageTimesDialog::syncCameraClicked() void ShiftImageTimesDialog::syncCameraClicked()

View file

@ -55,7 +55,8 @@ private:
class ShiftTimesDialog : public QDialog { class ShiftTimesDialog : public QDialog {
Q_OBJECT Q_OBJECT
public: public:
explicit ShiftTimesDialog(QWidget *parent); // Must be called with non-empty dives vector!
explicit ShiftTimesDialog(std::vector<dive *> dives, QWidget *parent);
private private
slots: slots:
void buttonClicked(QAbstractButton *button); void buttonClicked(QAbstractButton *button);
@ -63,6 +64,7 @@ slots:
private: private:
int64_t when; int64_t when;
std::vector<dive *> dives;
Ui::ShiftTimesDialog ui; Ui::ShiftTimesDialog ui;
}; };