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)
|
||||
{
|
||||
if (event_is_gaschange(ev)) {
|
||||
if (ev.is_gaschange()) {
|
||||
int index = ev.gas.index;
|
||||
// FIXME: The planner uses one past cylinder-count to signify "surface air". Remove in due course.
|
||||
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) {
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
@ -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 */
|
||||
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 true;
|
||||
}
|
||||
|
@ -1483,7 +1483,7 @@ pick_b:
|
|||
* If that's a gas-change that matches the previous
|
||||
* gas change, we'll just skip it
|
||||
*/
|
||||
if (event_is_gaschange(*pick)) {
|
||||
if (pick->is_gaschange()) {
|
||||
if (last_gas && same_gas(pick, last_gas))
|
||||
continue;
|
||||
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[])
|
||||
{
|
||||
if (!event_is_gaschange(ev))
|
||||
if (!ev.is_gaschange())
|
||||
return;
|
||||
if (ev.gas.index < 0)
|
||||
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 ||
|
||||
ev.type == SAMPLE_EVENT_GASCHANGE2;
|
||||
return type == SAMPLE_EVENT_GASCHANGE || 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
|
||||
|
@ -66,9 +65,9 @@ bool event::operator==(const event &b) const
|
|||
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:
|
||||
return EVENT_SEVERITY_INFO;
|
||||
case SAMPLE_FLAGS_SEVERITY_WARN:
|
||||
|
|
|
@ -48,6 +48,10 @@ struct event {
|
|||
~event();
|
||||
|
||||
bool operator==(const event &b2) const;
|
||||
|
||||
bool is_gaschange() const;
|
||||
bool is_divemodechange() const;
|
||||
event_severity get_severity() const;
|
||||
};
|
||||
|
||||
class event_loop
|
||||
|
@ -83,10 +87,6 @@ public:
|
|||
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 struct event *get_first_event(struct divecomputer &dc, const std::string &name);
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ struct event_type {
|
|||
bool plot;
|
||||
event_type(const struct event *ev) :
|
||||
name(ev->name),
|
||||
severity(get_event_severity(*ev)),
|
||||
severity(ev->get_severity()),
|
||||
plot(true)
|
||||
{
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ QString event_type_name(const event &ev)
|
|||
return QString();
|
||||
|
||||
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)
|
||||
|
|
|
@ -363,7 +363,7 @@ static void handle_event(struct divecomputer *dc, const struct sample &sample, d
|
|||
time += sample.time.seconds;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
state->active_dc->divemode = CCR;
|
||||
|
||||
if (event_is_gaschange(*ev)) {
|
||||
if (ev->is_gaschange()) {
|
||||
/*
|
||||
* We subtract one here because "0" is "no index",
|
||||
* 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)
|
||||
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 */
|
||||
ev.gas.index = state->cur_event.gas.index-1;
|
||||
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
|
||||
show_index(b, ev.value, "value=", "");
|
||||
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);
|
||||
if (ev.gas.index >= 0)
|
||||
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
|
||||
show_index(b, ev.value, "value='", "'");
|
||||
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);
|
||||
if (ev.gas.index >= 0)
|
||||
show_integer(b, ev.gas.index, "cylinder='", "'");
|
||||
|
|
|
@ -39,7 +39,7 @@ DiveEventItem::~DiveEventItem()
|
|||
|
||||
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()) {
|
||||
setPixmap(pixmaps.warning);
|
||||
} 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) {
|
||||
setPixmap(pixmaps.bookmark);
|
||||
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 icd_data 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 type = ev.type;
|
||||
|
||||
if (event_is_gaschange(ev)) {
|
||||
if (ev.is_gaschange()) {
|
||||
struct icd_data icd_data;
|
||||
struct gasmix mix = get_gasmix_from_event(dive, ev);
|
||||
name += ": ";
|
||||
|
|
|
@ -559,7 +559,7 @@ void ProfileScene::plotDive(const struct dive *dIn, int dcIn, DivePlannerPointsM
|
|||
if (event.name.empty() ||
|
||||
!(event.name == "heading" ||
|
||||
(event.name == "SP change" && event.time.seconds == 0) ||
|
||||
event_is_gaschange(event) ||
|
||||
event.is_gaschange() ||
|
||||
event.type == SAMPLE_EVENT_BOOKMARK))
|
||||
continue;
|
||||
}
|
||||
|
@ -570,7 +570,7 @@ void ProfileScene::plotDive(const struct dive *dIn, int dcIn, DivePlannerPointsM
|
|||
addItem(item);
|
||||
eventItems.push_back(item);
|
||||
}
|
||||
if (event_is_gaschange(event))
|
||||
if (event.is_gaschange())
|
||||
lastgasmix = get_gasmix_from_event(d, event);
|
||||
}
|
||||
|
||||
|
|
|
@ -559,7 +559,7 @@ void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event)
|
|||
DiveEventItem *item = dynamic_cast<DiveEventItem *>(sceneItem);
|
||||
|
||||
// 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;
|
||||
QMenu *gasChange = m.addMenu(tr("Edit Gas Change"));
|
||||
for (int i = 0; i < d->cylinders.nr; i++) {
|
||||
|
|
Loading…
Add table
Reference in a new issue