summaryrefslogtreecommitdiffstats
path: root/desktop-widgets/tab-widgets/maintab.cpp
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-03-19 22:05:52 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-04-12 18:19:07 +0300
commit4cb1ceefff96121331f63e1455d233b32b3d7680 (patch)
tree8ff4e229f4f4a19a5d420d415a254727eb9d2443 /desktop-widgets/tab-widgets/maintab.cpp
parentde579c1a1ad823fbc42d7e3122b77b03626283c3 (diff)
downloadsubsurface-4cb1ceefff96121331f63e1455d233b32b3d7680.tar.gz
Undo: implement undo of dive date- and time-editing
This is different from the other editing commands, because date and time editing may change the order of the dive list. Therefore, this uses an already implemented dive list command. The command is extended to send a divesEdited() signal. This signal and the divesChanged() signal, which is used by the dive list, will be unified in a later commit. Update of the graphics is now not done via signals, a direct call is performed in MainTab::divesEdited(). This simplifies things. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets/tab-widgets/maintab.cpp')
-rw-r--r--desktop-widgets/tab-widgets/maintab.cpp56
1 files changed, 34 insertions, 22 deletions
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()