summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--desktop-widgets/command_divelist.cpp1
-rw-r--r--desktop-widgets/tab-widgets/maintab.cpp56
-rw-r--r--desktop-widgets/tab-widgets/maintab.h2
3 files changed, 36 insertions, 23 deletions
diff --git a/desktop-widgets/command_divelist.cpp b/desktop-widgets/command_divelist.cpp
index 8da0fab46..a901822f9 100644
--- a/desktop-widgets/command_divelist.cpp
+++ b/desktop-widgets/command_divelist.cpp
@@ -746,6 +746,7 @@ void ShiftTime::redoit()
sort_dive_table(&trip->dives); // Keep the trip-table in order
emit diveListNotifier.divesTimeChanged(trip, timeChanged, divesInTrip);
});
+ emit diveListNotifier.divesEdited(diveList, DiveField::DATETIME);
// Negate the time-shift so that the next call does the reverse
timeChanged = -timeChanged;
diff --git a/desktop-widgets/tab-widgets/maintab.cpp b/desktop-widgets/tab-widgets/maintab.cpp
index 202c75071..7b0a06465 100644
--- a/desktop-widgets/tab-widgets/maintab.cpp
+++ b/desktop-widgets/tab-widgets/maintab.cpp
@@ -363,6 +363,11 @@ void MainTab::divesEdited(const QVector<dive *> &, DiveField field)
case DiveField::MODE:
updateMode(current_dive);
break;
+ case DiveField::DATETIME:
+ updateDateTime(current_dive);
+ MainWindow::instance()->graphics->dateTimeChanged();
+ DivePlannerPointsModel::instance()->getDiveplan().when = current_dive->when;
+ break;
default:
break;
}
@@ -423,6 +428,16 @@ void MainTab::updateMode(struct dive *d)
MainWindow::instance()->graphics->recalcCeiling();
}
+void MainTab::updateDateTime(struct dive *d)
+{
+ // Subsurface always uses "local time" as in "whatever was the local time at the location"
+ // so all time stamps have no time zone information and are in UTC
+ QDateTime localTime = QDateTime::fromMSecsSinceEpoch(1000*d->when, Qt::UTC);
+ localTime.setTimeSpec(Qt::UTC);
+ ui.dateEdit->setDate(localTime.date());
+ ui.timeEdit->setTime(localTime.time());
+}
+
void MainTab::updateDiveInfo(bool clear)
{
ui.location->refreshDiveSiteCache();
@@ -464,12 +479,7 @@ void MainTab::updateDiveInfo(bool clear)
ui.locationTags->clear();
}
- // Subsurface always uses "local time" as in "whatever was the local time at the location"
- // so all time stamps have no time zone information and are in UTC
- QDateTime localTime = QDateTime::fromMSecsSinceEpoch(1000*displayed_dive.when, Qt::UTC);
- localTime.setTimeSpec(Qt::UTC);
- ui.dateEdit->setDate(localTime.date());
- ui.timeEdit->setTime(localTime.time());
+ updateDateTime(&displayed_dive);
if (MainWindow::instance() && MainWindow::instance()->diveList->selectedTrips().count() == 1) {
// Remember the tab selected for last dive
if (lastSelectedDive)
@@ -599,7 +609,6 @@ void MainTab::updateDiveInfo(bool clear)
/* unset the special value text for date and time, just in case someone dove at midnight */
ui.dateEdit->setSpecialValueText(QString(""));
ui.timeEdit->setSpecialValueText(QString(""));
-
} else {
/* clear the fields */
clearTabs();
@@ -746,7 +755,7 @@ void MainTab::acceptChanges()
struct dive *d;
bool do_replot = false;
- if(ui.location->hasFocus()) {
+ if (ui.location->hasFocus()) {
this->setFocus();
}
@@ -898,10 +907,6 @@ void MainTab::acceptChanges()
invalidate_dive_cache(d);
}
}
-
- timestamp_t offset = displayed_dive.when - cd->when;
- if (offset)
- Command::shiftTime(selectedDives, (int)offset);
}
if (editMode == MANUALLY_ADDED_DIVE) {
// we just added or edited the dive, let fixup_dive() make
@@ -1117,28 +1122,35 @@ void MainTab::on_watertemp_editingFinished()
current_dive->watertemp.mkelvin);
}
+// Editing of the dive time is different. If multiple dives are edited,
+// all dives are shifted by an offset.
+static void shiftTime(QDateTime &dateTime)
+{
+ timestamp_t when = dateTime.toTime_t();
+ if (current_dive && current_dive->when != when) {
+ timestamp_t offset = current_dive->when - when;
+ Command::shiftTime(getSelectedDivesCurrentLast(), (int)offset);
+ }
+}
+
void MainTab::on_dateEdit_dateChanged(const QDate &date)
{
- if (editMode == IGNORE || acceptingEdit == true)
+ if (editMode == IGNORE || acceptingEdit == true || !current_dive)
return;
- markChangedWidget(ui.dateEdit);
- QDateTime dateTime = QDateTime::fromMSecsSinceEpoch(1000*displayed_dive.when, Qt::UTC);
+ QDateTime dateTime = QDateTime::fromMSecsSinceEpoch(1000*current_dive->when, Qt::UTC);
dateTime.setTimeSpec(Qt::UTC);
dateTime.setDate(date);
- DivePlannerPointsModel::instance()->getDiveplan().when = displayed_dive.when = dateTime.toTime_t();
- emit dateTimeChanged();
+ shiftTime(dateTime);
}
void MainTab::on_timeEdit_timeChanged(const QTime &time)
{
- if (editMode == IGNORE || acceptingEdit == true)
+ if (editMode == IGNORE || acceptingEdit == true || !current_dive)
return;
- markChangedWidget(ui.timeEdit);
- QDateTime dateTime = QDateTime::fromMSecsSinceEpoch(1000*displayed_dive.when, Qt::UTC);
+ QDateTime dateTime = QDateTime::fromMSecsSinceEpoch(1000*current_dive->when, Qt::UTC);
dateTime.setTimeSpec(Qt::UTC);
dateTime.setTime(time);
- DivePlannerPointsModel::instance()->getDiveplan().when = displayed_dive.when = dateTime.toTime_t();
- emit dateTimeChanged();
+ shiftTime(dateTime);
}
void MainTab::copyTagsToDisplayedDive()
diff --git a/desktop-widgets/tab-widgets/maintab.h b/desktop-widgets/tab-widgets/maintab.h
index 36f9a64a9..805618857 100644
--- a/desktop-widgets/tab-widgets/maintab.h
+++ b/desktop-widgets/tab-widgets/maintab.h
@@ -59,7 +59,6 @@ public:
signals:
void addDiveFinished();
- void dateTimeChanged();
void diveSiteChanged();
public
slots:
@@ -69,6 +68,7 @@ slots:
void updateDiveInfo(bool clear = false);
void updateNotes(const struct dive *d);
void updateMode(struct dive *d);
+ void updateDateTime(struct dive *d);
void updateDepthDuration();
void acceptChanges();
void rejectChanges();