diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2019-02-07 21:23:00 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2019-04-12 18:19:07 +0300 |
commit | 02d572226df82ccbdfff3c455c9e5b20a7992bc4 (patch) | |
tree | 26b213e2a2af1302631dd2dd2fd2ed3e622793ed | |
parent | a9bd0690fe1d6bd841b0ede2ac53b280ef907b93 (diff) | |
download | subsurface-02d572226df82ccbdfff3c455c9e5b20a7992bc4.tar.gz |
Undo: implement undo of divemaster editing
This is mostly a trivial copy of the buddies code.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r-- | desktop-widgets/command.cpp | 5 | ||||
-rw-r--r-- | desktop-widgets/command.h | 1 | ||||
-rw-r--r-- | desktop-widgets/command_edit.cpp | 23 | ||||
-rw-r--r-- | desktop-widgets/command_edit.h | 9 | ||||
-rw-r--r-- | desktop-widgets/tab-widgets/maintab.cpp | 18 | ||||
-rw-r--r-- | desktop-widgets/tab-widgets/maintab.h | 2 |
6 files changed, 45 insertions, 13 deletions
diff --git a/desktop-widgets/command.cpp b/desktop-widgets/command.cpp index f1c0a67dd..bb37eb816 100644 --- a/desktop-widgets/command.cpp +++ b/desktop-widgets/command.cpp @@ -185,4 +185,9 @@ void editBuddies(const QVector<dive *> &dives, const QStringList &newList, struc execute(new EditBuddies(dives, newList, d)); } +void editDiveMaster(const QVector<dive *> &dives, const QStringList &newList, struct dive *d) +{ + execute(new EditDiveMaster(dives, newList, d)); +} + } // namespace Command diff --git a/desktop-widgets/command.h b/desktop-widgets/command.h index 4ab07b132..d89f54bf7 100644 --- a/desktop-widgets/command.h +++ b/desktop-widgets/command.h @@ -63,6 +63,7 @@ void editDiveSite(const QVector<dive *> dives, struct dive_site *newValue, struc void editDiveSiteNew(const QVector<dive *> dives, const QString &newName, struct dive_site *oldValue); void editTags(const QVector<dive *> &dives, const QStringList &newList, struct dive *d); void editBuddies(const QVector<dive *> &dives, const QStringList &newList, struct dive *d); +void editDiveMaster(const QVector<dive *> &dives, const QStringList &newList, struct dive *d); } // namespace Command diff --git a/desktop-widgets/command_edit.cpp b/desktop-widgets/command_edit.cpp index 165bbbe90..8366db153 100644 --- a/desktop-widgets/command_edit.cpp +++ b/desktop-widgets/command_edit.cpp @@ -483,4 +483,27 @@ DiveField EditBuddies::fieldId() const return DiveField::BUDDY; } +// ***** DiveMaster ***** +QStringList EditDiveMaster::data(struct dive *d) const +{ + return stringToList(d->divemaster); +} + +void EditDiveMaster::set(struct dive *d, const QStringList &v) const +{ + QString text = v.join(", "); + free(d->divemaster); + d->divemaster = copy_qstring(text); +} + +QString EditDiveMaster::fieldName() const +{ + return tr("dive master"); +} + +DiveField EditDiveMaster::fieldId() const +{ + return DiveField::DIVEMASTER; +} + } // namespace Command diff --git a/desktop-widgets/command_edit.h b/desktop-widgets/command_edit.h index d77c46a27..d10da4325 100644 --- a/desktop-widgets/command_edit.h +++ b/desktop-widgets/command_edit.h @@ -182,6 +182,15 @@ public: DiveField fieldId() const override; }; +class EditDiveMaster : public EditTagsBase { +public: + using EditTagsBase::EditTagsBase; // Use constructor of base class. + QStringList data(struct dive *d) const override; + void set(struct dive *d, const QStringList &v) const override; + QString fieldName() const override; + DiveField fieldId() const override; +}; + } // namespace Command #endif diff --git a/desktop-widgets/tab-widgets/maintab.cpp b/desktop-widgets/tab-widgets/maintab.cpp index eff22192b..77a6c9f5c 100644 --- a/desktop-widgets/tab-widgets/maintab.cpp +++ b/desktop-widgets/tab-widgets/maintab.cpp @@ -378,6 +378,9 @@ void MainTab::divesEdited(const QVector<dive *> &, DiveField field) case DiveField::BUDDY: ui.buddy->setText(current_dive->buddy); break; + case DiveField::DIVEMASTER: + ui.divemaster->setText(current_dive->divemaster); + break; default: break; } @@ -998,21 +1001,12 @@ void MainTab::on_buddy_editingFinished() Command::editBuddies(getSelectedDivesCurrentLast(), stringToList(ui.buddy->toPlainText()), current_dive); } -void MainTab::on_divemaster_textChanged() +void MainTab::on_divemaster_editingFinished() { - if (editMode == IGNORE || acceptingEdit == true) - return; - - if (same_string(displayed_dive.divemaster, qPrintable(ui.divemaster->toPlainText()))) + if (editMode == IGNORE || acceptingEdit == true || !current_dive) return; - QStringList text_list = ui.divemaster->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.divemaster); - displayed_dive.divemaster = copy_qstring(text); - markChangedWidget(ui.divemaster); + Command::editDiveMaster(getSelectedDivesCurrentLast(), stringToList(ui.divemaster->toPlainText()), current_dive); } void MainTab::on_duration_textChanged(const QString &text) diff --git a/desktop-widgets/tab-widgets/maintab.h b/desktop-widgets/tab-widgets/maintab.h index 88c2b4738..2cb82b0bd 100644 --- a/desktop-widgets/tab-widgets/maintab.h +++ b/desktop-widgets/tab-widgets/maintab.h @@ -74,7 +74,7 @@ slots: void acceptChanges(); void rejectChanges(); void on_location_diveSiteSelected(); - void on_divemaster_textChanged(); + void on_divemaster_editingFinished(); void on_buddy_editingFinished(); void on_suit_editingFinished(); void on_diveTripLocation_textEdited(const QString& text); |