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 | |
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>
-rw-r--r-- | qt-ui/diveplanner.cpp | 26 | ||||
-rw-r--r-- | qt-ui/diveplanner.h | 5 | ||||
-rw-r--r-- | qt-ui/mainwindow.cpp | 3 | ||||
-rw-r--r-- | qt-ui/profile/profilewidget2.cpp | 57 | ||||
-rw-r--r-- | qt-ui/profile/profilewidget2.h | 1 |
5 files changed, 58 insertions, 34 deletions
diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index f4f3d5036..6e11f84aa 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -150,13 +150,6 @@ DivePlannerGraphics::DivePlannerGraphics(QWidget *parent) : QGraphicsView(parent ADD_ACTION(Qt::Key_Right, keyRightAction()); #undef ADD_ACTION - connect(plannerModel, SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(drawProfile())); - connect(plannerModel, SIGNAL(cylinderModelEdited()), this, SLOT(drawProfile())); - - 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))); setRenderHint(QPainter::Antialiasing); } @@ -504,23 +497,6 @@ void DivePlannerGraphics::drawProfile() depthLine->updateTicks(); } - // 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(timeLine->posAtValue(datapoint.time / 60), depthLine->posAtValue(datapoint.depth)); - QPointF p1 = (last == i) ? QPointF(timeLine->posAtValue(0), depthLine->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; - } - // (re-) create the profile with different colors for segments that were // entered vs. segments that were calculated double lastx = timeLine->posAtValue(0); @@ -1379,7 +1355,7 @@ void DivePlannerPointsModel::remove(const QModelIndex &index) endRemoveRows(); } -struct diveplan DivePlannerPointsModel::getDiveplan() +struct diveplan& DivePlannerPointsModel::getDiveplan() { return diveplan; } diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h index 94fcdeb53..a61f9520d 100644 --- a/qt-ui/diveplanner.h +++ b/qt-ui/diveplanner.h @@ -55,7 +55,7 @@ public: void editStop(int row, divedatapoint newData); divedatapoint at(int row); int size(); - struct diveplan getDiveplan(); + struct diveplan& getDiveplan(); QStringList &getGasList(); QVector<QPair<int, int> > collectGases(dive *d); int lastEnteredPoint(); @@ -276,4 +276,7 @@ private: Ui::DivePlanner ui; }; +QString gasToStr(const int o2Permille, const int hePermille); +QString dpGasToStr(const divedatapoint &p); + #endif // DIVEPLANNER_H diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index 33946f34f..9b00db2f1 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -410,10 +410,11 @@ void MainWindow::on_actionAddDive_triggered() ui.InfoWidget->updateDiveInfo(selected_dive); ui.InfoWidget->addDiveStarted(); ui.infoPane->setCurrentIndex(MAINTAB); + + ui.newProfile->setAddState(); DivePlannerPointsModel::instance()->clear(); DivePlannerPointsModel::instance()->createSimpleDive(); ui.ListWidget->reload(DiveTripModel::CURRENT); - ui.newProfile->setAddState(); } void MainWindow::on_actionRenumber_triggered() 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 |