summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2021-06-05 09:15:51 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2021-06-05 11:29:00 -0700
commitfd2862042b1aa925bd842f512ee6260865e2f5b1 (patch)
tree4bfd092b0fc2573a53e07b1ff82201e0acc632e8
parentc93fb83edfe4bfab6bd2c01e2c54cfe7b39f0506 (diff)
downloadsubsurface-fd2862042b1aa925bd842f512ee6260865e2f5b1.tar.gz
profile: pass axes and model to DiveEventItem on construction
Firstly, there is no point in supporting DiveEventItems without model and axis. Secondly, this avoid pointless position- recalculations. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r--profile-widget/diveeventitem.cpp34
-rw-r--r--profile-widget/diveeventitem.h4
-rw-r--r--profile-widget/profilewidget2.cpp5
3 files changed, 14 insertions, 29 deletions
diff --git a/profile-widget/diveeventitem.cpp b/profile-widget/diveeventitem.cpp
index 3590a35c8..1a0694979 100644
--- a/profile-widget/diveeventitem.cpp
+++ b/profile-widget/diveeventitem.cpp
@@ -14,10 +14,12 @@
#define DEPTH_NOT_FOUND (-2342)
-DiveEventItem::DiveEventItem(const struct dive *d, struct event *ev, struct gasmix lastgasmix, QGraphicsItem *parent) : DivePixmapItem(parent),
- vAxis(NULL),
- hAxis(NULL),
- dataModel(NULL),
+DiveEventItem::DiveEventItem(const struct dive *d, struct event *ev, struct gasmix lastgasmix,
+ DivePlotDataModel *model, DiveCartesianAxis *hAxis, DiveCartesianAxis *vAxis,
+ int speed, QGraphicsItem *parent) : DivePixmapItem(parent),
+ vAxis(vAxis),
+ hAxis(hAxis),
+ dataModel(model),
internalEvent(clone_event(ev)),
dive(d)
{
@@ -26,31 +28,15 @@ DiveEventItem::DiveEventItem(const struct dive *d, struct event *ev, struct gasm
setupPixmap(lastgasmix);
setupToolTipString(lastgasmix);
recalculatePos(0);
-}
-DiveEventItem::~DiveEventItem()
-{
- free(internalEvent);
-}
-
-void DiveEventItem::setHorizontalAxis(DiveCartesianAxis *axis)
-{
- hAxis = axis;
- recalculatePos(0);
-}
-void DiveEventItem::setModel(DivePlotDataModel *model)
-{
- dataModel = model;
- recalculatePos(0);
+ connect(vAxis, &DiveCartesianAxis::sizeChanged, this,
+ [speed, this] { recalculatePos(speed); });
}
-void DiveEventItem::setVerticalAxis(DiveCartesianAxis *axis, int speed)
+DiveEventItem::~DiveEventItem()
{
- vAxis = axis;
- recalculatePos(0);
- connect(vAxis, &DiveCartesianAxis::sizeChanged, this,
- [speed, this] { recalculatePos(speed); });
+ free(internalEvent);
}
struct event *DiveEventItem::getEvent()
diff --git a/profile-widget/diveeventitem.h b/profile-widget/diveeventitem.h
index a04d89214..1bb217d92 100644
--- a/profile-widget/diveeventitem.h
+++ b/profile-widget/diveeventitem.h
@@ -11,7 +11,9 @@ struct event;
class DiveEventItem : public DivePixmapItem {
Q_OBJECT
public:
- DiveEventItem(const struct dive *d, struct event *ev, struct gasmix lastgasmix, QGraphicsItem *parent = 0);
+ DiveEventItem(const struct dive *d, struct event *ev, struct gasmix lastgasmix,
+ DivePlotDataModel *model, DiveCartesianAxis *hAxis, DiveCartesianAxis *vAxis,
+ int speed, QGraphicsItem *parent = nullptr);
~DiveEventItem();
struct event *getEvent();
void eventVisibilityChanged(const QString &eventName, bool visible);
diff --git a/profile-widget/profilewidget2.cpp b/profile-widget/profilewidget2.cpp
index e4b624b8b..3503df75f 100644
--- a/profile-widget/profilewidget2.cpp
+++ b/profile-widget/profilewidget2.cpp
@@ -725,10 +725,7 @@ void ProfileWidget2::plotDive(const struct dive *dIn, int dcIn, bool doClearPict
// printMode is always selected for SUBSURFACE_MOBILE due to font problems
// BUT events are wanted.
#endif
- DiveEventItem *item = new DiveEventItem(d, event, lastgasmix);
- item->setHorizontalAxis(timeAxis);
- item->setVerticalAxis(profileYAxis, qPrefDisplay::animation_speed());
- item->setModel(dataModel);
+ DiveEventItem *item = new DiveEventItem(d, event, lastgasmix, dataModel, timeAxis, profileYAxis, animSpeed);
item->setZValue(2);
#ifndef SUBSURFACE_MOBILE
item->setScale(printMode ? 4 :1);