mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-31 19:13:24 +00:00
Undo: implement undo of suit editing
This one was trivially modelled after notes editing. Only difference: the textChanged() signal was replaced by the editingFinished() signal so that we're not generating undo-commands on every key-press. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
f11ac40593
commit
512a2e6b68
6 changed files with 45 additions and 8 deletions
|
@ -140,4 +140,9 @@ void editMode(const QVector<dive *> dives, int index, int newValue, int oldValue
|
|||
execute(new EditMode(dives, index, newValue, oldValue));
|
||||
}
|
||||
|
||||
void editSuit(const QVector<dive *> dives, const QString &newValue, const QString &oldValue)
|
||||
{
|
||||
execute(new EditSuit(dives, newValue, oldValue));
|
||||
}
|
||||
|
||||
} // namespace Command
|
||||
|
|
|
@ -53,6 +53,7 @@ void purgeUnusedDiveSites();
|
|||
// 4) Dive editing related commands
|
||||
|
||||
void editNotes(const QVector<dive *> dives, const QString &newValue, const QString &oldValue);
|
||||
void editSuit(const QVector<dive *> dives, const QString &newValue, const QString &oldValue);
|
||||
void editMode(const QVector<dive *> dives, int index, int newValue, int oldValue);
|
||||
|
||||
} // namespace Command
|
||||
|
|
|
@ -100,6 +100,28 @@ DiveField EditNotes::fieldId() const
|
|||
return DiveField::NOTES;
|
||||
}
|
||||
|
||||
// ***** Suit *****
|
||||
void EditSuit::set(struct dive *d, QString s) const
|
||||
{
|
||||
free(d->suit);
|
||||
d->suit = strdup(qPrintable(s));
|
||||
}
|
||||
|
||||
QString EditSuit::data(struct dive *d) const
|
||||
{
|
||||
return QString(d->suit);
|
||||
}
|
||||
|
||||
QString EditSuit::fieldName() const
|
||||
{
|
||||
return tr("suit");
|
||||
}
|
||||
|
||||
DiveField EditSuit::fieldId() const
|
||||
{
|
||||
return DiveField::SUIT;
|
||||
}
|
||||
|
||||
// ***** Mode *****
|
||||
// Editing the dive mode has very peculiar semantics for historic reasons:
|
||||
// Since the dive-mode depends on the dive computer, the i-th dive computer
|
||||
|
|
|
@ -56,6 +56,15 @@ public:
|
|||
DiveField fieldId() const override;
|
||||
};
|
||||
|
||||
class EditSuit : public EditBase<QString> {
|
||||
public:
|
||||
using EditBase<QString>::EditBase; // Use constructor of base class.
|
||||
void set(struct dive *d, QString s) const override;
|
||||
QString data(struct dive *d) const override;
|
||||
QString fieldName() const override;
|
||||
DiveField fieldId() const override;
|
||||
};
|
||||
|
||||
class EditMode : public EditBase<int> {
|
||||
int index;
|
||||
public:
|
||||
|
|
|
@ -342,6 +342,9 @@ void MainTab::divesEdited(const QVector<dive *> &, DiveField field)
|
|||
return;
|
||||
|
||||
switch(field) {
|
||||
case DiveField::SUIT:
|
||||
ui.suit->setText(QString(current_dive->suit));
|
||||
break;
|
||||
case DiveField::NOTES:
|
||||
updateNotes(current_dive);
|
||||
break;
|
||||
|
@ -795,8 +798,6 @@ void MainTab::acceptChanges()
|
|||
struct dive *cd = current_dive;
|
||||
// now check if something has changed and if yes, edit the selected dives that
|
||||
// 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 (displayed_dive.rating != cd->rating)
|
||||
MODIFY_DIVES(selectedDives, EDIT_VALUE(rating));
|
||||
if (displayed_dive.visibility != cd->visibility)
|
||||
|
@ -1343,13 +1344,12 @@ void MainTab::on_diveTripLocation_textEdited(const QString& text)
|
|||
}
|
||||
}
|
||||
|
||||
void MainTab::on_suit_textChanged(const QString &text)
|
||||
void MainTab::on_suit_editingFinished()
|
||||
{
|
||||
if (editMode == IGNORE || acceptingEdit == true)
|
||||
if (editMode == IGNORE || acceptingEdit == true || !current_dive)
|
||||
return;
|
||||
free(displayed_dive.suit);
|
||||
displayed_dive.suit = copy_qstring(text);
|
||||
markChangedWidget(ui.suit);
|
||||
|
||||
Command::editSuit(getSelectedDivesCurrentLast(), ui.suit->text(), QString(current_dive->suit));
|
||||
}
|
||||
|
||||
void MainTab::on_notes_textChanged()
|
||||
|
|
|
@ -76,7 +76,7 @@ slots:
|
|||
void on_location_textChanged();
|
||||
void on_divemaster_textChanged();
|
||||
void on_buddy_textChanged();
|
||||
void on_suit_textChanged(const QString &text);
|
||||
void on_suit_editingFinished();
|
||||
void on_diveTripLocation_textEdited(const QString& text);
|
||||
void on_notes_textChanged();
|
||||
void on_notes_editingFinished();
|
||||
|
|
Loading…
Add table
Reference in a new issue