diff options
-rw-r--r-- | qt-ui/diveplanner.cpp | 26 | ||||
-rw-r--r-- | qt-ui/diveplanner.h | 4 | ||||
-rw-r--r-- | qt-ui/maintab.cpp | 12 | ||||
-rw-r--r-- | qt-ui/maintab.h | 6 | ||||
-rw-r--r-- | qt-ui/mainwindow.cpp | 46 | ||||
-rw-r--r-- | qt-ui/mainwindow.h | 1 | ||||
-rw-r--r-- | qt-ui/profilegraphics.cpp | 16 | ||||
-rw-r--r-- | qt-ui/profilegraphics.h | 2 | ||||
-rw-r--r-- | subsurface.qrc | 1 |
9 files changed, 81 insertions, 33 deletions
diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index 2078ff8a8..169158987 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -425,6 +425,22 @@ void DivePlannerPointsModel::createSimpleDive() plannerModel->addStop(M_OR_FT(5,15), 45 * 60, tr("Air"), 0); } +void DivePlannerPointsModel::loadFromDive(dive* d) +{ + /* We need to make a copy, because + * as soon as the model is modified, it will + * remove all samples from the current dive. + * */ + backupSamples.clear(); + for(int i = 1; i < d->dc.samples-1; i++){ + backupSamples.push_back( d->dc.sample[i]); + } + + Q_FOREACH(const sample &s, backupSamples){ + plannerModel->addStop(s.depth.mm, s.time.seconds, tr("Air"), 0); + } +} + void DivePlannerGraphics::prepareSelectGas() { currentGasChoice = static_cast<Button*>(sender()); @@ -1181,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 acb36e63e..6883f62eb 100644 --- a/qt-ui/diveplanner.h +++ b/qt-ui/diveplanner.h @@ -54,7 +54,8 @@ public slots: void cancelPlan(); void createTemporaryPlan(); void deleteTemporaryPlan(); - + void loadFromDive(dive* d); + void undoEdition(); signals: void planCreated(); void planCanceled(); @@ -66,6 +67,7 @@ private: QVector<divedatapoint> divepoints; struct dive *tempDive; void deleteTemporaryPlan(struct divedatapoint *dp); + QVector<sample> backupSamples; // For editing added dives. }; class Button : public QObject, public QGraphicsRectItem { diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index 8d2324382..ddcdc6c63 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) @@ -506,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); @@ -563,7 +567,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..afc30a079 100644 --- a/qt-ui/maintab.h +++ b/qt-ui/maintab.h @@ -46,6 +46,8 @@ class MainTab : public QTabWidget { Q_OBJECT public: + enum EditMode { NONE, DIVE, TRIP, ADD, MANUALLY_ADDED_DIVE }; + MainTab(QWidget *parent); void clearStats(); void clearInfo(); @@ -74,8 +76,10 @@ public slots: void editCylinderWidget(const QModelIndex& index); void editWeightWidget(const QModelIndex& index); void addDiveStarted(); + void enableEdition(EditMode newEditMode = NONE); private: + EditMode editMode; Ui::MainTab ui; WeightModel *weightModel; CylindersModel *cylindersModel; @@ -88,9 +92,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 5a2f872b4..2be60edb7 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("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)); ui.InfoWidget->updateDiveInfo(selected_dive); @@ -782,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) @@ -813,25 +808,34 @@ 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); + refreshDisplay(); +} - ui.InfoWidget->reload(); - ui.globe->reload(); - ui.ListWidget->reload(DiveTripModel::TREE); - ui.ListWidget->setFocus(); - WSInfoModel *wsim = WSInfoModel::instance(); - wsim->updateInfo(); + +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; 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 @@ <file alias="trash">icons/trash.png</file> <file alias="units">icons/units.png</file> <file alias="advanced">icons/advanced.png</file> + <file alias="edit">icons/advanced.png</file> <file alias="graph">icons/graph.png</file> <file alias="minimum">icons/minimum.svg</file> <file alias="maximum">icons/maximum.svg</file> |