mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
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>
This commit is contained in:
parent
de579c1a1a
commit
4cb1ceefff
3 changed files with 36 additions and 23 deletions
|
@ -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;
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue