mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 06:15:26 +00:00
undo: add event removal undo command
This was a trivial copy & past of the event-adding undo command with a switch of the undo() and redo() actions. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
ab8e317b28
commit
3d511b069f
5 changed files with 49 additions and 7 deletions
|
@ -349,4 +349,9 @@ void renameEvent(struct dive *d, int dcNr, struct event *ev, const char *name)
|
|||
execute(new RenameEvent(d, dcNr, ev, name));
|
||||
}
|
||||
|
||||
void removeEvent(struct dive *d, int dcNr, struct event *ev)
|
||||
{
|
||||
execute(new RemoveEvent(d, dcNr, ev));
|
||||
}
|
||||
|
||||
} // namespace Command
|
||||
|
|
|
@ -110,6 +110,7 @@ void addEventBookmark(struct dive *d, int dcNr, int seconds);
|
|||
void addEventDivemodeSwitch(struct dive *d, int dcNr, int seconds, int divemode);
|
||||
void addEventSetpointChange(struct dive *d, int dcNr, int seconds, pressure_t pO2);
|
||||
void renameEvent(struct dive *d, int dcNr, struct event *ev, const char *name);
|
||||
void removeEvent(struct dive *d, int dcNr, struct event *ev);
|
||||
|
||||
} // namespace Command
|
||||
|
||||
|
|
|
@ -97,4 +97,30 @@ void RenameEvent::undoit()
|
|||
redoit();
|
||||
}
|
||||
|
||||
RemoveEvent::RemoveEvent(struct dive *d, int dcNr, struct event *ev) : EventBase(d, dcNr),
|
||||
eventToRemove(ev)
|
||||
{
|
||||
setText(tr("Remove %1 event").arg(ev->name));
|
||||
}
|
||||
|
||||
bool RemoveEvent::workToBeDone()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void RemoveEvent::redoit()
|
||||
{
|
||||
struct divecomputer *dc = get_dive_dc(d, dcNr);
|
||||
remove_event_from_dc(dc, eventToRemove);
|
||||
eventToAdd.reset(eventToRemove); // take ownership of event
|
||||
eventToRemove = nullptr;
|
||||
}
|
||||
|
||||
void RemoveEvent::undoit()
|
||||
{
|
||||
struct divecomputer *dc = get_dive_dc(d, dcNr);
|
||||
eventToRemove = eventToAdd.get();
|
||||
add_event_to_dc(dc, eventToAdd.release()); // return ownership to backend
|
||||
}
|
||||
|
||||
} // namespace Command
|
||||
|
|
|
@ -70,6 +70,18 @@ private:
|
|||
event *eventToRemove; // for undo and redo
|
||||
};
|
||||
|
||||
class RemoveEvent : public EventBase {
|
||||
public:
|
||||
RemoveEvent(struct dive *d, int dcNr, struct event *ev);
|
||||
private:
|
||||
bool workToBeDone() override;
|
||||
void undoit() override;
|
||||
void redoit() override;
|
||||
|
||||
OwningEventPtr eventToAdd; // for undo
|
||||
event *eventToRemove; // for redo
|
||||
};
|
||||
|
||||
} // namespace Command
|
||||
|
||||
#endif // COMMAND_EVENT_H
|
||||
|
|
|
@ -1602,17 +1602,15 @@ static event *find_event(const struct event *ev)
|
|||
|
||||
void ProfileWidget2::removeEvent(DiveEventItem *item)
|
||||
{
|
||||
struct event *event = item->getEvent();
|
||||
struct event *event = find_event(item->getEvent());
|
||||
if (!event)
|
||||
return;
|
||||
|
||||
if (QMessageBox::question(this, TITLE_OR_TEXT(
|
||||
tr("Remove the selected event?"),
|
||||
tr("%1 @ %2:%3").arg(event->name).arg(event->time.seconds / 60).arg(event->time.seconds % 60, 2, 10, QChar('0'))),
|
||||
QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok) {
|
||||
remove_event(event);
|
||||
invalidate_dive_cache(current_dive);
|
||||
mark_divelist_changed(true);
|
||||
replot();
|
||||
}
|
||||
QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok)
|
||||
Command::removeEvent(current_dive, dc_number, event);
|
||||
}
|
||||
|
||||
void ProfileWidget2::addBookmark(int seconds)
|
||||
|
|
Loading…
Add table
Reference in a new issue