2020-03-03 21:34:50 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
|
|
|
|
#include "command_event.h"
|
|
|
|
#include "core/dive.h"
|
|
|
|
#include "core/subsurface-qt/divelistnotifier.h"
|
|
|
|
#include "core/libdivecomputer.h"
|
2020-03-03 21:54:54 +00:00
|
|
|
#include "core/gettextfromc.h"
|
2020-03-03 21:34:50 +00:00
|
|
|
|
|
|
|
namespace Command {
|
|
|
|
|
2020-03-04 16:35:02 +00:00
|
|
|
EventBase::EventBase(struct dive *dIn, int dcNrIn) :
|
|
|
|
d(dIn), dcNr(dcNrIn)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void EventBase::redo()
|
|
|
|
{
|
|
|
|
redoit(); // Call actual function in base class
|
|
|
|
invalidate_dive_cache(d);
|
|
|
|
emit diveListNotifier.eventsChanged(d);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EventBase::undo()
|
|
|
|
{
|
|
|
|
undoit(); // Call actual function in base class
|
|
|
|
invalidate_dive_cache(d);
|
|
|
|
emit diveListNotifier.eventsChanged(d);
|
|
|
|
}
|
|
|
|
|
|
|
|
AddEventBase::AddEventBase(struct dive *d, int dcNr, struct event *ev) : EventBase(d, dcNr),
|
|
|
|
eventToAdd(ev)
|
2020-03-03 21:34:50 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AddEventBase::workToBeDone()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-03-04 16:35:02 +00:00
|
|
|
void AddEventBase::redoit()
|
2020-03-03 21:34:50 +00:00
|
|
|
{
|
|
|
|
struct divecomputer *dc = get_dive_dc(d, dcNr);
|
|
|
|
eventToRemove = eventToAdd.get();
|
|
|
|
add_event_to_dc(dc, eventToAdd.release()); // return ownership to backend
|
|
|
|
}
|
|
|
|
|
2020-03-04 16:35:02 +00:00
|
|
|
void AddEventBase::undoit()
|
2020-03-03 21:34:50 +00:00
|
|
|
{
|
|
|
|
struct divecomputer *dc = get_dive_dc(d, dcNr);
|
|
|
|
remove_event_from_dc(dc, eventToRemove);
|
|
|
|
eventToAdd.reset(eventToRemove); // take ownership of event
|
|
|
|
eventToRemove = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
AddEventBookmark::AddEventBookmark(struct dive *d, int dcNr, int seconds) :
|
|
|
|
AddEventBase(d, dcNr, create_event(seconds, SAMPLE_EVENT_BOOKMARK, 0, 0, "bookmark"))
|
|
|
|
{
|
|
|
|
setText(tr("Add bookmark"));
|
|
|
|
}
|
|
|
|
|
2020-03-03 21:54:54 +00:00
|
|
|
AddEventDivemodeSwitch::AddEventDivemodeSwitch(struct dive *d, int dcNr, int seconds, int divemode) :
|
|
|
|
AddEventBase(d, dcNr, create_event(seconds, SAMPLE_EVENT_BOOKMARK, 0, divemode, QT_TRANSLATE_NOOP("gettextFromC", "modechange")))
|
|
|
|
{
|
|
|
|
setText(tr("Add dive mode switch to %1").arg(gettextFromC::tr(divemode_text_ui[divemode])));
|
|
|
|
}
|
|
|
|
|
2020-03-03 22:31:46 +00:00
|
|
|
AddEventSetpointChange::AddEventSetpointChange(struct dive *d, int dcNr, int seconds, pressure_t pO2) :
|
|
|
|
AddEventBase(d, dcNr, create_event(seconds, SAMPLE_EVENT_PO2, 0, pO2.mbar, QT_TRANSLATE_NOOP("gettextFromC", "SP change")))
|
|
|
|
{
|
|
|
|
setText(tr("Add set point change")); // TODO: format pO2 value in bar or psi.
|
|
|
|
}
|
|
|
|
|
2020-03-03 21:34:50 +00:00
|
|
|
} // namespace Command
|