diff --git a/core/event.c b/core/event.c index c3ff36460..1e296be93 100644 --- a/core/event.c +++ b/core/event.c @@ -80,7 +80,7 @@ struct event *create_event(unsigned int time, int type, int flags, int value, co break; } - remember_event_type(name, flags); + remember_event_type(ev); return ev; } diff --git a/core/eventtype.cpp b/core/eventtype.cpp index 78afac1f3..90c1c7b09 100644 --- a/core/eventtype.cpp +++ b/core/eventtype.cpp @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 #include "eventtype.h" +#include "event.h" #include "subsurface-string.h" #include @@ -10,6 +11,10 @@ struct event_type { std::string name; int flags; bool plot; + event_type(const struct event *ev) + : name(ev->name), flags(ev->flags), plot(true) + { + } }; static std::vector event_types; @@ -24,24 +29,25 @@ extern "C" void clear_event_types() 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; - 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; - 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; } -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()) it->plot = false; } diff --git a/core/eventtype.h b/core/eventtype.h index e90777115..2ccba1c20 100644 --- a/core/eventtype.h +++ b/core/eventtype.h @@ -8,9 +8,9 @@ extern "C" { #endif extern void clear_event_types(void); -extern void remember_event_type(const char *eventname, const int flags); -extern bool is_event_type_hidden(const char *eventname, const int flags); -extern void hide_event_type(const char *eventname, const int flags); +extern void remember_event_type(const struct event *ev); +extern bool is_event_type_hidden(const struct event *ev); +extern void hide_event_type(const struct event *ev); extern void show_all_event_types(); extern bool any_event_types_hidden(); diff --git a/profile-widget/diveeventitem.cpp b/profile-widget/diveeventitem.cpp index 3e24c0a28..9b2b8213b 100644 --- a/profile-widget/diveeventitem.cpp +++ b/profile-widget/diveeventitem.cpp @@ -224,11 +224,6 @@ bool DiveEventItem::isInteresting(const struct dive *d, const struct divecompute return true; } -bool DiveEventItem::shouldBeHidden() -{ - return is_event_type_hidden(ev->name, ev->flags); -} - void DiveEventItem::recalculatePos() { if (!ev) @@ -238,7 +233,7 @@ void DiveEventItem::recalculatePos() hide(); return; } - setVisible(!shouldBeHidden()); + setVisible(!is_event_type_hidden(ev)); double x = hAxis->posAtValue(ev->time.seconds); double y = vAxis->posAtValue(depth); setPos(x, y); diff --git a/profile-widget/diveeventitem.h b/profile-widget/diveeventitem.h index d340f9cb9..c2a453a8f 100644 --- a/profile-widget/diveeventitem.h +++ b/profile-widget/diveeventitem.h @@ -21,7 +21,6 @@ public: void eventVisibilityChanged(const QString &eventName, bool visible); void setVerticalAxis(DiveCartesianAxis *axis, int speed); void setHorizontalAxis(DiveCartesianAxis *axis); - bool shouldBeHidden(); static bool isInteresting(const struct dive *d, const struct divecomputer *dc, const struct event *ev, const struct plot_info &pi, int firstSecond, int lastSecond); diff --git a/profile-widget/profilewidget2.cpp b/profile-widget/profilewidget2.cpp index 85f2b7f30..400e0eec8 100644 --- a/profile-widget/profilewidget2.cpp +++ b/profile-widget/profilewidget2.cpp @@ -702,7 +702,7 @@ void ProfileWidget2::hideSimilarEvents(DiveEventItem *item) const struct event *event = item->getEvent(); if (!empty_string(event->name)) { - hide_event_type(event->name, event->flags); + hide_event_type(event); replot(); }