diff options
author | Tomaz Canabrava <tomaz.canabrava@intel.com> | 2014-05-21 23:31:26 -0300 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-05-22 14:41:26 +0900 |
commit | f99ccc8ac2ba4ebcf2ae69e03ba9183ea71a0025 (patch) | |
tree | 1bf91fbfbc4d4b35c53dea57139d6335802c8549 /qt-ui/profile | |
parent | c6ad04d076a24001ded7bc099498dd6deb97949b (diff) | |
download | subsurface-f99ccc8ac2ba4ebcf2ae69e03ba9183ea71a0025.tar.gz |
Profile now correctly displays the planned dive.
But it doesn't move the handlers yet, and when you confirm it you also
must click on the dive to select it or the profile will show garbage.
Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/profile')
-rw-r--r-- | qt-ui/profile/profilewidget2.cpp | 57 | ||||
-rw-r--r-- | qt-ui/profile/profilewidget2.h | 1 |
2 files changed, 51 insertions, 7 deletions
diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp index 2ece177a7..6e565e77e 100644 --- a/qt-ui/profile/profilewidget2.cpp +++ b/qt-ui/profile/profilewidget2.cpp @@ -138,7 +138,7 @@ void ProfileWidget2::addItemsToScene() scene()->addItem(rulerItem); scene()->addItem(rulerItem->sourceNode()); scene()->addItem(rulerItem->destNode()); - Q_FOREACH(DiveCalculatedTissue * tissue, allTissues) { + Q_FOREACH (DiveCalculatedTissue * tissue, allTissues) { scene()->addItem(tissue); } } @@ -343,6 +343,19 @@ void ProfileWidget2::plotDives(QList<dive *> dives) if (!d) return; + //TODO: This is a temporary hack to help me understand the Planner. + // It seems that each time the 'createTemporaryPlan' runs, a new + // dive is created, and thus, we can plot that. hm... + if (currentState == ADD) { + DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance(); + plannerModel->createTemporaryPlan(); + if (!plannerModel->getDiveplan().dp) { + plannerModel->deleteTemporaryPlan(); + return; + } + } + //END + int animSpeedBackup = -1; if (firstCall && MainWindow::instance()->filesFromCommandLine()) { animSpeedBackup = prefs.animation; @@ -478,6 +491,12 @@ void ProfileWidget2::plotDives(QList<dive *> dives) if (MainWindow::instance()->filesFromCommandLine() && animSpeedBackup != -1) { prefs.animation = animSpeedBackup; } + + if (currentState == ADD) { // TODO: figure a way to move this from here. + repositionDiveHandlers(); + DivePlannerPointsModel *model = DivePlannerPointsModel::instance(); + model->deleteTemporaryPlan(); + } } void ProfileWidget2::settingsChanged() @@ -644,11 +663,6 @@ void ProfileWidget2::setProfileState() if (currentState == PROFILE) return; - if (dive_table.nr == 0) { // oops, called to plot something with zero dives. bail out. - setEmptyState(); - return; - } - disconnectTemporaryConnections(); currentState = PROFILE; MainWindow::instance()->setToolButtonsEnabled(true); @@ -709,7 +723,15 @@ void ProfileWidget2::setAddState() if (currentState == ADD) return; + setProfileState(); disconnectTemporaryConnections(); + DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance(); + connect(plannerModel, SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(replot())); + connect(plannerModel, SIGNAL(cylinderModelEdited()), this, SLOT(replot())); + connect(plannerModel, SIGNAL(rowsInserted(const QModelIndex &, int, int)), + this, SLOT(pointInserted(const QModelIndex &, int, int))); + connect(plannerModel, SIGNAL(rowsRemoved(const QModelIndex &, int, int)), + this, SLOT(pointsRemoved(const QModelIndex &, int, int))); /* show the same stuff that the profile shows. */ currentState = ADD; /* enable the add state. */ setBackgroundBrush(QColor(Qt::blue).light()); @@ -719,7 +741,7 @@ void ProfileWidget2::setPlanState() { if (currentState == PLAN) return; - + setProfileState(); disconnectTemporaryConnections(); /* show the same stuff that the profile shows. */ currentState = PLAN; /* enable the add state. */ @@ -964,3 +986,24 @@ void ProfileWidget2::pointsRemoved(const QModelIndex &, int start, int end) scene()->clearSelection(); replot(); } + +void ProfileWidget2::repositionDiveHandlers() +{ + DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance(); + // Re-position the user generated dive handlers + int last = 0; + for (int i = 0; i < plannerModel->rowCount(); i++) { + struct divedatapoint datapoint = plannerModel->at(i); + if (datapoint.time == 0) // those are the magic entries for tanks + continue; + DiveHandler *h = handles.at(i); + h->setPos(timeAxis->posAtValue(datapoint.time), profileYAxis->posAtValue(datapoint.depth)); + QPointF p1 = (last == i) ? QPointF(timeAxis->posAtValue(0), profileYAxis->posAtValue(0)) : handles[last]->pos(); + QPointF p2 = handles[i]->pos(); + QLineF line(p1, p2); + QPointF pos = line.pointAt(0.5); + gases[i]->setPos(pos); + gases[i]->setText(dpGasToStr(plannerModel->at(i))); + last = i; + } +} diff --git a/qt-ui/profile/profilewidget2.h b/qt-ui/profile/profilewidget2.h index 2ba1cd01a..9b9802ed0 100644 --- a/qt-ui/profile/profilewidget2.h +++ b/qt-ui/profile/profilewidget2.h @@ -145,6 +145,7 @@ private: //specifics for ADD and PLAN QList<DiveHandler *> handles; QList<QGraphicsSimpleTextItem *> gases; + void repositionDiveHandlers(); }; #endif // PROFILEWIDGET2_H |