From d3c9cb14bf4afdd5287008527b94494cbd65b47b Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Wed, 14 Feb 2024 10:59:13 +0100 Subject: [PATCH] core: rename eventname.* to eventtype.* This structure is used to hide events of a certain type. The type was inferred from its name, but now includes flags. So event_type is more appropriate. Signed-off-by: Berthold Stoeger --- Subsurface-mobile.pro | 4 +-- core/CMakeLists.txt | 4 +-- core/divelist.c | 4 +-- core/event.c | 4 +-- core/eventname.cpp | 60 ------------------------------- core/eventname.h | 21 ----------- core/eventtype.cpp | 59 ++++++++++++++++++++++++++++++ core/eventtype.h | 21 +++++++++++ profile-widget/diveeventitem.cpp | 4 +-- profile-widget/profilewidget2.cpp | 8 ++--- 10 files changed, 94 insertions(+), 95 deletions(-) delete mode 100644 core/eventname.cpp delete mode 100644 core/eventname.h create mode 100644 core/eventtype.cpp create mode 100644 core/eventtype.h diff --git a/Subsurface-mobile.pro b/Subsurface-mobile.pro index 0167be861..9ff1fbbe6 100644 --- a/Subsurface-mobile.pro +++ b/Subsurface-mobile.pro @@ -51,7 +51,7 @@ SOURCES += subsurface-mobile-main.cpp \ core/divecomputer.c \ core/divefilter.cpp \ core/event.c \ - core/eventname.cpp \ + core/eventtype.cpp \ core/filterconstraint.cpp \ core/filterpreset.cpp \ core/divelist.c \ @@ -202,7 +202,7 @@ HEADERS += \ core/dive.h \ core/divecomputer.h \ core/event.h \ - core/eventname.h \ + core/eventtype.h \ core/extradata.h \ core/git-access.h \ core/globals.h \ diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 6b552c6cb..5b580ea91 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -81,8 +81,8 @@ set(SUBSURFACE_CORE_LIB_SRCS downloadfromdcthread.h event.c event.h - eventname.cpp - eventname.h + eventtype.cpp + eventtype.h equipment.c equipment.h errorhelper.c diff --git a/core/divelist.c b/core/divelist.c index ac0af1b18..ee67d77aa 100644 --- a/core/divelist.c +++ b/core/divelist.c @@ -9,7 +9,7 @@ #include "divelog.h" #include "divesite.h" #include "event.h" -#include "eventname.h" +#include "eventtype.h" #include "filterpreset.h" #include "fulltext.h" #include "interpolate.h" @@ -1319,7 +1319,7 @@ void clear_dive_file_data() current_dive = NULL; clear_divelog(&divelog); - clear_event_names(); + clear_event_types(); reset_min_datafile_version(); clear_git_id(); diff --git a/core/event.c b/core/event.c index 8019cacd7..c3ff36460 100644 --- a/core/event.c +++ b/core/event.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 #include "event.h" -#include "eventname.h" +#include "eventtype.h" #include "subsurface-string.h" #include @@ -80,7 +80,7 @@ struct event *create_event(unsigned int time, int type, int flags, int value, co break; } - remember_event_name(name, flags); + remember_event_type(name, flags); return ev; } diff --git a/core/eventname.cpp b/core/eventname.cpp deleted file mode 100644 index 2404fe81e..000000000 --- a/core/eventname.cpp +++ /dev/null @@ -1,60 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -#include "eventname.h" -#include "subsurface-string.h" - -#include -#include -#include - -struct event_name { - std::string name; - int flags; - bool plot; -}; - -static std::vector event_names; - -// Small helper so that we can compare events to C-strings -static bool operator==(const event_name &en1, const event_name &en2) -{ - return en1.name == en2.name && en1.flags == en2.flags; -} - -extern "C" void clear_event_names() -{ - event_names.clear(); -} - -extern "C" void remember_event_name(const char *eventname, const int flags) -{ - if (empty_string(eventname)) - return; - if (std::find(event_names.begin(), event_names.end(), event_name{ eventname, flags }) != event_names.end()) - return; - event_names.push_back({ eventname, flags, true }); -} - -extern "C" bool is_event_hidden(const char *eventname, const int flags) -{ - auto it = std::find(event_names.begin(), event_names.end(), event_name{ eventname, flags }); - return it != event_names.end() && !it->plot; -} - -extern "C" void hide_similar_events(const char *eventname, const int flags) -{ - auto it = std::find(event_names.begin(), event_names.end(), event_name{ eventname, flags }); - if (it != event_names.end()) - it->plot = false; -} - -extern "C" void show_all_events() -{ - for (event_name &en: event_names) - en.plot = true; -} - -extern "C" bool any_events_hidden() -{ - return std::any_of(event_names.begin(), event_names.end(), - [] (const event_name &en) { return !en.plot; }); -} diff --git a/core/eventname.h b/core/eventname.h deleted file mode 100644 index bf22c9375..000000000 --- a/core/eventname.h +++ /dev/null @@ -1,21 +0,0 @@ -// collect all event names and whether we display events of that type -// SPDX-License-Identifier: GPL-2.0 -#ifndef EVENTNAME_H -#define EVENTNAME_H - -#ifdef __cplusplus -extern "C" { -#endif - -extern void clear_event_names(void); -extern void remember_event_name(const char *eventname, const int flags); -extern bool is_event_hidden(const char *eventname, const int flags); -extern void hide_similar_events(const char *eventname, const int flags); -extern void show_all_events(); -extern bool any_events_hidden(); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/core/eventtype.cpp b/core/eventtype.cpp new file mode 100644 index 000000000..78afac1f3 --- /dev/null +++ b/core/eventtype.cpp @@ -0,0 +1,59 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "eventtype.h" +#include "subsurface-string.h" + +#include +#include +#include + +struct event_type { + std::string name; + int flags; + bool plot; +}; + +static std::vector event_types; + +static bool operator==(const event_type &en1, const event_type &en2) +{ + return en1.name == en2.name && en1.flags == en2.flags; +} + +extern "C" void clear_event_types() +{ + event_types.clear(); +} + +extern "C" void remember_event_type(const char *eventname, const int flags) +{ + if (empty_string(eventname)) + return; + if (std::find(event_types.begin(), event_types.end(), event_type{ eventname, flags }) != event_types.end()) + return; + event_types.push_back({ eventname, flags, true }); +} + +extern "C" bool is_event_type_hidden(const char *eventname, const int flags) +{ + auto it = std::find(event_types.begin(), event_types.end(), event_type{ eventname, flags }); + return it != event_types.end() && !it->plot; +} + +extern "C" void hide_event_type(const char *eventname, const int flags) +{ + auto it = std::find(event_types.begin(), event_types.end(), event_type{ eventname, flags }); + if (it != event_types.end()) + it->plot = false; +} + +extern "C" void show_all_event_types() +{ + for (event_type &e: event_types) + e.plot = true; +} + +extern "C" bool any_event_types_hidden() +{ + return std::any_of(event_types.begin(), event_types.end(), + [] (const event_type &e) { return !e.plot; }); +} diff --git a/core/eventtype.h b/core/eventtype.h new file mode 100644 index 000000000..e90777115 --- /dev/null +++ b/core/eventtype.h @@ -0,0 +1,21 @@ +// collect all event names and whether we display events of that type +// SPDX-License-Identifier: GPL-2.0 +#ifndef EVENTNAME_H +#define EVENTNAME_H + +#ifdef __cplusplus +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 show_all_event_types(); +extern bool any_event_types_hidden(); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/profile-widget/diveeventitem.cpp b/profile-widget/diveeventitem.cpp index 8c91fb6fd..3e24c0a28 100644 --- a/profile-widget/diveeventitem.cpp +++ b/profile-widget/diveeventitem.cpp @@ -4,7 +4,7 @@ #include "profile-widget/divepixmapcache.h" #include "profile-widget/animationfunctions.h" #include "core/event.h" -#include "core/eventname.h" +#include "core/eventtype.h" #include "core/format.h" #include "core/profile.h" #include "core/gettextfromc.h" @@ -226,7 +226,7 @@ bool DiveEventItem::isInteresting(const struct dive *d, const struct divecompute bool DiveEventItem::shouldBeHidden() { - return is_event_hidden(ev->name, ev->flags); + return is_event_type_hidden(ev->name, ev->flags); } void DiveEventItem::recalculatePos() diff --git a/profile-widget/profilewidget2.cpp b/profile-widget/profilewidget2.cpp index 0b4e2208f..85f2b7f30 100644 --- a/profile-widget/profilewidget2.cpp +++ b/profile-widget/profilewidget2.cpp @@ -3,7 +3,7 @@ #include "profile-widget/profilescene.h" #include "core/device.h" #include "core/event.h" -#include "core/eventname.h" +#include "core/eventtype.h" #include "core/subsurface-string.h" #include "core/qthelper.h" #include "core/range.h" @@ -656,7 +656,7 @@ void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event) } #endif } - if (any_events_hidden() || std::any_of(profileScene->eventItems.begin(), profileScene->eventItems.end(), [] (const DiveEventItem *item) { return !item->isVisible(); })) + if (any_event_types_hidden() || std::any_of(profileScene->eventItems.begin(), profileScene->eventItems.end(), [] (const DiveEventItem *item) { return !item->isVisible(); })) m.addAction(tr("Unhide all events"), this, &ProfileWidget2::unhideEvents); m.exec(event->globalPos()); } @@ -702,7 +702,7 @@ void ProfileWidget2::hideSimilarEvents(DiveEventItem *item) const struct event *event = item->getEvent(); if (!empty_string(event->name)) { - hide_similar_events(event->name, event->flags); + hide_event_type(event->name, event->flags); replot(); } @@ -710,7 +710,7 @@ void ProfileWidget2::hideSimilarEvents(DiveEventItem *item) void ProfileWidget2::unhideEvents() { - show_all_events(); + show_all_event_types(); for (DiveEventItem *item: profileScene->eventItems) item->show(); }