profile: make event hiding persistent across change of dive

Currently, the "hide event" status is lost when switching dives.
Save it in the event struct instead to make it persistent.

In the future we might save this information to the log file.
Then this should be integrated in the undo-system.

This commit also makes the "show events" menu entry more
fine grained: It now differentiates between individual
events and event types. The plan is to make this even
more fine-grained in future commits, such that the user
can choose individual event types.

Note this adds an additional field to the event structure.
There is a "deleted" field that is used internally for
book-keeping, but probably should be removed. Not touching
this at the moment as long as this is C-only code. When/if
switching to C++ we can make the event linked list a table,
which will make this much simpler.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-02-19 09:04:14 +01:00
parent 0d8c6c4bc4
commit e039615c3d
6 changed files with 52 additions and 10 deletions

View file

@ -42,7 +42,8 @@ struct event {
struct gasmix mix;
} gas;
};
bool deleted;
bool deleted; // used internally in the parser and in fixup_dive().
bool hidden;
char name[];
};

View file

@ -1,6 +1,7 @@
#include "string-format.h"
#include "dive.h"
#include "divesite.h"
#include "event.h"
#include "format.h"
#include "qthelper.h"
#include "subsurface-string.h"
@ -327,3 +328,26 @@ QString formatTripTitleWithDives(const dive_trip *trip)
return formatTripTitle(trip) + " " +
gettextFromC::tr("(%n dive(s))", "", nr);
}
static QString formatEventSeverity(const event *ev)
{
switch(get_event_severity(ev)) {
case EVENT_SEVERITY_INFO: return gettextFromC::tr("info");
case EVENT_SEVERITY_WARN: return gettextFromC::tr("warn");
case EVENT_SEVERITY_ALARM: return gettextFromC::tr("alarm");
default: return QString();
}
}
QString formatEventType(const event *ev)
{
if (!ev || empty_string(ev->name))
return QString();
QString eventName = QString::fromUtf8(ev->name);
QString severity = formatEventSeverity(ev);
if (severity.isEmpty())
return eventName;
return QStringLiteral("%1 (%2)").arg(eventName, severity);
}

View file

@ -7,6 +7,7 @@
struct dive;
struct dive_trip;
struct event;
QString formatSac(const dive *d);
QString formatNotes(const dive *d);
@ -31,5 +32,6 @@ QString formatDayOfWeek(int day);
QString formatMinutes(int seconds);
QString formatTripTitle(const dive_trip *trip);
QString formatTripTitleWithDives(const dive_trip *trip);
QString formatEventType(const event *ev);
#endif

View file

@ -228,7 +228,7 @@ void DiveEventItem::recalculatePos()
hide();
return;
}
setVisible(!is_event_type_hidden(ev));
setVisible(!ev->hidden && !is_event_type_hidden(ev));
double x = hAxis->posAtValue(ev->time.seconds);
double y = vAxis->posAtValue(depth);
setPos(x, y);

View file

@ -7,6 +7,7 @@
#include "core/subsurface-string.h"
#include "core/qthelper.h"
#include "core/range.h"
#include "core/string-format.h"
#include "core/settings/qPrefTechnicalDetails.h"
#include "core/settings/qPrefPartialPressureGas.h"
#include "profile-widget/diveeventitem.h"
@ -608,10 +609,11 @@ void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event)
[this, seconds](){ addDivemodeSwitch(seconds, PSCR); });
if (DiveEventItem *item = dynamic_cast<DiveEventItem *>(sceneItem)) {
const struct event *dcEvent = item->getEvent();
m.addAction(tr("Remove event"), [this,item] { removeEvent(item); });
m.addAction(tr("Hide event"), [this, item] { hideEvent(item); });
m.addAction(tr("Hide similar events"), [this, item] { hideSimilarEvents(item); });
const struct event *dcEvent = item->getEvent();
m.addAction(tr("Hide events of type '%1'").arg(formatEventType(dcEvent)),
[this, item] { hideEventType(item); });
if (dcEvent->type == SAMPLE_EVENT_BOOKMARK)
m.addAction(tr("Edit name"), [this, item] { editName(item); });
#if 0 // TODO::: FINISH OR DISABLE
@ -656,8 +658,11 @@ void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event)
}
#endif
}
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);
if (any_event_types_hidden())
m.addAction(tr("Unhide all event types"), this, &ProfileWidget2::unhideEventTypes);
if (std::any_of(profileScene->eventItems.begin(), profileScene->eventItems.end(),
[] (const DiveEventItem *item) { return item->getEvent()->hidden; }))
m.addAction(tr("Unhide individually hidden events of this dive"), this, &ProfileWidget2::unhideEvents);
m.exec(event->globalPos());
}
@ -694,10 +699,11 @@ void ProfileWidget2::renameCurrentDC()
void ProfileWidget2::hideEvent(DiveEventItem *item)
{
item->getEventMutable()->hidden = true;
item->hide();
}
void ProfileWidget2::hideSimilarEvents(DiveEventItem *item)
void ProfileWidget2::hideEventType(DiveEventItem *item)
{
const struct event *event = item->getEvent();
@ -710,9 +716,17 @@ void ProfileWidget2::hideSimilarEvents(DiveEventItem *item)
void ProfileWidget2::unhideEvents()
{
show_all_event_types();
for (DiveEventItem *item: profileScene->eventItems)
for (DiveEventItem *item: profileScene->eventItems) {
item->getEventMutable()->hidden = false;
item->show();
}
}
void ProfileWidget2::unhideEventTypes()
{
show_all_event_types();
replot();
}
void ProfileWidget2::removeEvent(DiveEventItem *item)

View file

@ -126,9 +126,10 @@ private:
void addSetpointChange(int seconds);
void removeEvent(DiveEventItem *item);
void hideEvent(DiveEventItem *item);
void hideSimilarEvents(DiveEventItem *item);
void hideEventType(DiveEventItem *item);
void editName(DiveEventItem *item);
void unhideEvents();
void unhideEventTypes();
void makeFirstDC();
void deleteCurrentDC();
void splitCurrentDC();