aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-08-26 14:17:39 -0300
committerGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-08-26 14:17:39 -0300
commitbc71f9a9160cd704e6a01e5485cadba950d758e9 (patch)
treefc73ced10f2794006ffa0671e495909bf71aecbc
parent024dd80664a160671922043762491d11f7d60b5a (diff)
downloadsubsurface-bc71f9a9160cd704e6a01e5485cadba950d758e9.tar.gz
Moved the creation of the data plan point to the model.
Moved the creation of the data plan point to the model, this way when the user creates a data point on the graphical planner, or when the user creates the point on the QWidget based view, both of them will be updated. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
-rw-r--r--qt-ui/diveplanner.cpp79
-rw-r--r--qt-ui/diveplanner.h4
2 files changed, 56 insertions, 27 deletions
diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp
index 6587185a7..94b1c05f7 100644
--- a/qt-ui/diveplanner.cpp
+++ b/qt-ui/diveplanner.cpp
@@ -142,9 +142,35 @@ DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent)
gasListView->hide();
connect(gasListView, SIGNAL(activated(QModelIndex)), this, SLOT(selectGas(QModelIndex)));
+ connect(DivePlannerPointsModel::instance(), SIGNAL(rowsInserted(const QModelIndex&,int,int)),
+ this, SLOT(pointInserted(const QModelIndex&, int, int)));
setRenderHint(QPainter::Antialiasing);
}
+void DivePlannerGraphics::pointInserted(const QModelIndex& parent, int start , int end)
+{
+ qDebug() << "Adicionou";
+ divedatapoint point = DivePlannerPointsModel::instance()->at(start);
+ DiveHandler *item = new DiveHandler ();
+ double xpos = timeLine->posAtValue(point.time);
+ double ypos = depthLine->posAtValue(point.depth);
+ item->sec = point.time * 60;
+ item->mm = point.depth * 1000;
+ item->setPos(QPointF(xpos, ypos));
+ qDebug() << xpos << ypos;
+ scene()->addItem(item);
+ handles << item;
+
+ Button *gasChooseBtn = new Button();
+ gasChooseBtn ->setText(tr("Air"));
+ scene()->addItem(gasChooseBtn);
+ gasChooseBtn->setZValue(10);
+ connect(gasChooseBtn, SIGNAL(clicked()), this, SLOT(prepareSelectGas()));
+
+ gases << gasChooseBtn;
+ createDecoStops();
+}
+
void DivePlannerGraphics::keyDownAction()
{
if(scene()->selectedItems().count()){
@@ -341,32 +367,31 @@ void DivePlannerGraphics::mouseDoubleClickEvent(QMouseEvent* event)
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()){
- qDebug() << "There's already an point at that place.";
- //TODO: Move this later to a KMessageWidget.
- return;
- }
- }
- DivePlannerPointsModel::instance()->addStop(meters, minutes, tr("Air"), 0);
- DiveHandler *item = new DiveHandler ();
- item->sec = minutes * 60;
- item->mm = meters * 1000;
- item->setPos(QPointF(xpos, ypos));
- scene()->addItem(item);
- handles << item;
+// 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;
+// }
+// }
- Button *gasChooseBtn = new Button();
- gasChooseBtn ->setText(tr("Air"));
- scene()->addItem(gasChooseBtn);
- gasChooseBtn->setZValue(10);
- connect(gasChooseBtn, SIGNAL(clicked()), this, SLOT(prepareSelectGas()));
-
- gases << gasChooseBtn;
- createDecoStops();
+ DivePlannerPointsModel::instance()->addStop(meters, minutes, tr("Air"), 0);
+// DiveHandler *item = new DiveHandler ();
+// item->sec = minutes * 60;
+// item->mm = meters * 1000;
+// item->setPos(QPointF(xpos, ypos));
+// scene()->addItem(item);
+// handles << item;
+//
+// Button *gasChooseBtn = new Button();
+// gasChooseBtn ->setText(tr("Air"));
+// scene()->addItem(gasChooseBtn);
+// gasChooseBtn->setZValue(10);
+// connect(gasChooseBtn, SIGNAL(clicked()), this, SLOT(prepareSelectGas()));
+//
+// gases << gasChooseBtn;
+// createDecoStops();
}
void DivePlannerGraphics::prepareSelectGas()
@@ -751,7 +776,7 @@ void Ruler::setColor(const QColor& color)
Button::Button(QObject* parent): QObject(parent), QGraphicsRectItem()
{
- icon = new QGraphicsPixmapItem(this);
+ icon = new QGraphicsPixmapItem(this);
text = new QGraphicsSimpleTextItem(this);
icon->setPos(0,0);
text->setPos(0,0);
@@ -939,3 +964,7 @@ int DivePlannerPointsModel::addStop(int meters, int minutes, const QString& gas,
return row;
}
+divedatapoint DivePlannerPointsModel::at(int row)
+{
+ return divepoints.at(row);
+}
diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h
index ab466da8e..e8951b682 100644
--- a/qt-ui/diveplanner.h
+++ b/qt-ui/diveplanner.h
@@ -31,7 +31,7 @@ public:
* @return the row number.
*/
int addStop(int meters, int minutes,const QString& gas, int ccpoint );
-
+ divedatapoint at(int row);
public slots:
void setGFHigh(short gfhigh);
void setGFLow(short ghflow);
@@ -131,7 +131,7 @@ private slots:
void cancelPlan();
void prepareSelectGas();
void selectGas(const QModelIndex& index);
-
+ void pointInserted(const QModelIndex&, int start, int end);
private:
void moveActiveHandler(const QPointF& pos);