2020-03-03 21:34:50 +00:00
|
|
|
// 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"
|
2021-01-11 15:52:02 +00:00
|
|
|
#include "core/divemode.h"
|
2020-03-03 21:34:50 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
|
|
2020-03-04 16:35:02 +00:00
|
|
|
class EventBase : public Base {
|
|
|
|
protected:
|
|
|
|
EventBase(struct dive *d, int dcNr);
|
2020-03-03 21:34:50 +00:00
|
|
|
void undo() override;
|
|
|
|
void redo() override;
|
2020-03-04 16:35:02 +00:00
|
|
|
virtual void redoit() = 0;
|
|
|
|
virtual void undoit() = 0;
|
2020-03-03 21:34:50 +00:00
|
|
|
|
|
|
|
// 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;
|
2020-03-05 22:10:44 +00:00
|
|
|
private:
|
|
|
|
void updateDive();
|
2020-03-04 16:35:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class AddEventBase : public EventBase {
|
|
|
|
public:
|
|
|
|
AddEventBase(struct dive *d, int dcNr, struct event *ev); // Takes ownership of event!
|
2021-01-11 15:52:02 +00:00
|
|
|
protected:
|
2020-03-04 16:35:02 +00:00
|
|
|
void undoit() override;
|
|
|
|
void redoit() override;
|
2021-01-11 15:52:02 +00:00
|
|
|
private:
|
|
|
|
bool workToBeDone() override;
|
2020-03-03 21:34:50 +00:00
|
|
|
|
|
|
|
OwningEventPtr eventToAdd; // for redo
|
|
|
|
event *eventToRemove; // for undo
|
|
|
|
};
|
|
|
|
|
|
|
|
class AddEventBookmark : public AddEventBase {
|
|
|
|
public:
|
|
|
|
AddEventBookmark(struct dive *d, int dcNr, int seconds);
|
|
|
|
};
|
|
|
|
|
2020-03-03 21:54:54 +00:00
|
|
|
class AddEventDivemodeSwitch : public AddEventBase {
|
|
|
|
public:
|
|
|
|
AddEventDivemodeSwitch(struct dive *d, int dcNr, int seconds, int divemode);
|
|
|
|
};
|
|
|
|
|
2020-03-03 22:31:46 +00:00
|
|
|
class AddEventSetpointChange : public AddEventBase {
|
|
|
|
public:
|
|
|
|
AddEventSetpointChange(struct dive *d, int dcNr, int seconds, pressure_t pO2);
|
2021-01-11 15:52:02 +00:00
|
|
|
private:
|
|
|
|
divemode_t divemode; // Wonderful: this may change the divemode of the dive to CCR
|
|
|
|
void undoit() override;
|
|
|
|
void redoit() override;
|
2020-03-03 22:31:46 +00:00
|
|
|
};
|
|
|
|
|
2020-03-04 17:13:02 +00:00
|
|
|
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
|
|
|
|
};
|
|
|
|
|
2020-03-04 17:25:47 +00:00
|
|
|
class RemoveEvent : public EventBase {
|
|
|
|
public:
|
|
|
|
RemoveEvent(struct dive *d, int dcNr, struct event *ev);
|
|
|
|
private:
|
|
|
|
bool workToBeDone() override;
|
|
|
|
void undoit() override;
|
|
|
|
void redoit() override;
|
2020-03-06 22:20:58 +00:00
|
|
|
void post() const; // Called to fix up dives should a gas-change have happened.
|
2020-03-04 17:25:47 +00:00
|
|
|
|
|
|
|
OwningEventPtr eventToAdd; // for undo
|
|
|
|
event *eventToRemove; // for redo
|
2020-03-06 22:20:58 +00:00
|
|
|
int cylinder; // affected cylinder (if removing gas switch). <0: not a gas switch.
|
2020-03-04 17:25:47 +00:00
|
|
|
};
|
|
|
|
|
2020-03-04 20:10:05 +00:00
|
|
|
class AddGasSwitch : public EventBase {
|
|
|
|
public:
|
|
|
|
AddGasSwitch(struct dive *d, int dcNr, int seconds, int tank);
|
|
|
|
private:
|
|
|
|
bool workToBeDone() override;
|
|
|
|
void undoit() override;
|
|
|
|
void redoit() override;
|
|
|
|
|
|
|
|
std::vector<int> cylinders; // cylinders that are modified
|
|
|
|
std::vector<OwningEventPtr> eventsToAdd;
|
|
|
|
std::vector<event *> eventsToRemove;
|
|
|
|
};
|
|
|
|
|
2020-03-03 21:34:50 +00:00
|
|
|
} // namespace Command
|
|
|
|
|
|
|
|
#endif // COMMAND_EVENT_H
|