mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
a9bd0690fe
commit
02d572226d
6 changed files with 45 additions and 13 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
if (editMode == IGNORE || acceptingEdit == true || !current_dive)
|
||||
return;
|
||||
|
||||
if (same_string(displayed_dive.divemaster, qPrintable(ui.divemaster->toPlainText())))
|
||||
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)
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue