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 <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-02-14 10:59:13 +01:00 committed by Dirk Hohndel
parent 7a74a6c426
commit d3c9cb14bf
10 changed files with 94 additions and 95 deletions

View file

@ -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 \

View file

@ -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

View file

@ -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();

View file

@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-2.0
#include "event.h"
#include "eventname.h"
#include "eventtype.h"
#include "subsurface-string.h"
#include <string.h>
@ -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;
}

View file

@ -1,60 +0,0 @@
// SPDX-License-Identifier: GPL-2.0
#include "eventname.h"
#include "subsurface-string.h"
#include <string>
#include <vector>
#include <algorithm>
struct event_name {
std::string name;
int flags;
bool plot;
};
static std::vector<event_name> 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; });
}

View file

@ -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

59
core/eventtype.cpp Normal file
View file

@ -0,0 +1,59 @@
// SPDX-License-Identifier: GPL-2.0
#include "eventtype.h"
#include "subsurface-string.h"
#include <string>
#include <vector>
#include <algorithm>
struct event_type {
std::string name;
int flags;
bool plot;
};
static std::vector<event_type> 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; });
}

21
core/eventtype.h Normal file
View file

@ -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

View file

@ -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()

View file

@ -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();
}