diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2013-09-22 11:01:18 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-09-22 11:01:18 -0700 |
commit | 9ba7b12767b580ed339231ee3469f35a3588a37a (patch) | |
tree | f98449036ff145a196c7431e64a0a9d8c60c7241 | |
parent | 799b56a1f39fa09b3b6160465199e5dd1780df31 (diff) | |
download | subsurface-9ba7b12767b580ed339231ee3469f35a3588a37a.tar.gz |
Prevent nodes in planner / dive add profile edit to run past each other
I always disliked the fact that when you moved the handlers around you
could just 'run over' the neighbors. This also (as a somewhat intended
side effect) prevents vertical descents and ascents).
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | qt-ui/diveplanner.cpp | 43 | ||||
-rw-r--r-- | qt-ui/diveplanner.h | 1 |
2 files changed, 18 insertions, 26 deletions
diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index 89da3b4b4..d3bdc3a69 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -560,9 +560,18 @@ void DivePlannerGraphics::mouseMoveEvent(QMouseEvent* event) void DivePlannerGraphics::moveActiveHandler(const QPointF& mappedPos, const int pos) { - divedatapoint data = plannerModel->at(pos); + int mintime = 0, maxtime = (timeLine->maximum() + 10) * 60; + if (pos > 0) + mintime = plannerModel->at(pos - 1).time; + if (pos < plannerModel->size() - 1) + maxtime = plannerModel->at(pos + 1).time; + int minutes = rint(timeLine->valueAt(mappedPos)); + + if (minutes * 60 <= mintime || minutes * 60 >= maxtime) + return; + int meters = rint(depthLine->valueAt(mappedPos)); double xpos = timeLine->posAtValue(minutes); double ypos = depthLine->posAtValue(meters); @@ -617,32 +626,9 @@ void DivePlannerGraphics::mousePressEvent(QMouseEvent* event) void DivePlannerGraphics::mouseReleaseEvent(QMouseEvent* event) { if (activeDraggedHandler) { - QPointF mappedPos = mapToScene(event->pos()); - int minutes = rint(timeLine->valueAt(mappedPos)); - int meters = rint(depthLine->valueAt(mappedPos)); - double xpos = timeLine->posAtValue(minutes); - double ypos = depthLine->posAtValue(meters); - Q_FOREACH(DiveHandler* handler, handles){ - if (xpos == handler->pos().x() && handler != activeDraggedHandler){ - qDebug() << "There's already an point at that place."; - //TODO: Move this later to a KMessageWidget. - activeDraggedHandler->setPos(originalHandlerPos); - activeDraggedHandler = NULL; - return; - } - } - - int pos = handles.indexOf(activeDraggedHandler); - divedatapoint data = plannerModel->at(pos); - - data.depth = rint(depthLine->valueAt(mappedPos)) * 1000; - data.time = rint(timeLine->valueAt(mappedPos)) * 60; - - plannerModel->editStop(pos, data); - + /* we already deal with all the positioning in the life update, + * so all we need to do here is change the color of the handler */ activeDraggedHandler->setBrush(QBrush(Qt::white)); - activeDraggedHandler->setPos(QPointF(xpos, ypos)); - activeDraggedHandler = 0; drawProfile(); } @@ -1128,6 +1114,11 @@ void DivePlannerPointsModel::editStop(int row, divedatapoint newData) emit dataChanged(createIndex(0, 0), createIndex(rowCount()-1, COLUMNS-1)); } +int DivePlannerPointsModel::size() +{ + return divepoints.size(); +} + divedatapoint DivePlannerPointsModel::at(int row) { return divepoints.at(row); diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h index 81825c765..e9fe2051a 100644 --- a/qt-ui/diveplanner.h +++ b/qt-ui/diveplanner.h @@ -42,6 +42,7 @@ public: */ void editStop(int row, divedatapoint newData ); divedatapoint at(int row); + int size(); struct diveplan getDiveplan(); public slots: int addStop(int meters = 0, int minutes = 0,const QString& gas = QString(), int ccpoint = 0 ); |