subsurface/commands/command_event.h
Berthold Stoeger ab8e317b28 undo: implement renaming of events
There is a slight complexity here owing to the fact that the profile
works on a copy of the current dive: We get a copy of the event and
have to search for the original event in the current dive. This
could be done in the undo command. Nevertheless, here we do it in
the profile so that when in the future the profile can work on a
non-copied dive we can simply remove this function.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:35 +02:00

75 lines
2.1 KiB
C++

// SPDX-License-Identifier: GPL-2.0
// Note: this header file is used by the undo-machinery and should not be included elsewhere.
#ifndef COMMAND_EVENT_H
#define COMMAND_EVENT_H
#include "command_base.h"
// We put everything in a namespace, so that we can shorten names without polluting the global namespace
namespace Command {
// Events are a strange thing: they contain there own description which means
// that on changing the description a new object must be allocated. Moreover,
// it means that these objects can't be collected in a table.
// Therefore, the undo commands work on events as they do with dives: using
// owning pointers. See comments in command_base.h
class EventBase : public Base {
protected:
EventBase(struct dive *d, int dcNr);
void undo() override;
void redo() override;
virtual void redoit() = 0;
virtual void undoit() = 0;
// Note: we store dive and the divecomputer-number instead of a pointer to the divecomputer.
// Since one divecomputer is integrated into the dive structure, pointers to divecomputers
// are probably not stable.
struct dive *d;
int dcNr;
};
class AddEventBase : public EventBase {
public:
AddEventBase(struct dive *d, int dcNr, struct event *ev); // Takes ownership of event!
private:
bool workToBeDone() override;
void undoit() override;
void redoit() override;
OwningEventPtr eventToAdd; // for redo
event *eventToRemove; // for undo
};
class AddEventBookmark : public AddEventBase {
public:
AddEventBookmark(struct dive *d, int dcNr, int seconds);
};
class AddEventDivemodeSwitch : public AddEventBase {
public:
AddEventDivemodeSwitch(struct dive *d, int dcNr, int seconds, int divemode);
};
class AddEventSetpointChange : public AddEventBase {
public:
AddEventSetpointChange(struct dive *d, int dcNr, int seconds, pressure_t pO2);
};
class RenameEvent : public EventBase {
public:
RenameEvent(struct dive *d, int dcNr, struct event *ev, const char *name);
private:
bool workToBeDone() override;
void undoit() override;
void redoit() override;
OwningEventPtr eventToAdd; // for undo and redo
event *eventToRemove; // for undo and redo
};
} // namespace Command
#endif // COMMAND_EVENT_H