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>
This commit is contained in:
Tomaz Canabrava 2013-11-01 11:48:34 -04:00
parent d9afcdc8cb
commit f7cd3e780c
6 changed files with 51 additions and 6 deletions

View file

@ -425,6 +425,28 @@ void DivePlannerPointsModel::createSimpleDive()
plannerModel->addStop(M_OR_FT(5,15), 45 * 60, tr("Air"), 0); 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() void DivePlannerGraphics::prepareSelectGas()
{ {
currentGasChoice = static_cast<Button*>(sender()); currentGasChoice = static_cast<Button*>(sender());

View file

@ -54,6 +54,7 @@ public slots:
void cancelPlan(); void cancelPlan();
void createTemporaryPlan(); void createTemporaryPlan();
void deleteTemporaryPlan(); void deleteTemporaryPlan();
void loadFromDive(dive* d);
signals: signals:
void planCreated(); void planCreated();

View file

@ -113,7 +113,7 @@ void MainTab::addDiveStarted()
editMode = ADD; editMode = ADD;
} }
void MainTab::enableEdition() void MainTab::enableEdition(EditMode newEditMode)
{ {
if (selected_dive < 0 || editMode != NONE) if (selected_dive < 0 || editMode != NONE)
return; return;
@ -170,7 +170,8 @@ void MainTab::enableEdition()
notesBackup[mydive].weightsystem[i] = mydive->weightsystem[i]; 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) // clean up the dive data (get duration, depth information from samples)
fixup_dive(current_dive); fixup_dive(current_dive);
if (dive_table.nr == 1) if (dive_table.nr == 1)
@ -563,7 +564,7 @@ void MainTab::rejectChanges()
ui.equipmentButtonBox->hide(); ui.equipmentButtonBox->hide();
notesBackup.clear(); notesBackup.clear();
resetPallete(); resetPallete();
if (editMode == ADD) { if (editMode == ADD || editMode == MANUALLY_ADDED_DIVE) {
// more clean up // more clean up
updateDiveInfo(selected_dive); updateDiveInfo(selected_dive);
mainWindow()->showProfile(); mainWindow()->showProfile();

View file

@ -46,6 +46,7 @@ class MainTab : public QTabWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
enum EditMode { NONE, DIVE, TRIP, ADD, MANUALLY_ADDED_DIVE } editMode;
MainTab(QWidget *parent); MainTab(QWidget *parent);
void clearStats(); void clearStats();
void clearInfo(); void clearInfo();
@ -74,6 +75,7 @@ public slots:
void editCylinderWidget(const QModelIndex& index); void editCylinderWidget(const QModelIndex& index);
void editWeightWidget(const QModelIndex& index); void editWeightWidget(const QModelIndex& index);
void addDiveStarted(); void addDiveStarted();
void enableEdition(EditMode newEditMode = NONE);
private: private:
Ui::MainTab ui; Ui::MainTab ui;
@ -88,9 +90,7 @@ private:
* then applying the changes on the other dives.*/ * then applying the changes on the other dives.*/
struct dive multiEditEquipmentPlaceholder; struct dive multiEditEquipmentPlaceholder;
enum { NONE, DIVE, TRIP, ADD } editMode;
Completers completers; Completers completers;
void enableEdition();
void resetPallete(); void resetPallete();
QString printGPSCoords(int lat, int lon); QString printGPSCoords(int lat, int lon);
}; };

View file

@ -819,3 +819,23 @@ void MainWindow::on_actionImportCSV_triggered()
process_dives(TRUE, FALSE); process_dives(TRUE, FALSE);
refreshDisplay(); 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")){
}
}

View file

@ -109,6 +109,7 @@ public slots:
void readSettings(); void readSettings();
void refreshDisplay(); void refreshDisplay();
void showProfile(); void showProfile();
void editCurrentDive();
private: private:
Ui::MainWindow ui; Ui::MainWindow ui;