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>
This commit is contained in:
Dirk Hohndel 2013-09-22 11:01:18 -07:00
parent 799b56a1f3
commit 9ba7b12767
2 changed files with 18 additions and 26 deletions

View file

@ -560,9 +560,18 @@ void DivePlannerGraphics::mouseMoveEvent(QMouseEvent* event)
void DivePlannerGraphics::moveActiveHandler(const QPointF& mappedPos, const int pos) void DivePlannerGraphics::moveActiveHandler(const QPointF& mappedPos, const int pos)
{ {
divedatapoint data = plannerModel->at(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)); int minutes = rint(timeLine->valueAt(mappedPos));
if (minutes * 60 <= mintime || minutes * 60 >= maxtime)
return;
int meters = rint(depthLine->valueAt(mappedPos)); int meters = rint(depthLine->valueAt(mappedPos));
double xpos = timeLine->posAtValue(minutes); double xpos = timeLine->posAtValue(minutes);
double ypos = depthLine->posAtValue(meters); double ypos = depthLine->posAtValue(meters);
@ -617,32 +626,9 @@ void DivePlannerGraphics::mousePressEvent(QMouseEvent* event)
void DivePlannerGraphics::mouseReleaseEvent(QMouseEvent* event) void DivePlannerGraphics::mouseReleaseEvent(QMouseEvent* event)
{ {
if (activeDraggedHandler) { if (activeDraggedHandler) {
QPointF mappedPos = mapToScene(event->pos()); /* we already deal with all the positioning in the life update,
int minutes = rint(timeLine->valueAt(mappedPos)); * so all we need to do here is change the color of the handler */
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);
activeDraggedHandler->setBrush(QBrush(Qt::white)); activeDraggedHandler->setBrush(QBrush(Qt::white));
activeDraggedHandler->setPos(QPointF(xpos, ypos));
activeDraggedHandler = 0; activeDraggedHandler = 0;
drawProfile(); drawProfile();
} }
@ -1128,6 +1114,11 @@ void DivePlannerPointsModel::editStop(int row, divedatapoint newData)
emit dataChanged(createIndex(0, 0), createIndex(rowCount()-1, COLUMNS-1)); emit dataChanged(createIndex(0, 0), createIndex(rowCount()-1, COLUMNS-1));
} }
int DivePlannerPointsModel::size()
{
return divepoints.size();
}
divedatapoint DivePlannerPointsModel::at(int row) divedatapoint DivePlannerPointsModel::at(int row)
{ {
return divepoints.at(row); return divepoints.at(row);

View file

@ -42,6 +42,7 @@ public:
*/ */
void editStop(int row, divedatapoint newData ); void editStop(int row, divedatapoint newData );
divedatapoint at(int row); divedatapoint at(int row);
int size();
struct diveplan getDiveplan(); struct diveplan getDiveplan();
public slots: public slots:
int addStop(int meters = 0, int minutes = 0,const QString& gas = QString(), int ccpoint = 0 ); int addStop(int meters = 0, int minutes = 0,const QString& gas = QString(), int ccpoint = 0 );