From c495a49b1b044ab54ee60d4b0db14caa3f8e3de1 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Fri, 3 Jan 2020 16:04:54 +0100 Subject: Cleanup: use getDiveSelection() for shifting time There are two cases where dive-times are shifted: in an explicit dialog and when editing the date/time of a dive. In each of these cases, the selected dives were collected manually. Instead use the getDiveSelection() function. Since this returns a std::vector, change the argument of Command::ShiftTime() to such a std::vector. Signed-off-by: Berthold Stoeger --- desktop-widgets/simplewidgets.cpp | 13 ++----------- desktop-widgets/tab-widgets/maintab.cpp | 10 +--------- 2 files changed, 3 insertions(+), 20 deletions(-) (limited to 'desktop-widgets') diff --git a/desktop-widgets/simplewidgets.cpp b/desktop-widgets/simplewidgets.cpp index cf4b9b0ae..fb4d3750b 100644 --- a/desktop-widgets/simplewidgets.cpp +++ b/desktop-widgets/simplewidgets.cpp @@ -222,17 +222,8 @@ void ShiftTimesDialog::buttonClicked(QAbstractButton *button) amount = ui.timeEdit->time().hour() * 3600 + ui.timeEdit->time().minute() * 60; if (ui.backwards->isChecked()) amount *= -1; - if (amount != 0) { - // DANGER, DANGER - this could get our dive_table unsorted... - int i; - struct dive *d; - QVector affectedDives; - for_each_dive (i, d) { - if (d->selected) - affectedDives.append(d); - } - Command::shiftTime(affectedDives, amount); - } + if (amount != 0) + Command::shiftTime(getDiveSelection(), amount); } } diff --git a/desktop-widgets/tab-widgets/maintab.cpp b/desktop-widgets/tab-widgets/maintab.cpp index b17b80633..85d64c66d 100644 --- a/desktop-widgets/tab-widgets/maintab.cpp +++ b/desktop-widgets/tab-widgets/maintab.cpp @@ -677,18 +677,10 @@ void MainTab::on_depth_editingFinished() // all dives are shifted by an offset. static void shiftTime(QDateTime &dateTime) { - QVector dives; - struct dive *d; - int i; - for_each_dive (i, d) { - if (d->selected) - dives.append(d); - } - timestamp_t when = dateTime.toTime_t(); if (current_dive && current_dive->when != when) { timestamp_t offset = when - current_dive->when; - Command::shiftTime(dives, (int)offset); + Command::shiftTime(getDiveSelection(), (int)offset); } } -- cgit v1.2.3-70-g09d2