From 9e603cbe2bbcae1822859b284c39dd804bf321fb Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Fri, 25 Jan 2019 18:27:31 +0100 Subject: Undo: implement rudimentary undo of dive-notes editing Implement a first rudimentary dive-editing command. The main code resides in a base class Command::Edit, which calls virtual functions to read / set the fields and extract the field name. Implement an example: editing of dive notes. This dose not yet update the UI on undo / redo. Signed-off-by: Berthold Stoeger --- desktop-widgets/tab-widgets/maintab.cpp | 23 ++++++++++++----------- desktop-widgets/tab-widgets/maintab.h | 1 + 2 files changed, 13 insertions(+), 11 deletions(-) (limited to 'desktop-widgets/tab-widgets') diff --git a/desktop-widgets/tab-widgets/maintab.cpp b/desktop-widgets/tab-widgets/maintab.cpp index a077ad2a2..ab2eabd4c 100644 --- a/desktop-widgets/tab-widgets/maintab.cpp +++ b/desktop-widgets/tab-widgets/maintab.cpp @@ -767,8 +767,6 @@ void MainTab::acceptChanges() // were identical with the master dive shown (and mark the divelist as changed) if (!same_string(displayed_dive.suit, cd->suit)) MODIFY_DIVES(selectedDives, EDIT_TEXT(suit)); - if (!same_string(displayed_dive.notes, cd->notes)) - MODIFY_DIVES(selectedDives, EDIT_TEXT(notes)); if (displayed_dive.rating != cd->rating) MODIFY_DIVES(selectedDives, EDIT_VALUE(rating)); if (displayed_dive.visibility != cd->visibility) @@ -1343,16 +1341,19 @@ void MainTab::on_notes_textChanged() return; free(displayedTrip.notes); displayedTrip.notes = copy_qstring(ui.notes->toPlainText()); - } else { - if (same_string(displayed_dive.notes, qPrintable(ui.notes->toPlainText()))) - return; - free(displayed_dive.notes); - if (ui.notes->toHtml().indexOf("toHtml()); - else - displayed_dive.notes = copy_qstring(ui.notes->toPlainText()); + markChangedWidget(ui.notes); } - markChangedWidget(ui.notes); +} + +void MainTab::on_notes_editingFinished() +{ + if (currentTrip || !current_dive) + return; // Trip-note editing is done via on_notes_textChanged() + + QString notes = ui.notes->toHtml().indexOf("toHtml() : ui.notes->toPlainText(); + + Command::editNotes(getSelectedDivesCurrentLast(), notes, QString(current_dive->notes)); } void MainTab::on_rating_valueChanged(int value) diff --git a/desktop-widgets/tab-widgets/maintab.h b/desktop-widgets/tab-widgets/maintab.h index 094f3d053..00b94d1a0 100644 --- a/desktop-widgets/tab-widgets/maintab.h +++ b/desktop-widgets/tab-widgets/maintab.h @@ -75,6 +75,7 @@ slots: void on_suit_textChanged(const QString &text); void on_diveTripLocation_textEdited(const QString& text); void on_notes_textChanged(); + void on_notes_editingFinished(); void on_airtemp_textChanged(const QString &text); void on_duration_textChanged(const QString &text); void on_depth_textChanged(const QString &text); -- cgit v1.2.3-70-g09d2