diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2019-02-10 17:37:06 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2019-04-12 18:19:07 +0300 |
commit | c82f4487f985a2d3fd832a1acce60fa052f9f246 (patch) | |
tree | 56c573892c607ebf1feef3ca7b4c46158decfbb3 /desktop-widgets/tab-widgets | |
parent | 02d572226df82ccbdfff3c455c9e5b20a7992bc4 (diff) | |
download | subsurface-c82f4487f985a2d3fd832a1acce60fa052f9f246.tar.gz |
Undo: implement undo of depth and duration editing
This was a bit different from the other editing commands:
1) Only the current dive is edited not all selected dives.
Therefore, create a function that turns the current dive
into a one-element list.
2) The profile has to be replot. Here, likewise, create a
function to do that.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets/tab-widgets')
-rw-r--r-- | desktop-widgets/tab-widgets/maintab.cpp | 59 | ||||
-rw-r--r-- | desktop-widgets/tab-widgets/maintab.h | 4 |
2 files changed, 33 insertions, 30 deletions
diff --git a/desktop-widgets/tab-widgets/maintab.cpp b/desktop-widgets/tab-widgets/maintab.cpp index 77a6c9f5c..8992a645d 100644 --- a/desktop-widgets/tab-widgets/maintab.cpp +++ b/desktop-widgets/tab-widgets/maintab.cpp @@ -333,6 +333,13 @@ void MainTab::enableEdition(EditMode newEditMode) } } +static void profileFromDive(struct dive *d) +{ + DivePlannerPointsModel::instance()->loadFromDive(d); + MainWindow::instance()->graphics->setReplot(true); + MainWindow::instance()->graphics->plotDive(current_dive, true); +} + // This function gets called if a field gets updated by an undo command. // Refresh the corresponding UI field. void MainTab::divesEdited(const QVector<dive *> &, DiveField field) @@ -342,6 +349,14 @@ void MainTab::divesEdited(const QVector<dive *> &, DiveField field) return; switch(field) { + case DiveField::DURATION: + ui.duration->setText(render_seconds_to_string(current_dive->duration.seconds)); + profileFromDive(current_dive); + break; + case DiveField::DEPTH: + ui.depth->setText(get_depth_string(current_dive->maxdepth, true)); + profileFromDive(current_dive); + break; case DiveField::AIR_TEMP: ui.airtemp->setText(get_temperature_string(current_dive->airtemp, true)); break; @@ -724,6 +739,13 @@ static QVector<dive *> getSelectedDivesCurrentLast() return res; } +// When editing depth and duration, we only edit a single dive. Therefore, return the current dive as a list +static QVector<dive *> getCurrentAsList() +{ + return current_dive ? QVector<dive *> { current_dive } + : QVector<dive *> { }; +} + void MainTab::acceptChanges() { int i, addedId = -1; @@ -1009,41 +1031,22 @@ void MainTab::on_divemaster_editingFinished() Command::editDiveMaster(getSelectedDivesCurrentLast(), stringToList(ui.divemaster->toPlainText()), current_dive); } -void MainTab::on_duration_textChanged(const QString &text) +void MainTab::on_duration_editingFinished() { - if (editMode == IGNORE || acceptingEdit == true) + if (editMode == IGNORE || acceptingEdit == true || !current_dive) return; - // parse this - MainWindow::instance()->graphics->setReplot(false); - if (!isEditing()) - enableEdition(); - displayed_dive.dc.duration.seconds = parseDurationToSeconds(text); - displayed_dive.duration = displayed_dive.dc.duration; - displayed_dive.dc.meandepth.mm = 0; - displayed_dive.dc.samples = 0; - DivePlannerPointsModel::instance()->loadFromDive(&displayed_dive); - markChangedWidget(ui.duration); - MainWindow::instance()->graphics->setReplot(true); - MainWindow::instance()->graphics->plotDive(); + // Duration editing is special: we only edit the current dive. + Command::editDuration(getCurrentAsList(), parseDurationToSeconds(ui.duration->text()), displayed_dive.dc.duration.seconds); } -void MainTab::on_depth_textChanged(const QString &text) +void MainTab::on_depth_editingFinished() { - if (editMode == IGNORE || acceptingEdit == true) + if (editMode == IGNORE || acceptingEdit == true || !current_dive) return; - // don't replot until we set things up the way we want them - MainWindow::instance()->graphics->setReplot(false); - if (!isEditing()) - enableEdition(); - displayed_dive.dc.maxdepth.mm = parseLengthToMm(text); - displayed_dive.maxdepth = displayed_dive.dc.maxdepth; - displayed_dive.dc.meandepth.mm = 0; - displayed_dive.dc.samples = 0; - DivePlannerPointsModel::instance()->loadFromDive(&displayed_dive); - markChangedWidget(ui.depth); - MainWindow::instance()->graphics->setReplot(true); - MainWindow::instance()->graphics->plotDive(); + + // Depth editing is special: we only edit the current dive. + Command::editDepth(getCurrentAsList(), parseLengthToMm(ui.depth->text()), current_dive->dc.maxdepth.mm); } void MainTab::on_airtemp_editingFinished() diff --git a/desktop-widgets/tab-widgets/maintab.h b/desktop-widgets/tab-widgets/maintab.h index 2cb82b0bd..f9d7417f5 100644 --- a/desktop-widgets/tab-widgets/maintab.h +++ b/desktop-widgets/tab-widgets/maintab.h @@ -81,8 +81,8 @@ slots: void on_notes_textChanged(); void on_notes_editingFinished(); void on_airtemp_editingFinished(); - void on_duration_textChanged(const QString &text); - void on_depth_textChanged(const QString &text); + void on_duration_editingFinished(); + void on_depth_editingFinished(); void divetype_Changed(int); void on_watertemp_editingFinished(); void on_dateEdit_dateChanged(const QDate &date); |