diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2021-01-09 18:58:33 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2021-01-10 15:57:39 -0800 |
commit | be9f9efb0eae6f09db4c61de7a5156b186dc2ad6 (patch) | |
tree | 39e661e97de294d2de514048aa625f58d08a4f88 /profile-widget | |
parent | 09287809ebb76541a31af94e60856f731e3e9d37 (diff) | |
download | subsurface-be9f9efb0eae6f09db4c61de7a5156b186dc2ad6.tar.gz |
profile: pass dive to EventItem
Don't access the global displayed_dive variable in an effort
to make the profile reentrant.
Note that this still accesses the global dc_number variable,
which will likely have to be removed.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'profile-widget')
-rw-r--r-- | profile-widget/diveeventitem.cpp | 14 | ||||
-rw-r--r-- | profile-widget/diveeventitem.h | 3 | ||||
-rw-r--r-- | profile-widget/profilewidget2.cpp | 2 |
3 files changed, 10 insertions, 9 deletions
diff --git a/profile-widget/diveeventitem.cpp b/profile-widget/diveeventitem.cpp index 26ee346ff..cfbba4c8a 100644 --- a/profile-widget/diveeventitem.cpp +++ b/profile-widget/diveeventitem.cpp @@ -53,11 +53,12 @@ struct event *DiveEventItem::getEvent() return internalEvent; } -void DiveEventItem::setEvent(struct event *ev, struct gasmix lastgasmix) +void DiveEventItem::setEvent(const struct dive *d, struct event *ev, struct gasmix lastgasmix) { if (!ev) return; + dive = d; free(internalEvent); internalEvent = clone_event(ev); setupPixmap(lastgasmix); @@ -94,7 +95,7 @@ void DiveEventItem::setupPixmap(struct gasmix lastgasmix) } else if (internalEvent->type == SAMPLE_EVENT_BOOKMARK) { setPixmap(EVENT_PIXMAP(":dive-bookmark-icon")); } else if (event_is_gaschange(internalEvent)) { - struct gasmix mix = get_gasmix_from_event(&displayed_dive, internalEvent); + struct gasmix mix = get_gasmix_from_event(dive, internalEvent); struct icd_data icd_data; bool icd = isobaric_counterdiffusion(lastgasmix, mix, &icd_data); if (mix.he.permille) { @@ -176,7 +177,7 @@ void DiveEventItem::setupToolTipString(struct gasmix lastgasmix) if (event_is_gaschange(internalEvent)) { struct icd_data icd_data; - struct gasmix mix = get_gasmix_from_event(&displayed_dive, internalEvent); + struct gasmix mix = get_gasmix_from_event(dive, internalEvent); struct membuffer mb = {}; name += ": "; name += gasname(mix); @@ -224,15 +225,14 @@ void DiveEventItem::eventVisibilityChanged(const QString&, bool) bool DiveEventItem::shouldBeHidden() { - struct event *event = internalEvent; - struct dive *dive = &displayed_dive; - struct divecomputer *dc = get_dive_dc(dive, dc_number); + const struct event *event = internalEvent; + const struct divecomputer *dc = get_dive_dc_const(dive, dc_number); /* * Some gas change events are special. Some dive computers just tell us the initial gas this way. * Don't bother showing those */ - struct sample *first_sample = &dc->sample[0]; + const struct sample *first_sample = &dc->sample[0]; if (!strcmp(event->name, "gaschange") && (event->time.seconds == 0 || (first_sample && event->time.seconds == first_sample->time.seconds) || diff --git a/profile-widget/diveeventitem.h b/profile-widget/diveeventitem.h index 0c065e131..1b2c1c5ba 100644 --- a/profile-widget/diveeventitem.h +++ b/profile-widget/diveeventitem.h @@ -13,7 +13,7 @@ class DiveEventItem : public DivePixmapItem { public: DiveEventItem(QGraphicsItem *parent = 0); ~DiveEventItem(); - void setEvent(struct event *ev, struct gasmix lastgasmix); + void setEvent(const struct dive *d, struct event *ev, struct gasmix lastgasmix); struct event *getEvent(); void eventVisibilityChanged(const QString &eventName, bool visible); void setVerticalAxis(DiveCartesianAxis *axis, int speed); @@ -32,6 +32,7 @@ private: DiveCartesianAxis *hAxis; DivePlotDataModel *dataModel; struct event *internalEvent; + const struct dive *dive; }; #endif // DIVEEVENTITEM_H diff --git a/profile-widget/profilewidget2.cpp b/profile-widget/profilewidget2.cpp index 5e32f39a8..c3097ed32 100644 --- a/profile-widget/profilewidget2.cpp +++ b/profile-widget/profilewidget2.cpp @@ -768,7 +768,7 @@ void ProfileWidget2::plotDive(const struct dive *d, bool force, bool doClearPict item->setHorizontalAxis(timeAxis); item->setVerticalAxis(profileYAxis, qPrefDisplay::animation_speed()); item->setModel(dataModel); - item->setEvent(event, lastgasmix); + item->setEvent(&displayed_dive, event, lastgasmix); item->setZValue(2); #ifndef SUBSURFACE_MOBILE item->setScale(printMode ? 4 :1); |