mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
core: fold event-related functions into event class
Not strictly necessary, but more idiomatic C++ and less polution of the global namespace. This one is so trivial that there seems to be no reason not to do it. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
c27314d603
commit
e237f29fb2
12 changed files with 28 additions and 29 deletions
|
@ -130,7 +130,7 @@ void add_gas_switch_event(struct dive *dive, struct divecomputer *dc, int second
|
||||||
|
|
||||||
struct gasmix get_gasmix_from_event(const struct dive *dive, const struct event &ev)
|
struct gasmix get_gasmix_from_event(const struct dive *dive, const struct event &ev)
|
||||||
{
|
{
|
||||||
if (event_is_gaschange(ev)) {
|
if (ev.is_gaschange()) {
|
||||||
int index = ev.gas.index;
|
int index = ev.gas.index;
|
||||||
// FIXME: The planner uses one past cylinder-count to signify "surface air". Remove in due course.
|
// FIXME: The planner uses one past cylinder-count to signify "surface air". Remove in due course.
|
||||||
if (index == dive->cylinders.nr)
|
if (index == dive->cylinders.nr)
|
||||||
|
@ -311,7 +311,7 @@ void copy_events_until(const struct dive *sd, struct dive *dd, int dcNr, int tim
|
||||||
|
|
||||||
for (const auto &ev: s->events) {
|
for (const auto &ev: s->events) {
|
||||||
// Don't add events the planner knows about
|
// Don't add events the planner knows about
|
||||||
if (ev.time.seconds < time && !event_is_gaschange(ev) && !event_is_divemodechange(ev))
|
if (ev.time.seconds < time && !ev.is_gaschange() && !ev.is_divemodechange())
|
||||||
add_event(d, ev.time.seconds, ev.type, ev.flags, ev.value, ev.name);
|
add_event(d, ev.time.seconds, ev.type, ev.flags, ev.value, ev.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1051,7 +1051,7 @@ static bool validate_gaschange(struct dive *dive, struct event &event)
|
||||||
/* Clean up event, return true if event is ok, false if it should be dropped as bogus */
|
/* Clean up event, return true if event is ok, false if it should be dropped as bogus */
|
||||||
static bool validate_event(struct dive *dive, struct event &event)
|
static bool validate_event(struct dive *dive, struct event &event)
|
||||||
{
|
{
|
||||||
if (event_is_gaschange(event))
|
if (event.is_gaschange())
|
||||||
return validate_gaschange(dive, event);
|
return validate_gaschange(dive, event);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1483,7 +1483,7 @@ pick_b:
|
||||||
* If that's a gas-change that matches the previous
|
* If that's a gas-change that matches the previous
|
||||||
* gas change, we'll just skip it
|
* gas change, we'll just skip it
|
||||||
*/
|
*/
|
||||||
if (event_is_gaschange(*pick)) {
|
if (pick->is_gaschange()) {
|
||||||
if (last_gas && same_gas(pick, last_gas))
|
if (last_gas && same_gas(pick, last_gas))
|
||||||
continue;
|
continue;
|
||||||
last_gas = pick;
|
last_gas = pick;
|
||||||
|
@ -1567,7 +1567,7 @@ static void renumber_last_sample(struct divecomputer *dc, const int mapping[])
|
||||||
|
|
||||||
static void event_renumber(struct event &ev, const int mapping[])
|
static void event_renumber(struct event &ev, const int mapping[])
|
||||||
{
|
{
|
||||||
if (!event_is_gaschange(ev))
|
if (!ev.is_gaschange())
|
||||||
return;
|
return;
|
||||||
if (ev.gas.index < 0)
|
if (ev.gas.index < 0)
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -49,15 +49,14 @@ event::~event()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool event_is_gaschange(const struct event &ev)
|
bool event::is_gaschange() const
|
||||||
{
|
{
|
||||||
return ev.type == SAMPLE_EVENT_GASCHANGE ||
|
return type == SAMPLE_EVENT_GASCHANGE || type == SAMPLE_EVENT_GASCHANGE2;
|
||||||
ev.type == SAMPLE_EVENT_GASCHANGE2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool event_is_divemodechange(const struct event &ev)
|
bool event::is_divemodechange() const
|
||||||
{
|
{
|
||||||
return ev.name == "modechange";
|
return name == "modechange";
|
||||||
}
|
}
|
||||||
|
|
||||||
bool event::operator==(const event &b) const
|
bool event::operator==(const event &b) const
|
||||||
|
@ -66,9 +65,9 @@ bool event::operator==(const event &b) const
|
||||||
std::tie(b.time.seconds, b.type, b.flags, b.value, b.name);
|
std::tie(b.time.seconds, b.type, b.flags, b.value, b.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern enum event_severity get_event_severity(const struct event &ev)
|
enum event_severity event::get_severity() const
|
||||||
{
|
{
|
||||||
switch (ev.flags & SAMPLE_FLAGS_SEVERITY_MASK) {
|
switch (flags & SAMPLE_FLAGS_SEVERITY_MASK) {
|
||||||
case SAMPLE_FLAGS_SEVERITY_INFO:
|
case SAMPLE_FLAGS_SEVERITY_INFO:
|
||||||
return EVENT_SEVERITY_INFO;
|
return EVENT_SEVERITY_INFO;
|
||||||
case SAMPLE_FLAGS_SEVERITY_WARN:
|
case SAMPLE_FLAGS_SEVERITY_WARN:
|
||||||
|
|
|
@ -48,6 +48,10 @@ struct event {
|
||||||
~event();
|
~event();
|
||||||
|
|
||||||
bool operator==(const event &b2) const;
|
bool operator==(const event &b2) const;
|
||||||
|
|
||||||
|
bool is_gaschange() const;
|
||||||
|
bool is_divemodechange() const;
|
||||||
|
event_severity get_severity() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
class event_loop
|
class event_loop
|
||||||
|
@ -83,10 +87,6 @@ public:
|
||||||
divemode_t next(int time);
|
divemode_t next(int time);
|
||||||
};
|
};
|
||||||
|
|
||||||
extern bool event_is_gaschange(const struct event &ev);
|
|
||||||
extern bool event_is_divemodechange(const struct event &ev);
|
|
||||||
extern enum event_severity get_event_severity(const struct event &ev);
|
|
||||||
|
|
||||||
extern const struct event *get_first_event(const struct divecomputer &dc, const std::string &name);
|
extern const struct event *get_first_event(const struct divecomputer &dc, const std::string &name);
|
||||||
extern struct event *get_first_event(struct divecomputer &dc, const std::string &name);
|
extern struct event *get_first_event(struct divecomputer &dc, const std::string &name);
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ struct event_type {
|
||||||
bool plot;
|
bool plot;
|
||||||
event_type(const struct event *ev) :
|
event_type(const struct event *ev) :
|
||||||
name(ev->name),
|
name(ev->name),
|
||||||
severity(get_event_severity(*ev)),
|
severity(ev->get_severity()),
|
||||||
plot(true)
|
plot(true)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -108,7 +108,7 @@ QString event_type_name(const event &ev)
|
||||||
return QString();
|
return QString();
|
||||||
|
|
||||||
QString name = QString::fromStdString(ev.name);
|
QString name = QString::fromStdString(ev.name);
|
||||||
return event_type_name(std::move(name), get_event_severity(ev));
|
return event_type_name(std::move(name), ev.get_severity());
|
||||||
}
|
}
|
||||||
|
|
||||||
QString event_type_name(int idx)
|
QString event_type_name(int idx)
|
||||||
|
|
|
@ -363,7 +363,7 @@ static void handle_event(struct divecomputer *dc, const struct sample &sample, d
|
||||||
time += sample.time.seconds;
|
time += sample.time.seconds;
|
||||||
|
|
||||||
ev = add_event(dc, time, type, value.event.flags, value.event.value, name);
|
ev = add_event(dc, time, type, value.event.flags, value.event.value, name);
|
||||||
if (event_is_gaschange(*ev) && ev->gas.index >= 0)
|
if (ev->is_gaschange() && ev->gas.index >= 0)
|
||||||
current_gas_index = ev->gas.index;
|
current_gas_index = ev->gas.index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -868,7 +868,7 @@ static void parse_dc_event(char *line, struct git_parser_state *state)
|
||||||
if (p.ev.time.seconds == 0 && p.ev.type == SAMPLE_EVENT_PO2 && p.ev.value && state->active_dc->divemode==OC)
|
if (p.ev.time.seconds == 0 && p.ev.type == SAMPLE_EVENT_PO2 && p.ev.value && state->active_dc->divemode==OC)
|
||||||
state->active_dc->divemode = CCR;
|
state->active_dc->divemode = CCR;
|
||||||
|
|
||||||
if (event_is_gaschange(*ev)) {
|
if (ev->is_gaschange()) {
|
||||||
/*
|
/*
|
||||||
* We subtract one here because "0" is "no index",
|
* We subtract one here because "0" is "no index",
|
||||||
* and the parsing will add one for actual cylinder
|
* and the parsing will add one for actual cylinder
|
||||||
|
|
|
@ -91,7 +91,7 @@ void event_end(struct parser_state *state)
|
||||||
if (ev.time.seconds == 0 && ev.type == SAMPLE_EVENT_PO2 && ev.value && dc->divemode==OC)
|
if (ev.time.seconds == 0 && ev.type == SAMPLE_EVENT_PO2 && ev.value && dc->divemode==OC)
|
||||||
dc->divemode = CCR;
|
dc->divemode = CCR;
|
||||||
|
|
||||||
if (event_is_gaschange(ev)) {
|
if (ev.is_gaschange()) {
|
||||||
/* See try_to_fill_event() on why the filled-in index is one too big */
|
/* See try_to_fill_event() on why the filled-in index is one too big */
|
||||||
ev.gas.index = state->cur_event.gas.index-1;
|
ev.gas.index = state->cur_event.gas.index-1;
|
||||||
if (state->cur_event.gas.mix.o2.permille || state->cur_event.gas.mix.he.permille)
|
if (state->cur_event.gas.mix.o2.permille || state->cur_event.gas.mix.he.permille)
|
||||||
|
|
|
@ -394,7 +394,7 @@ static void save_one_event(struct membuffer *b, struct dive *dive, const struct
|
||||||
else
|
else
|
||||||
show_index(b, ev.value, "value=", "");
|
show_index(b, ev.value, "value=", "");
|
||||||
show_utf8(b, " name=", ev.name.c_str(), "");
|
show_utf8(b, " name=", ev.name.c_str(), "");
|
||||||
if (event_is_gaschange(ev)) {
|
if (ev.is_gaschange()) {
|
||||||
struct gasmix mix = get_gasmix_from_event(dive, ev);
|
struct gasmix mix = get_gasmix_from_event(dive, ev);
|
||||||
if (ev.gas.index >= 0)
|
if (ev.gas.index >= 0)
|
||||||
show_integer(b, ev.gas.index, "cylinder=", "");
|
show_integer(b, ev.gas.index, "cylinder=", "");
|
||||||
|
|
|
@ -363,7 +363,7 @@ static void save_one_event(struct membuffer *b, struct dive *dive, const struct
|
||||||
else
|
else
|
||||||
show_index(b, ev.value, "value='", "'");
|
show_index(b, ev.value, "value='", "'");
|
||||||
show_utf8(b, ev.name.c_str(), " name='", "'", 1);
|
show_utf8(b, ev.name.c_str(), " name='", "'", 1);
|
||||||
if (event_is_gaschange(ev)) {
|
if (ev.is_gaschange()) {
|
||||||
struct gasmix mix = get_gasmix_from_event(dive, ev);
|
struct gasmix mix = get_gasmix_from_event(dive, ev);
|
||||||
if (ev.gas.index >= 0)
|
if (ev.gas.index >= 0)
|
||||||
show_integer(b, ev.gas.index, "cylinder='", "'");
|
show_integer(b, ev.gas.index, "cylinder='", "'");
|
||||||
|
|
|
@ -39,7 +39,7 @@ DiveEventItem::~DiveEventItem()
|
||||||
|
|
||||||
void DiveEventItem::setupPixmap(struct gasmix lastgasmix, const DivePixmaps &pixmaps)
|
void DiveEventItem::setupPixmap(struct gasmix lastgasmix, const DivePixmaps &pixmaps)
|
||||||
{
|
{
|
||||||
event_severity severity = get_event_severity(ev);
|
event_severity severity = ev.get_severity();
|
||||||
if (ev.name.empty()) {
|
if (ev.name.empty()) {
|
||||||
setPixmap(pixmaps.warning);
|
setPixmap(pixmaps.warning);
|
||||||
} else if (same_string_caseinsensitive(ev.name.c_str(), "modechange")) {
|
} else if (same_string_caseinsensitive(ev.name.c_str(), "modechange")) {
|
||||||
|
@ -50,7 +50,7 @@ void DiveEventItem::setupPixmap(struct gasmix lastgasmix, const DivePixmaps &pix
|
||||||
} else if (ev.type == SAMPLE_EVENT_BOOKMARK) {
|
} else if (ev.type == SAMPLE_EVENT_BOOKMARK) {
|
||||||
setPixmap(pixmaps.bookmark);
|
setPixmap(pixmaps.bookmark);
|
||||||
setOffset(QPointF(0.0, -pixmap().height()));
|
setOffset(QPointF(0.0, -pixmap().height()));
|
||||||
} else if (event_is_gaschange(ev)) {
|
} else if (ev.is_gaschange()) {
|
||||||
struct gasmix mix = get_gasmix_from_event(dive, ev);
|
struct gasmix mix = get_gasmix_from_event(dive, ev);
|
||||||
struct icd_data icd_data;
|
struct icd_data icd_data;
|
||||||
bool icd = isobaric_counterdiffusion(lastgasmix, mix, &icd_data);
|
bool icd = isobaric_counterdiffusion(lastgasmix, mix, &icd_data);
|
||||||
|
@ -121,7 +121,7 @@ void DiveEventItem::setupToolTipString(struct gasmix lastgasmix)
|
||||||
int value = ev.value;
|
int value = ev.value;
|
||||||
int type = ev.type;
|
int type = ev.type;
|
||||||
|
|
||||||
if (event_is_gaschange(ev)) {
|
if (ev.is_gaschange()) {
|
||||||
struct icd_data icd_data;
|
struct icd_data icd_data;
|
||||||
struct gasmix mix = get_gasmix_from_event(dive, ev);
|
struct gasmix mix = get_gasmix_from_event(dive, ev);
|
||||||
name += ": ";
|
name += ": ";
|
||||||
|
|
|
@ -559,7 +559,7 @@ void ProfileScene::plotDive(const struct dive *dIn, int dcIn, DivePlannerPointsM
|
||||||
if (event.name.empty() ||
|
if (event.name.empty() ||
|
||||||
!(event.name == "heading" ||
|
!(event.name == "heading" ||
|
||||||
(event.name == "SP change" && event.time.seconds == 0) ||
|
(event.name == "SP change" && event.time.seconds == 0) ||
|
||||||
event_is_gaschange(event) ||
|
event.is_gaschange() ||
|
||||||
event.type == SAMPLE_EVENT_BOOKMARK))
|
event.type == SAMPLE_EVENT_BOOKMARK))
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -570,7 +570,7 @@ void ProfileScene::plotDive(const struct dive *dIn, int dcIn, DivePlannerPointsM
|
||||||
addItem(item);
|
addItem(item);
|
||||||
eventItems.push_back(item);
|
eventItems.push_back(item);
|
||||||
}
|
}
|
||||||
if (event_is_gaschange(event))
|
if (event.is_gaschange())
|
||||||
lastgasmix = get_gasmix_from_event(d, event);
|
lastgasmix = get_gasmix_from_event(d, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -559,7 +559,7 @@ void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event)
|
||||||
DiveEventItem *item = dynamic_cast<DiveEventItem *>(sceneItem);
|
DiveEventItem *item = dynamic_cast<DiveEventItem *>(sceneItem);
|
||||||
|
|
||||||
// Add or edit Gas Change
|
// Add or edit Gas Change
|
||||||
if (d && item && event_is_gaschange(item->ev)) {
|
if (d && item && item->ev.is_gaschange()) {
|
||||||
int eventTime = item->ev.time.seconds;
|
int eventTime = item->ev.time.seconds;
|
||||||
QMenu *gasChange = m.addMenu(tr("Edit Gas Change"));
|
QMenu *gasChange = m.addMenu(tr("Edit Gas Change"));
|
||||||
for (int i = 0; i < d->cylinders.nr; i++) {
|
for (int i = 0; i < d->cylinders.nr; i++) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue