core: pass event to event_type functions

Instead of passing name / flag pairs to event_type functions,
pass a pointer to the event. This hides implementation details.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-02-14 11:16:34 +01:00 committed by Dirk Hohndel
parent d3c9cb14bf
commit 6ad7e577f1
6 changed files with 20 additions and 20 deletions

View file

@ -80,7 +80,7 @@ struct event *create_event(unsigned int time, int type, int flags, int value, co
break; break;
} }
remember_event_type(name, flags); remember_event_type(ev);
return ev; return ev;
} }

View file

@ -1,5 +1,6 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#include "eventtype.h" #include "eventtype.h"
#include "event.h"
#include "subsurface-string.h" #include "subsurface-string.h"
#include <string> #include <string>
@ -10,6 +11,10 @@ struct event_type {
std::string name; std::string name;
int flags; int flags;
bool plot; bool plot;
event_type(const struct event *ev)
: name(ev->name), flags(ev->flags), plot(true)
{
}
}; };
static std::vector<event_type> event_types; static std::vector<event_type> event_types;
@ -24,24 +29,25 @@ extern "C" void clear_event_types()
event_types.clear(); event_types.clear();
} }
extern "C" void remember_event_type(const char *eventname, const int flags) extern "C" void remember_event_type(const struct event *ev)
{ {
if (empty_string(eventname)) if (empty_string(ev->name))
return; return;
if (std::find(event_types.begin(), event_types.end(), event_type{ eventname, flags }) != event_types.end()) event_type type(ev);
if (std::find(event_types.begin(), event_types.end(), type) != event_types.end())
return; return;
event_types.push_back({ eventname, flags, true }); event_types.push_back(std::move(type));
} }
extern "C" bool is_event_type_hidden(const char *eventname, const int flags) extern "C" bool is_event_type_hidden(const struct event *ev)
{ {
auto it = std::find(event_types.begin(), event_types.end(), event_type{ eventname, flags }); auto it = std::find(event_types.begin(), event_types.end(), ev);
return it != event_types.end() && !it->plot; return it != event_types.end() && !it->plot;
} }
extern "C" void hide_event_type(const char *eventname, const int flags) extern "C" void hide_event_type(const struct event *ev)
{ {
auto it = std::find(event_types.begin(), event_types.end(), event_type{ eventname, flags }); auto it = std::find(event_types.begin(), event_types.end(), ev);
if (it != event_types.end()) if (it != event_types.end())
it->plot = false; it->plot = false;
} }

View file

@ -8,9 +8,9 @@ extern "C" {
#endif #endif
extern void clear_event_types(void); extern void clear_event_types(void);
extern void remember_event_type(const char *eventname, const int flags); extern void remember_event_type(const struct event *ev);
extern bool is_event_type_hidden(const char *eventname, const int flags); extern bool is_event_type_hidden(const struct event *ev);
extern void hide_event_type(const char *eventname, const int flags); extern void hide_event_type(const struct event *ev);
extern void show_all_event_types(); extern void show_all_event_types();
extern bool any_event_types_hidden(); extern bool any_event_types_hidden();

View file

@ -224,11 +224,6 @@ bool DiveEventItem::isInteresting(const struct dive *d, const struct divecompute
return true; return true;
} }
bool DiveEventItem::shouldBeHidden()
{
return is_event_type_hidden(ev->name, ev->flags);
}
void DiveEventItem::recalculatePos() void DiveEventItem::recalculatePos()
{ {
if (!ev) if (!ev)
@ -238,7 +233,7 @@ void DiveEventItem::recalculatePos()
hide(); hide();
return; return;
} }
setVisible(!shouldBeHidden()); setVisible(!is_event_type_hidden(ev));
double x = hAxis->posAtValue(ev->time.seconds); double x = hAxis->posAtValue(ev->time.seconds);
double y = vAxis->posAtValue(depth); double y = vAxis->posAtValue(depth);
setPos(x, y); setPos(x, y);

View file

@ -21,7 +21,6 @@ public:
void eventVisibilityChanged(const QString &eventName, bool visible); void eventVisibilityChanged(const QString &eventName, bool visible);
void setVerticalAxis(DiveCartesianAxis *axis, int speed); void setVerticalAxis(DiveCartesianAxis *axis, int speed);
void setHorizontalAxis(DiveCartesianAxis *axis); void setHorizontalAxis(DiveCartesianAxis *axis);
bool shouldBeHidden();
static bool isInteresting(const struct dive *d, const struct divecomputer *dc, static bool isInteresting(const struct dive *d, const struct divecomputer *dc,
const struct event *ev, const struct plot_info &pi, const struct event *ev, const struct plot_info &pi,
int firstSecond, int lastSecond); int firstSecond, int lastSecond);

View file

@ -702,7 +702,7 @@ void ProfileWidget2::hideSimilarEvents(DiveEventItem *item)
const struct event *event = item->getEvent(); const struct event *event = item->getEvent();
if (!empty_string(event->name)) { if (!empty_string(event->name)) {
hide_event_type(event->name, event->flags); hide_event_type(event);
replot(); replot();
} }