From a7b19b251da3421060f9603133265f0a5d54492d Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Thu, 31 Oct 2013 16:50:09 -0400 Subject: Removed Reference to dangling pointer. We cannot use tr("").toLocal8bit().constData(); on a function that expects a char* because the object will be deleted on the next line, so a strdup is necessary. Signed-off-by: Tomaz Canabrava --- qt-ui/mainwindow.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'qt-ui') diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index 5a2f872b4..1dcf03314 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -280,7 +280,8 @@ void MainWindow::on_actionAddDive_triggered() // now cheat - create one dive that we use to store the info tab data in struct dive *dive = alloc_dive(); dive->when = QDateTime::currentMSecsSinceEpoch() / 1000L; - dive->dc.model = tr("manually added dive").toLocal8Bit().constData(); // do not use tr here since it expects a char*. + const char* model = strdup(tr("manulaly added dive").toLocal8Bit().constData()); + dive->dc.model = model; // do not use tr here since it expects a char*. record_dive(dive); select_dive(get_divenr(dive)); ui.InfoWidget->updateDiveInfo(selected_dive); -- cgit v1.2.3-70-g09d2 From 69d4ccae6db83173c2d87b2565852b530852c3cc Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Fri, 1 Nov 2013 09:33:39 -0400 Subject: Added a new option to edit the dives. Added a new option to edit the dive in the profile view. The option will only be visible if the dive was manually entered or if the dive is a plan. Signed-off-by: Tomaz Canabrava --- qt-ui/mainwindow.cpp | 2 +- qt-ui/profilegraphics.cpp | 16 ++++++++++++---- qt-ui/profilegraphics.h | 2 +- subsurface.qrc | 1 + 4 files changed, 15 insertions(+), 6 deletions(-) (limited to 'qt-ui') diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index 1dcf03314..d797b0fe1 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -280,7 +280,7 @@ void MainWindow::on_actionAddDive_triggered() // now cheat - create one dive that we use to store the info tab data in struct dive *dive = alloc_dive(); dive->when = QDateTime::currentMSecsSinceEpoch() / 1000L; - const char* model = strdup(tr("manulaly added dive").toLocal8Bit().constData()); + const char* model = strdup(tr("manually added dive").toLocal8Bit().constData()); dive->dc.model = model; // do not use tr here since it expects a char*. record_dive(dive); select_dive(get_divenr(dive)); diff --git a/qt-ui/profilegraphics.cpp b/qt-ui/profilegraphics.cpp index cba803de2..0eed723dd 100644 --- a/qt-ui/profilegraphics.cpp +++ b/qt-ui/profilegraphics.cpp @@ -342,7 +342,7 @@ void ProfileGraphicsView::plot(struct dive *d, bool forceRedraw) } if (!printMode) - addControlItems(); + addControlItems(d); if (rulerEnabled && !printMode) add_ruler(); @@ -378,20 +378,28 @@ void ProfileGraphicsView::plot_depth_scale() depthMarkers->setPos(depthMarkers->pos().x() - 10, 0); } -void ProfileGraphicsView::addControlItems() +void ProfileGraphicsView::addControlItems(struct dive *d) { QAction *scaleAction = new QAction(QIcon(":scale"), tr("Scale"), this); QAction *rulerAction = new QAction(QIcon(":ruler"), tr("Ruler"), this); QToolBar *toolBar = new QToolBar("", 0); toolBar->addAction(rulerAction); toolBar->addAction(scaleAction); + toolBar->setOrientation(Qt::Vertical); //make toolbar transparent - toolBar->setStyleSheet(QString::fromUtf8 ("background-color: rgba(255,255,255,0);")); + //toolBar->setStyleSheet(QString::fromUtf8 ("background-color: rgba(255,255,255,0);")); connect(scaleAction, SIGNAL(triggered()), this, SLOT(on_scaleAction())); connect(rulerAction, SIGNAL(triggered()), this, SLOT(on_rulerAction())); - toolBarProxy = scene()->addWidget(toolBar); //Put it into the lower right corner of the profile + + QString defaultDC(d->dc.model); + if (defaultDC == tr("manually added dive") || defaultDC == tr("Simulated Dive")) { + QAction *editAction = new QAction(QIcon(":edit"), tr("Edit"), this); + toolBar->addAction(editAction); + connect(editAction, SIGNAL(triggered()), mainWindow(), SLOT(editCurrentDive())); + } + toolBarProxy = scene()->addWidget(toolBar); toolBarProxy->setPos(gc.maxx-toolBar->width(), gc.maxy-toolBar->height()); } diff --git a/qt-ui/profilegraphics.h b/qt-ui/profilegraphics.h index 7fe4f9ff7..28e7b9d60 100644 --- a/qt-ui/profilegraphics.h +++ b/qt-ui/profilegraphics.h @@ -171,7 +171,7 @@ private: void plot_depth_scale(); - void addControlItems(); + void addControlItems(struct dive *d); void create_ruler(); void add_ruler(); diff --git a/subsurface.qrc b/subsurface.qrc index cda15944c..67efdc7a1 100644 --- a/subsurface.qrc +++ b/subsurface.qrc @@ -6,6 +6,7 @@ icons/trash.png icons/units.png icons/advanced.png + icons/advanced.png icons/graph.png icons/minimum.svg icons/maximum.svg -- cgit v1.2.3-70-g09d2 From d9afcdc8cb0239d07b0578bbe2b4e4efe87c5958 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Fri, 1 Nov 2013 09:43:41 -0400 Subject: Code cleanup - Stop calling the same 6 lines everywhere. There's a method named refreshDisplay, fairly unused, let's use it a bit mroe. Signed-off-by: Tomaz Canabrava --- qt-ui/mainwindow.cpp | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) (limited to 'qt-ui') diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index d797b0fe1..d2121e510 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -783,13 +783,7 @@ void MainWindow::importFiles(const QStringList fileNames) } } process_dives(TRUE, FALSE); - - ui.InfoWidget->reload(); - ui.globe->reload(); - ui.ListWidget->reload(DiveTripModel::TREE); - ui.ListWidget->setFocus(); - WSInfoModel *wsim = WSInfoModel::instance(); - wsim->updateInfo(); + refreshDisplay(); } void MainWindow::loadFiles(const QStringList fileNames) @@ -814,25 +808,14 @@ void MainWindow::loadFiles(const QStringList fileNames) process_dives(FALSE, FALSE); - ui.InfoWidget->reload(); - ui.globe->reload(); - ui.ListWidget->reload(DiveTripModel::TREE); - ui.ListWidget->setFocus(); - WSInfoModel *wsim = WSInfoModel::instance(); - wsim->updateInfo(); + refreshDisplay(); ui.actionAutoGroup->setChecked(autogroup); } void MainWindow::on_actionImportCSV_triggered() { - CSVImportDialog *csvImport = new(CSVImportDialog); + CSVImportDialog *csvImport = new CSVImportDialog(); csvImport->show(); process_dives(TRUE, FALSE); - - ui.InfoWidget->reload(); - ui.globe->reload(); - ui.ListWidget->reload(DiveTripModel::TREE); - ui.ListWidget->setFocus(); - WSInfoModel *wsim = WSInfoModel::instance(); - wsim->updateInfo(); + refreshDisplay(); } -- cgit v1.2.3-70-g09d2 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.cpp | 22 ++++++++++++++++++++++ qt-ui/diveplanner.h | 1 + qt-ui/maintab.cpp | 9 +++++---- qt-ui/maintab.h | 4 ++-- qt-ui/mainwindow.cpp | 20 ++++++++++++++++++++ qt-ui/mainwindow.h | 1 + 6 files changed, 51 insertions(+), 6 deletions(-) (limited to 'qt-ui') 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 > 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(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; -- 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') 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') 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