From f7cd3e780cdc77180ce279c95322de2095192657 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Fri, 1 Nov 2013 11:48:34 -0400 Subject: 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 --- qt-ui/diveplanner.h | 1 + 1 file changed, 1 insertion(+) (limited to 'qt-ui/diveplanner.h') 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(); -- cgit v1.2.3-70-g09d2 From 23a193b0d1a94098ebcf1b5bafbc79ed879b5106 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Fri, 1 Nov 2013 13:45:14 -0400 Subject: Changed the backup implementation of the samples on EditDive. Changed the backup implementation of the samples on EditDive, it's way cleaner now what's happening, and it's also better for the cancel edit. Next: The Cancel Edit. Signed-off-by: Tomaz Canabrava --- qt-ui/diveplanner.cpp | 14 ++++---------- qt-ui/diveplanner.h | 1 + 2 files changed, 5 insertions(+), 10 deletions(-) (limited to 'qt-ui/diveplanner.h') diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index f4bbfafa0..d94e96570 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -427,23 +427,17 @@ void DivePlannerPointsModel::createSimpleDive() 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 > values; + backupSamples.clear(); 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)); + backupSamples.push_back( d->dc.sample[i]); } - for(int i = 0; i < totalSamples; i++){ - plannerModel->addStop(values[i].first, values[i].second, tr("Air"), 0); + Q_FOREACH(const sample &s, backupSamples){ + plannerModel->addStop(s.depth.mm, s.time.seconds, tr("Air"), 0); } } diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h index 90859abe9..6812b26ef 100644 --- a/qt-ui/diveplanner.h +++ b/qt-ui/diveplanner.h @@ -67,6 +67,7 @@ private: QVector divepoints; struct dive *tempDive; void deleteTemporaryPlan(struct divedatapoint *dp); + QVector backupSamples; // For editing added dives. }; class Button : public QObject, public QGraphicsRectItem { -- cgit v1.2.3-70-g09d2 From 0e96c9f62e3a7030d9208f32e59390cb3fd20bbe Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Fri, 1 Nov 2013 14:06:03 -0400 Subject: Enable undo for the Edit mode on Added Dives. This enables undo for the edit mode on added dives, it uses the premade backup to fill the old dive with data. :) Signed-off-by: Tomaz Canabrava --- qt-ui/diveplanner.cpp | 10 ++++++++++ qt-ui/diveplanner.h | 2 +- qt-ui/maintab.cpp | 3 +++ qt-ui/maintab.h | 4 +++- 4 files changed, 17 insertions(+), 2 deletions(-) (limited to 'qt-ui/diveplanner.h') diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index d94e96570..169158987 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -1197,6 +1197,16 @@ void DivePlannerPointsModel::createTemporaryPlan() #endif } +void DivePlannerPointsModel::undoEdition() +{ + beginRemoveRows(QModelIndex(), 0, rowCount()-1); + divepoints.clear(); + endRemoveRows(); + Q_FOREACH(const sample &s, backupSamples){ + plannerModel->addStop(s.depth.mm, s.time.seconds, tr("Air"), 0); + } +} + void DivePlannerPointsModel::deleteTemporaryPlan() { deleteTemporaryPlan(diveplan.dp); diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h index 6812b26ef..6883f62eb 100644 --- a/qt-ui/diveplanner.h +++ b/qt-ui/diveplanner.h @@ -55,7 +55,7 @@ public slots: void createTemporaryPlan(); void deleteTemporaryPlan(); void loadFromDive(dive* d); - + void undoEdition(); signals: void planCreated(); void planCanceled(); diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index f88d7c6d0..ddcdc6c63 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -507,6 +507,9 @@ void MainTab::rejectChanges() delete_single_dive(selected_dive); DivePlannerPointsModel::instance()->cancelPlan(); } + else if (editMode == MANUALLY_ADDED_DIVE ){ + DivePlannerPointsModel::instance()->undoEdition(); + } struct dive *curr = current_dive; ui.notes->setText(notesBackup[curr].notes ); ui.location->setText(notesBackup[curr].location); diff --git a/qt-ui/maintab.h b/qt-ui/maintab.h index 1f586e70a..afc30a079 100644 --- a/qt-ui/maintab.h +++ b/qt-ui/maintab.h @@ -46,7 +46,8 @@ class MainTab : public QTabWidget { Q_OBJECT public: - enum EditMode { NONE, DIVE, TRIP, ADD, MANUALLY_ADDED_DIVE } editMode; + enum EditMode { NONE, DIVE, TRIP, ADD, MANUALLY_ADDED_DIVE }; + MainTab(QWidget *parent); void clearStats(); void clearInfo(); @@ -78,6 +79,7 @@ public slots: void enableEdition(EditMode newEditMode = NONE); private: + EditMode editMode; Ui::MainTab ui; WeightModel *weightModel; CylindersModel *cylindersModel; -- cgit v1.2.3-70-g09d2