diff options
author | Tomaz Canabrava <tomaz.canabrava@intel.com> | 2013-11-01 11:48:34 -0400 |
---|---|---|
committer | Tomaz Canabrava <tomaz.canabrava@intel.com> | 2013-11-01 11:48:34 -0400 |
commit | f7cd3e780cdc77180ce279c95322de2095192657 (patch) | |
tree | 30be9f9d9071be59f74e60fb55c3f67b70f909a4 | |
parent | d9afcdc8cb0239d07b0578bbe2b4e4efe87c5958 (diff) | |
download | subsurface-f7cd3e780cdc77180ce279c95322de2095192657.tar.gz |
Enable editing a dive that was manually entered.
This patch enables editing a dive that was manually entered,
it doesn't cover dive plans yet because on the plan I need to
figure out what are the 'user-entered' points, and what are
the algorithm point. and I feel lazy. =p
One last thing that's missing is to revert the dive to the
previous condition if the user cancels the edition, currently
canceling and applying ok is the same thing.
Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
-rw-r--r-- | qt-ui/diveplanner.cpp | 22 | ||||
-rw-r--r-- | qt-ui/diveplanner.h | 1 | ||||
-rw-r--r-- | qt-ui/maintab.cpp | 9 | ||||
-rw-r--r-- | qt-ui/maintab.h | 4 | ||||
-rw-r--r-- | qt-ui/mainwindow.cpp | 20 | ||||
-rw-r--r-- | qt-ui/mainwindow.h | 1 |
6 files changed, 51 insertions, 6 deletions
diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index 2078ff8a8..f4bbfafa0 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -425,6 +425,28 @@ void DivePlannerPointsModel::createSimpleDive() plannerModel->addStop(M_OR_FT(5,15), 45 * 60, tr("Air"), 0); } +void DivePlannerPointsModel::loadFromDive(dive* d) +{ + int totalSamples = d->dc.samples -2; // removes begin and end. + + /* We need to make a copy, because + * as soon as the model is modified, it will + * remove all samples from the current dive. + * + * TODO: keep a backup of the values, + * so we can restore. + * */ + QList<QPair<int,int> > values; + for(int i = 1; i < d->dc.samples-1; i++){ + struct sample &s = d->dc.sample[i]; + values.append( qMakePair(s.depth.mm, s.time.seconds)); + } + + for(int i = 0; i < totalSamples; i++){ + plannerModel->addStop(values[i].first, values[i].second, tr("Air"), 0); + } +} + void DivePlannerGraphics::prepareSelectGas() { currentGasChoice = static_cast<Button*>(sender()); diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h index acb36e63e..90859abe9 100644 --- a/qt-ui/diveplanner.h +++ b/qt-ui/diveplanner.h @@ -54,6 +54,7 @@ public slots: void cancelPlan(); void createTemporaryPlan(); void deleteTemporaryPlan(); + void loadFromDive(dive* d); signals: void planCreated(); diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index 8d2324382..f88d7c6d0 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -113,7 +113,7 @@ void MainTab::addDiveStarted() editMode = ADD; } -void MainTab::enableEdition() +void MainTab::enableEdition(EditMode newEditMode) { if (selected_dive < 0 || editMode != NONE) return; @@ -170,7 +170,8 @@ void MainTab::enableEdition() notesBackup[mydive].weightsystem[i] = mydive->weightsystem[i]; } } - editMode = DIVE; + + editMode = newEditMode != NONE ? newEditMode : DIVE; } } @@ -449,7 +450,7 @@ void MainTab::acceptChanges() } } - if (editMode == ADD) { + if (editMode == ADD || editMode == MANUALLY_ADDED_DIVE) { // clean up the dive data (get duration, depth information from samples) fixup_dive(current_dive); if (dive_table.nr == 1) @@ -563,7 +564,7 @@ void MainTab::rejectChanges() ui.equipmentButtonBox->hide(); notesBackup.clear(); resetPallete(); - if (editMode == ADD) { + if (editMode == ADD || editMode == MANUALLY_ADDED_DIVE) { // more clean up updateDiveInfo(selected_dive); mainWindow()->showProfile(); diff --git a/qt-ui/maintab.h b/qt-ui/maintab.h index 9cfe43a26..1f586e70a 100644 --- a/qt-ui/maintab.h +++ b/qt-ui/maintab.h @@ -46,6 +46,7 @@ class MainTab : public QTabWidget { Q_OBJECT public: + enum EditMode { NONE, DIVE, TRIP, ADD, MANUALLY_ADDED_DIVE } editMode; MainTab(QWidget *parent); void clearStats(); void clearInfo(); @@ -74,6 +75,7 @@ public slots: void editCylinderWidget(const QModelIndex& index); void editWeightWidget(const QModelIndex& index); void addDiveStarted(); + void enableEdition(EditMode newEditMode = NONE); private: Ui::MainTab ui; @@ -88,9 +90,7 @@ private: * then applying the changes on the other dives.*/ struct dive multiEditEquipmentPlaceholder; - enum { NONE, DIVE, TRIP, ADD } editMode; Completers completers; - void enableEdition(); void resetPallete(); QString printGPSCoords(int lat, int lon); }; diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index d2121e510..2be60edb7 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -819,3 +819,23 @@ void MainWindow::on_actionImportCSV_triggered() process_dives(TRUE, FALSE); refreshDisplay(); } + + +void MainWindow::editCurrentDive() +{ + struct dive *d = current_dive; + QString defaultDC(d->dc.model); + + if (defaultDC == tr("manually added dive")){ + disableDcShortcuts(); + DivePlannerPointsModel::instance()->setPlanMode(false); + ui.stackedWidget->setCurrentIndex(PLANNERPROFILE); // Planner. + ui.infoPane->setCurrentIndex(MAINTAB); + DivePlannerPointsModel::instance()->loadFromDive(d); + ui.InfoWidget->enableEdition(MainTab::MANUALLY_ADDED_DIVE); + } + else if (defaultDC == tr("Simulated Dive")){ + + } + +} diff --git a/qt-ui/mainwindow.h b/qt-ui/mainwindow.h index 1c68fc4f7..e35230a3c 100644 --- a/qt-ui/mainwindow.h +++ b/qt-ui/mainwindow.h @@ -109,6 +109,7 @@ public slots: void readSettings(); void refreshDisplay(); void showProfile(); + void editCurrentDive(); private: Ui::MainWindow ui; |