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; };