aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-07-04 10:06:52 -0300
committerGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-07-04 10:06:52 -0300
commit603d2f5cb3c748bbb64711a99d1c115f6407d09e (patch)
tree0fd185b3fa9d0be4c70cf1196bf9a79da25286e1
parent55f8979160080998e5353a5cbecf00e9995c5db2 (diff)
downloadsubsurface-603d2f5cb3c748bbb64711a99d1c115f6407d09e.tar.gz
Make it possible to add a handler between others
Make it possible to add a handler between others, someone asked why I didn't make like this from the beginning, the answer is that I wanted to have something stable before messing a bit more with the planner, but since the planer is almost-stable, I added. :) Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
-rw-r--r--qt-ui/diveplanner.cpp26
1 files changed, 18 insertions, 8 deletions
diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp
index 8b82d9573..d4c6e9561 100644
--- a/qt-ui/diveplanner.cpp
+++ b/qt-ui/diveplanner.cpp
@@ -18,6 +18,10 @@
#define MAX_DEEPNESS 150
#define MIN_DEEPNESS 40
+bool handlerLessThenMinutes(DiveHandler *d1, DiveHandler *d2){
+ return d1->sec < d2->sec;
+}
+
DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent), activeDraggedHandler(0),
lastValidPos(0.0, 0.0)
{
@@ -163,21 +167,25 @@ void DivePlannerGraphics::mouseDoubleClickEvent(QMouseEvent* event)
if (isPointOutOfBoundaries(mappedPos))
return;
- if (handles.count() && handles.last()->x() > mappedPos.x())
- return;
-
- DiveHandler *item = new DiveHandler ();
- item->setRect(-5,-5,10,10);
- item->setFlag(QGraphicsItem::ItemIgnoresTransformations);
int minutes = rint(timeLine->valueAt(mappedPos));
int meters = rint(depthLine->valueAt(mappedPos));
- item->sec = minutes * 60;
- item->mm = meters * 1000;
double xpos = timeLine->posAtValue(minutes);
double ypos = depthLine->posAtValue(meters);
+ Q_FOREACH(DiveHandler* handler, handles){
+ if (xpos == handler->pos().x()){
+ qDebug() << "There's already an point at that place.";
+ //TODO: Move this later to a KMessageWidget.
+ return;
+ }
+ }
+
+ DiveHandler *item = new DiveHandler ();
+ item->sec = minutes * 60;
+ item->mm = meters * 1000;
item->setPos(QPointF(xpos, ypos));
scene()->addItem(item);
handles << item;
+ qSort(handles.begin(), handles.end(), handlerLessThenMinutes);
createDecoStops();
}
@@ -403,6 +411,8 @@ void DivePlannerGraphics::mouseReleaseEvent(QMouseEvent* event)
DiveHandler::DiveHandler(): QGraphicsEllipseItem(), from(0), to(0)
{
+ setRect(-5,-5,10,10);
+ setFlag(QGraphicsItem::ItemIgnoresTransformations);
setBrush(Qt::white);
setZValue(2);
}