From ea4d4ac020319dee0e1d74ff793ef50ab8c47508 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Fri, 23 May 2014 20:51:30 -0300 Subject: Make the planner actually work. This commit makes the planner actually work. There ar still a few edges, but oh, joy - the new Profile gave a very unexpected and nice addition to it - Grab the last handler of the initial dive, and move it to the right, or get any handler, and move it to the bottom to see what I mean. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- qt-ui/profile/profilewidget2.cpp | 24 ++++++++++++++++++++++++ qt-ui/profile/profilewidget2.h | 3 +++ 2 files changed, 27 insertions(+) (limited to 'qt-ui/profile') diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp index 81ed98619..dd4ecca85 100644 --- a/qt-ui/profile/profilewidget2.cpp +++ b/qt-ui/profile/profilewidget2.cpp @@ -964,6 +964,7 @@ void ProfileWidget2::pointInserted(const QModelIndex &parent, int start, int end scene()->addItem(item); handles << item; + connect(item, SIGNAL(moved()), this, SLOT(recreatePlannedDive())); QGraphicsSimpleTextItem *gasChooseBtn = new QGraphicsSimpleTextItem(); scene()->addItem(gasChooseBtn); gasChooseBtn->setZValue(10); @@ -1007,3 +1008,26 @@ void ProfileWidget2::repositionDiveHandlers() last = i; } } + +void ProfileWidget2::recreatePlannedDive() +{ + DiveHandler *activeHandler = qobject_cast(sender()); + DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance(); + int index = handles.indexOf(activeHandler); + + int mintime = 0, maxtime = (timeAxis->maximum() + 10) * 60; + if (index > 0) + mintime = plannerModel->at(index - 1).time; + if (index < plannerModel->size() - 1) + maxtime = plannerModel->at(index + 1).time; + + int minutes = rint(timeAxis->valueAt(activeHandler->pos()) / 60); + if (minutes * 60 <= mintime || minutes * 60 >= maxtime) + return; + + divedatapoint data = plannerModel->at(index); + data.depth = rint(profileYAxis->valueAt(activeHandler->pos()) / M_OR_FT(1, 1)) * M_OR_FT(1, 1);; + data.time = rint(timeAxis->valueAt(activeHandler->pos())); + + plannerModel->editStop(index, data); +} diff --git a/qt-ui/profile/profilewidget2.h b/qt-ui/profile/profilewidget2.h index 895b82c78..1c1258de5 100644 --- a/qt-ui/profile/profilewidget2.h +++ b/qt-ui/profile/profilewidget2.h @@ -91,6 +91,9 @@ slots: // Necessary to call from QAction's signals. void pointsRemoved(const QModelIndex &, int start, int end); void replot(); + /* this is called for every move on the handlers. maybe we can speed up this a bit? */ + void recreatePlannedDive(); + protected: virtual void resizeEvent(QResizeEvent *event); virtual void wheelEvent(QWheelEvent *event); -- cgit v1.2.3-70-g09d2