From 03572e233dd25b5eef5b977d19c1fd2bd3af6bae Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Wed, 26 Jun 2013 19:14:55 -0300 Subject: [PATCH 1/2] Remove the bogus time/depth, and fix the positioning of the Handler after updateTicks. Remove the bogus time/depth that was duplicated in the Handler - dirk didn't realized that I already created the same data that he put on it later, but mine was double and his his was int, I choosed his implementation since he knows a bit more than I do about subsurface internals. Besides that, I worked a bit on the logic that called update ticks, because it was calling it for every mouseMoveEvent, it created sooooo many ticks that it made the app unusable ( and slow. ) Signed-off-by: Tomaz Canabrava --- qt-ui/diveplanner.cpp | 28 +++++++++++++--------------- qt-ui/diveplanner.h | 2 -- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index 5b603cfc0..e1396798f 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -106,8 +106,6 @@ void DivePlannerGraphics::mouseDoubleClickEvent(QMouseEvent* event) scene()->addItem(line); createDecoStops(); } - item->time = (timeLine->valueAt(mappedPos)); - item->depth = (depthLine->valueAt(mappedPos)); } void DivePlannerGraphics::clearGeneratedDeco() @@ -162,13 +160,13 @@ void DivePlannerGraphics::createDecoStops() // when we change the maximum and things accelerate from there // BAD // - // timeLine->setMaximum(dp->time / 60.0 + 5); + timeLine->setMaximum(dp->time / 60.0 + 5); + timeLine->updateTicks(); } + // Re-position the user generated dive handlers - Q_FOREACH(DiveHandler *h, handles) { - // uncomment this as soon as the posAtValue is implemented. - // h->setPos(timeLine->posAtValue(h->time), - // depthLine->posAtValue(h->depth)); + Q_FOREACH(DiveHandler *h, handles){ + h->setPos(timeLine->posAtValue(h->sec / 60), depthLine->posAtValue(h->mm) / 1000); } // Create all 'deco' GraphicsLineItems and put it on the canvas. @@ -270,11 +268,6 @@ void DivePlannerGraphics::moveActiveHandler(const QPointF& pos) QLineF f = activeDraggedHandler->to->line(); activeDraggedHandler->to->setLine(newPos.x(), newPos.y(), f.x2(), f.y2()); } - - if (activeDraggedHandler == handles.last()) { - clearGeneratedDeco(); - createDecoStops(); - } activeDraggedHandler->sec = sec; activeDraggedHandler->mm = mm; } @@ -311,9 +304,15 @@ void DivePlannerGraphics::mouseReleaseEvent(QMouseEvent* event) { if (activeDraggedHandler) { QPointF mappedPos = mapToScene(event->pos()); - activeDraggedHandler->time = (timeLine->valueAt(mappedPos)); - activeDraggedHandler->depth = (depthLine->valueAt(mappedPos)); + activeDraggedHandler->sec = rint(timeLine->valueAt(mappedPos)) * 60; + activeDraggedHandler->mm = rint(depthLine->valueAt(mappedPos)) * 1000; activeDraggedHandler->setBrush(QBrush()); + + if (activeDraggedHandler == handles.last()) { + clearGeneratedDeco(); + createDecoStops(); + } + activeDraggedHandler = 0; } } @@ -351,7 +350,6 @@ void Ruler::updateTicks() double stepSize = (m.x2() - m.x1()) / steps; for (qreal pos = m.x1(); pos < m.x2(); pos += stepSize) { ticks.push_back(new QGraphicsLineItem(pos, m.y1(), pos, m.y1() + 1, this)); - } } else { double steps = (max - min) / interval; diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h index 8c3505f52..4553c3b94 100644 --- a/qt-ui/diveplanner.h +++ b/qt-ui/diveplanner.h @@ -20,8 +20,6 @@ public: DiveHandler(); QGraphicsLineItem *from; QGraphicsLineItem *to; - qreal time; - qreal depth; int sec; int mm; }; From 7a840d2668c364769f66a44a732983570a79c653 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Wed, 26 Jun 2013 20:41:39 -0300 Subject: [PATCH 2/2] Fixes most of the issues with the dive planner. Fixes most of the issues with the dive planner, The lines are removed when the drag starts, and it's repopulated after. The time ruler updates itself with the biggest time in the dive (I'll add later the code to keep a minimum of 60 minutes, and increase by 15 to 15 minutes, but for now this will work ), Removed the code to do line manipulation while we are moving handlers around ( because it could trigger ruler-expansion, that woul'd move everything, and that's not nice. This showed that something bogus is going on with the decompression algorithm - I don't know if it's on the data or on the algorithm itself, but it's creating a ring with the lines on the canvas I painted all decompression-algorithm based lines red so it's easier to spot where the hell things got wrong. midnight, sleepy. Signed-off-by: Tomaz Canabrava --- qt-ui/diveplanner.cpp | 84 ++++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 54 deletions(-) diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index e1396798f..8cd389777 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -87,38 +87,18 @@ void DivePlannerGraphics::mouseDoubleClickEvent(QMouseEvent* event) item->setPos(QPointF(xpos, ypos)); scene()->addItem(item); handles << item; - - if (lines.empty()) { - double xpos = timeLine->posAtValue(0); - double ypos = depthLine->posAtValue(0); - QGraphicsLineItem *first = new QGraphicsLineItem(xpos,ypos, mappedPos.x(), mappedPos.y()); - item->from = first; - lines.push_back(first); - createDecoStops(); - scene()->addItem(first); - } else { - clearGeneratedDeco(); - DiveHandler *prevHandle = handles.at(handles.count()-2); - QGraphicsLineItem *line = new QGraphicsLineItem(prevHandle->x(), prevHandle->y(), item->x(), item->y()); - prevHandle->to = line; - item->from = line; - lines.push_back(line); - scene()->addItem(line); - createDecoStops(); - } + createDecoStops(); } void DivePlannerGraphics::clearGeneratedDeco() { - for (int i = handles.count(); i <= lines.count(); i++) { - scene()->removeItem(lines.last()); - delete lines.last(); - lines.removeLast(); - } } void DivePlannerGraphics::createDecoStops() { + qDeleteAll(lines); + lines.clear(); + // This needs to be done in the following steps: // Get the user-input and calculate the dive info // Not sure if this is the place to create the diveplan... @@ -154,21 +134,36 @@ void DivePlannerGraphics::createDecoStops() while(dp->next) dp = dp->next; - if (timeLine->maximum() < dp->time / 60.0 + 5) { - // this causes all kinds of bad things as the - // handle that you are holding on to gets scaled out - // when we change the maximum and things accelerate from there - // BAD - // + + //if (timeLine->maximum() < dp->time / 60.0 + 5) { timeLine->setMaximum(dp->time / 60.0 + 5); timeLine->updateTicks(); - } + //} // Re-position the user generated dive handlers Q_FOREACH(DiveHandler *h, handles){ h->setPos(timeLine->posAtValue(h->sec / 60), depthLine->posAtValue(h->mm) / 1000); } + // Create all 'user entered' lines, and put it on the canvas. + double xpos = timeLine->posAtValue(0); + double ypos = depthLine->posAtValue(0); + QGraphicsLineItem *first = new QGraphicsLineItem(xpos,ypos, handles.first()->x(), handles.first()->y()); + handles.first()->from = first; + scene()->addItem(first); + lines.push_back(first); + +// +// for(int i = 0; i < handles.count()-1; i++){ +// DiveHandler *first = handles.at(i); +// DiveHandler *second = handles.at(i+1); +// QGraphicsLineItem *line = new QGraphicsLineItem(first->x(),first->y(), second->x(), second->y()); +// first->from = line; +// second->to = line; +// scene()->addItem(line); +// lines.push_back(line); +// } + // Create all 'deco' GraphicsLineItems and put it on the canvas. double lastx = handles.last()->x(); double lasty = handles.last()->y(); @@ -179,6 +174,7 @@ void DivePlannerGraphics::createDecoStops() double ypos = depthLine->posAtValue(dp->depth / 1000.0); qDebug("time/depth %f/%f", dp->time / 60.0, dp->depth / 1000.0); QGraphicsLineItem *item = new QGraphicsLineItem(lastx, lasty, xpos, ypos); + item->setPen(QPen(QBrush(Qt::red),0)); lastx = xpos; lasty = ypos; scene()->addItem(item); @@ -241,36 +237,21 @@ void DivePlannerGraphics::moveActiveHandler(const QPointF& pos) if (idx == 0 ) { // first if (newPos.x() < handles[1]->x()) { activeDraggedHandler->setPos(newPos); - moveLines = true; } } else if (idx == handles.count()-1) { // last if (newPos.x() > handles[idx-1]->x()) { activeDraggedHandler->setPos(newPos); - moveLines = true; } } else { // middle if (newPos.x() > handles[idx-1]->x() && newPos.x() < handles[idx+1]->x()) { activeDraggedHandler->setPos(newPos); - moveLines = true; } } } else { activeDraggedHandler->setPos(newPos); - moveLines = true; - } - if (moveLines) { - if (activeDraggedHandler->from) { - QLineF f = activeDraggedHandler->from->line(); - activeDraggedHandler->from->setLine(f.x1(), f.y1(), newPos.x(), newPos.y()); - } - - if (activeDraggedHandler->to) { - QLineF f = activeDraggedHandler->to->line(); - activeDraggedHandler->to->setLine(newPos.x(), newPos.y(), f.x2(), f.y2()); - } - activeDraggedHandler->sec = sec; - activeDraggedHandler->mm = mm; } + qqDeleteAll(lines); + lines.clear(); } bool DivePlannerGraphics::isPointOutOfBoundaries(const QPointF& point) @@ -307,12 +288,7 @@ void DivePlannerGraphics::mouseReleaseEvent(QMouseEvent* event) activeDraggedHandler->sec = rint(timeLine->valueAt(mappedPos)) * 60; activeDraggedHandler->mm = rint(depthLine->valueAt(mappedPos)) * 1000; activeDraggedHandler->setBrush(QBrush()); - - if (activeDraggedHandler == handles.last()) { - clearGeneratedDeco(); - createDecoStops(); - } - + createDecoStops(); activeDraggedHandler = 0; } }