profile: pass event at construction time to DiveEventItem

There is no point in having a dive event without an event.
Let's pass the event at construction time to avoid having
to handle "invalid" events.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2021-06-05 09:05:46 +02:00 committed by Dirk Hohndel
parent e42fc1a1e9
commit c93fb83edf
3 changed files with 9 additions and 20 deletions

View file

@ -14,14 +14,18 @@
#define DEPTH_NOT_FOUND (-2342) #define DEPTH_NOT_FOUND (-2342)
DiveEventItem::DiveEventItem(QGraphicsItem *parent) : DivePixmapItem(parent), DiveEventItem::DiveEventItem(const struct dive *d, struct event *ev, struct gasmix lastgasmix, QGraphicsItem *parent) : DivePixmapItem(parent),
vAxis(NULL), vAxis(NULL),
hAxis(NULL), hAxis(NULL),
dataModel(NULL), dataModel(NULL),
internalEvent(NULL), internalEvent(clone_event(ev)),
dive(NULL) dive(d)
{ {
setFlag(ItemIgnoresTransformations); setFlag(ItemIgnoresTransformations);
setupPixmap(lastgasmix);
setupToolTipString(lastgasmix);
recalculatePos(0);
} }
DiveEventItem::~DiveEventItem() DiveEventItem::~DiveEventItem()
@ -54,19 +58,6 @@ struct event *DiveEventItem::getEvent()
return internalEvent; return internalEvent;
} }
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);
setupToolTipString(lastgasmix);
recalculatePos(0);
}
void DiveEventItem::setupPixmap(struct gasmix lastgasmix) void DiveEventItem::setupPixmap(struct gasmix lastgasmix)
{ {
const IconMetrics& metrics = defaultIconMetrics(); const IconMetrics& metrics = defaultIconMetrics();

View file

@ -11,9 +11,8 @@ struct event;
class DiveEventItem : public DivePixmapItem { class DiveEventItem : public DivePixmapItem {
Q_OBJECT Q_OBJECT
public: public:
DiveEventItem(QGraphicsItem *parent = 0); DiveEventItem(const struct dive *d, struct event *ev, struct gasmix lastgasmix, QGraphicsItem *parent = 0);
~DiveEventItem(); ~DiveEventItem();
void setEvent(const struct dive *d, struct event *ev, struct gasmix lastgasmix);
struct event *getEvent(); struct event *getEvent();
void eventVisibilityChanged(const QString &eventName, bool visible); void eventVisibilityChanged(const QString &eventName, bool visible);
void setVerticalAxis(DiveCartesianAxis *axis, int speed); void setVerticalAxis(DiveCartesianAxis *axis, int speed);

View file

@ -725,11 +725,10 @@ void ProfileWidget2::plotDive(const struct dive *dIn, int dcIn, bool doClearPict
// printMode is always selected for SUBSURFACE_MOBILE due to font problems // printMode is always selected for SUBSURFACE_MOBILE due to font problems
// BUT events are wanted. // BUT events are wanted.
#endif #endif
DiveEventItem *item = new DiveEventItem(); DiveEventItem *item = new DiveEventItem(d, event, lastgasmix);
item->setHorizontalAxis(timeAxis); item->setHorizontalAxis(timeAxis);
item->setVerticalAxis(profileYAxis, qPrefDisplay::animation_speed()); item->setVerticalAxis(profileYAxis, qPrefDisplay::animation_speed());
item->setModel(dataModel); item->setModel(dataModel);
item->setEvent(d, event, lastgasmix);
item->setZValue(2); item->setZValue(2);
#ifndef SUBSURFACE_MOBILE #ifndef SUBSURFACE_MOBILE
item->setScale(printMode ? 4 :1); item->setScale(printMode ? 4 :1);