Move the events when a partial pressure graph is enabled / disabled

The events were static on the canvas even if the profile changed its size
because of a toggle of the partial pressure gas. This patch makes events
move on the canvas to their correct place.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Tomaz Canabrava 2014-02-15 21:05:47 -02:00 committed by Dirk Hohndel
parent 6c67f90858
commit 87d5289920
2 changed files with 14 additions and 7 deletions

View file

@ -1,6 +1,7 @@
#include "diveeventitem.h" #include "diveeventitem.h"
#include "diveplotdatamodel.h" #include "diveplotdatamodel.h"
#include "divecartesianaxis.h" #include "divecartesianaxis.h"
#include "animationfunctions.h"
#include "dive.h" #include "dive.h"
#include <QDebug> #include <QDebug>
@ -14,19 +15,20 @@ DiveEventItem::DiveEventItem(QObject* parent): DivePixmapItem(parent),
void DiveEventItem::setHorizontalAxis(DiveCartesianAxis* axis) void DiveEventItem::setHorizontalAxis(DiveCartesianAxis* axis)
{ {
hAxis = axis; hAxis = axis;
recalculatePos(); recalculatePos(true);
} }
void DiveEventItem::setModel(DivePlotDataModel* model) void DiveEventItem::setModel(DivePlotDataModel* model)
{ {
dataModel = model; dataModel = model;
recalculatePos(); recalculatePos(true);
} }
void DiveEventItem::setVerticalAxis(DiveCartesianAxis* axis) void DiveEventItem::setVerticalAxis(DiveCartesianAxis* axis)
{ {
vAxis = axis; vAxis = axis;
recalculatePos(); recalculatePos(true);
connect(vAxis, SIGNAL(sizeChanged()), this, SLOT(recalculatePos()));
} }
void DiveEventItem::setEvent(struct event* ev) void DiveEventItem::setEvent(struct event* ev)
@ -34,7 +36,7 @@ void DiveEventItem::setEvent(struct event* ev)
internalEvent = ev; internalEvent = ev;
setupPixmap(); setupPixmap();
setupToolTipString(); setupToolTipString();
recalculatePos(); recalculatePos(true);
} }
void DiveEventItem::setupPixmap() void DiveEventItem::setupPixmap()
@ -101,7 +103,7 @@ void DiveEventItem::eventVisibilityChanged(const QString& eventName, bool visibl
{ {
} }
void DiveEventItem::recalculatePos() void DiveEventItem::recalculatePos(bool instant)
{ {
if (!vAxis || !hAxis || !internalEvent || !dataModel) { if (!vAxis || !hAxis || !internalEvent || !dataModel) {
return; return;
@ -117,5 +119,9 @@ void DiveEventItem::recalculatePos()
int depth = dataModel->data(dataModel->index(result.first().row(), DivePlotDataModel::DEPTH)).toInt(); int depth = dataModel->data(dataModel->index(result.first().row(), DivePlotDataModel::DEPTH)).toInt();
qreal x = hAxis->posAtValue(internalEvent->time.seconds); qreal x = hAxis->posAtValue(internalEvent->time.seconds);
qreal y = vAxis->posAtValue(depth); qreal y = vAxis->posAtValue(depth);
setPos(x, y); if (!instant){
Animations::moveTo(this, x, y, 500);
}else{
setPos(x,y);
}
} }

View file

@ -16,9 +16,10 @@ public:
void setVerticalAxis(DiveCartesianAxis *axis); void setVerticalAxis(DiveCartesianAxis *axis);
void setHorizontalAxis(DiveCartesianAxis *axis); void setHorizontalAxis(DiveCartesianAxis *axis);
void setModel(DivePlotDataModel *model); void setModel(DivePlotDataModel *model);
public slots:
void recalculatePos(bool instant = false);
private: private:
void setupToolTipString(); void setupToolTipString();
void recalculatePos();
void setupPixmap(); void setupPixmap();
DiveCartesianAxis *vAxis; DiveCartesianAxis *vAxis;
DiveCartesianAxis *hAxis; DiveCartesianAxis *hAxis;