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 <tcanabrava@kde.org>
This commit is contained in:
Tomaz Canabrava 2013-06-26 20:41:39 -03:00
parent 03572e233d
commit 7a840d2668

View file

@ -87,38 +87,18 @@ void DivePlannerGraphics::mouseDoubleClickEvent(QMouseEvent* event)
item->setPos(QPointF(xpos, ypos)); item->setPos(QPointF(xpos, ypos));
scene()->addItem(item); scene()->addItem(item);
handles << item; handles << item;
createDecoStops();
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();
}
} }
void DivePlannerGraphics::clearGeneratedDeco() void DivePlannerGraphics::clearGeneratedDeco()
{ {
for (int i = handles.count(); i <= lines.count(); i++) {
scene()->removeItem(lines.last());
delete lines.last();
lines.removeLast();
}
} }
void DivePlannerGraphics::createDecoStops() void DivePlannerGraphics::createDecoStops()
{ {
qDeleteAll(lines);
lines.clear();
// This needs to be done in the following steps: // This needs to be done in the following steps:
// Get the user-input and calculate the dive info // Get the user-input and calculate the dive info
// Not sure if this is the place to create the diveplan... // Not sure if this is the place to create the diveplan...
@ -154,21 +134,36 @@ void DivePlannerGraphics::createDecoStops()
while(dp->next) while(dp->next)
dp = dp->next; dp = dp->next;
if (timeLine->maximum() < dp->time / 60.0 + 5) {
// this causes all kinds of bad things as the //if (timeLine->maximum() < dp->time / 60.0 + 5) {
// handle that you are holding on to gets scaled out
// 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(); timeLine->updateTicks();
} //}
// Re-position the user generated dive handlers // Re-position the user generated dive handlers
Q_FOREACH(DiveHandler *h, handles){ Q_FOREACH(DiveHandler *h, handles){
h->setPos(timeLine->posAtValue(h->sec / 60), depthLine->posAtValue(h->mm) / 1000); 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. // Create all 'deco' GraphicsLineItems and put it on the canvas.
double lastx = handles.last()->x(); double lastx = handles.last()->x();
double lasty = handles.last()->y(); double lasty = handles.last()->y();
@ -179,6 +174,7 @@ void DivePlannerGraphics::createDecoStops()
double ypos = depthLine->posAtValue(dp->depth / 1000.0); double ypos = depthLine->posAtValue(dp->depth / 1000.0);
qDebug("time/depth %f/%f", dp->time / 60.0, 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); QGraphicsLineItem *item = new QGraphicsLineItem(lastx, lasty, xpos, ypos);
item->setPen(QPen(QBrush(Qt::red),0));
lastx = xpos; lastx = xpos;
lasty = ypos; lasty = ypos;
scene()->addItem(item); scene()->addItem(item);
@ -241,36 +237,21 @@ void DivePlannerGraphics::moveActiveHandler(const QPointF& pos)
if (idx == 0 ) { // first if (idx == 0 ) { // first
if (newPos.x() < handles[1]->x()) { if (newPos.x() < handles[1]->x()) {
activeDraggedHandler->setPos(newPos); activeDraggedHandler->setPos(newPos);
moveLines = true;
} }
} else if (idx == handles.count()-1) { // last } else if (idx == handles.count()-1) { // last
if (newPos.x() > handles[idx-1]->x()) { if (newPos.x() > handles[idx-1]->x()) {
activeDraggedHandler->setPos(newPos); activeDraggedHandler->setPos(newPos);
moveLines = true;
} }
} else { // middle } else { // middle
if (newPos.x() > handles[idx-1]->x() && newPos.x() < handles[idx+1]->x()) { if (newPos.x() > handles[idx-1]->x() && newPos.x() < handles[idx+1]->x()) {
activeDraggedHandler->setPos(newPos); activeDraggedHandler->setPos(newPos);
moveLines = true;
} }
} }
} else { } else {
activeDraggedHandler->setPos(newPos); 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) bool DivePlannerGraphics::isPointOutOfBoundaries(const QPointF& point)
@ -307,12 +288,7 @@ void DivePlannerGraphics::mouseReleaseEvent(QMouseEvent* event)
activeDraggedHandler->sec = rint(timeLine->valueAt(mappedPos)) * 60; activeDraggedHandler->sec = rint(timeLine->valueAt(mappedPos)) * 60;
activeDraggedHandler->mm = rint(depthLine->valueAt(mappedPos)) * 1000; activeDraggedHandler->mm = rint(depthLine->valueAt(mappedPos)) * 1000;
activeDraggedHandler->setBrush(QBrush()); activeDraggedHandler->setBrush(QBrush());
createDecoStops();
if (activeDraggedHandler == handles.last()) {
clearGeneratedDeco();
createDecoStops();
}
activeDraggedHandler = 0; activeDraggedHandler = 0;
} }
} }