diff --git a/core/event.h b/core/event.h index 31eca87fc..fc8a03d64 100644 --- a/core/event.h +++ b/core/event.h @@ -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[]; }; diff --git a/core/string-format.cpp b/core/string-format.cpp index dc2f3fad5..1d2147899 100644 --- a/core/string-format.cpp +++ b/core/string-format.cpp @@ -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); +} diff --git a/core/string-format.h b/core/string-format.h index 404e7f9cc..857bbbb09 100644 --- a/core/string-format.h +++ b/core/string-format.h @@ -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 diff --git a/profile-widget/diveeventitem.cpp b/profile-widget/diveeventitem.cpp index 0de81c454..c5fc5f975 100644 --- a/profile-widget/diveeventitem.cpp +++ b/profile-widget/diveeventitem.cpp @@ -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); diff --git a/profile-widget/profilewidget2.cpp b/profile-widget/profilewidget2.cpp index 400e0eec8..9c6be32d6 100644 --- a/profile-widget/profilewidget2.cpp +++ b/profile-widget/profilewidget2.cpp @@ -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(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) diff --git a/profile-widget/profilewidget2.h b/profile-widget/profilewidget2.h index 1ca9dccfd..1e91aff20 100644 --- a/profile-widget/profilewidget2.h +++ b/profile-widget/profilewidget2.h @@ -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();