diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2019-02-07 21:00:09 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2019-04-12 18:19:07 +0300 |
commit | a9bd0690fe1d6bd841b0ede2ac53b280ef907b93 (patch) | |
tree | 663bd078f59c8e08902b31fe59395b7327728ee7 /desktop-widgets/tab-widgets | |
parent | 8c89f6fe1520d9d88fb81acab995ba803f5c4ac1 (diff) | |
download | subsurface-a9bd0690fe1d6bd841b0ede2ac53b280ef907b93.tar.gz |
Undo: implement undo of buddy editing
This was mostly trivial by reusing the code for tag-editing.
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 | 24 | ||||
-rw-r--r-- | desktop-widgets/tab-widgets/maintab.h | 2 |
2 files changed, 14 insertions, 12 deletions
diff --git a/desktop-widgets/tab-widgets/maintab.cpp b/desktop-widgets/tab-widgets/maintab.cpp index 19fa56332..eff22192b 100644 --- a/desktop-widgets/tab-widgets/maintab.cpp +++ b/desktop-widgets/tab-widgets/maintab.cpp @@ -375,6 +375,9 @@ void MainTab::divesEdited(const QVector<dive *> &, DiveField field) case DiveField::TAGS: ui.tagWidget->setText(get_taglist_string(current_dive->tag_list)); break; + case DiveField::BUDDY: + ui.buddy->setText(current_dive->buddy); + break; default: break; } @@ -979,21 +982,20 @@ void MainTab::markChangedWidget(QWidget *w) modified = true; } -void MainTab::on_buddy_textChanged() +static QStringList stringToList(const QString &s) { - if (editMode == IGNORE || acceptingEdit == true) - return; + QStringList res = s.split(",", QString::SkipEmptyParts); + for (QString &str: res) + str = str.trimmed(); + return res; +} - if (same_string(displayed_dive.buddy, qPrintable(ui.buddy->toPlainText()))) +void MainTab::on_buddy_editingFinished() +{ + if (editMode == IGNORE || acceptingEdit == true || !current_dive) return; - QStringList text_list = ui.buddy->toPlainText().split(",", QString::SkipEmptyParts); - for (int i = 0; i < text_list.size(); i++) - text_list[i] = text_list[i].trimmed(); - QString text = text_list.join(", "); - free(displayed_dive.buddy); - displayed_dive.buddy = copy_qstring(text); - markChangedWidget(ui.buddy); + Command::editBuddies(getSelectedDivesCurrentLast(), stringToList(ui.buddy->toPlainText()), current_dive); } void MainTab::on_divemaster_textChanged() diff --git a/desktop-widgets/tab-widgets/maintab.h b/desktop-widgets/tab-widgets/maintab.h index 3b9fa26d6..88c2b4738 100644 --- a/desktop-widgets/tab-widgets/maintab.h +++ b/desktop-widgets/tab-widgets/maintab.h @@ -75,7 +75,7 @@ slots: void rejectChanges(); void on_location_diveSiteSelected(); void on_divemaster_textChanged(); - void on_buddy_textChanged(); + void on_buddy_editingFinished(); void on_suit_editingFinished(); void on_diveTripLocation_textEdited(const QString& text); void on_notes_textChanged(); |