From bfe1ea0cb23c0f072caae0ec61b072280fe2b1d7 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Mon, 16 Sep 2013 11:38:41 -0300 Subject: Plug the Cancel action on the Dive Planner Table and start the 'ok' code. Plug the cancel action on the dive planner ( before that, only by hitting the 'ESC' button things worked, so now you can also click on the Cancel box that's on the right of the planner profile window. Also, the beginning of the 'ok' code is also at place. Signed-off-by: Tomaz Canabrava --- qt-ui/diveplanner.cpp | 36 +++++++++++++++++++++++------------- qt-ui/diveplanner.h | 6 +++++- qt-ui/mainwindow.cpp | 2 +- 3 files changed, 29 insertions(+), 15 deletions(-) (limited to 'qt-ui') diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index 5d0299c88..f2e3c9462 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -317,7 +317,7 @@ void DivePlannerGraphics::keyEscAction() scene()->clearSelection(); return; } - cancelPlan(); + plannerModel->cancelPlan(); } qreal DivePlannerGraphics::fromPercent(qreal percent, Qt::Orientation orientation) @@ -327,18 +327,6 @@ qreal DivePlannerGraphics::fromPercent(qreal percent, Qt::Orientation orientatio return result; } -void DivePlannerGraphics::cancelPlan() -{ - if (handles.size()){ - if (QMessageBox::warning(mainWindow(), tr("Save the Plan?"), - tr("You have a working plan, \n are you sure that you wanna cancel it?"), - QMessageBox::Ok | QMessageBox::Cancel) != QMessageBox::Ok){ - return; - } - } - mainWindow()->showProfile(); -} - void DivePlannerGraphics::increaseDepth() { if (depthLine->maximum() + 10 > MAX_DEEPNESS) @@ -857,6 +845,12 @@ DivePlannerWidget::DivePlannerWidget(QWidget* parent, Qt::WindowFlags f): QWidge connect(ui->highGF, SIGNAL(textChanged(QString)), this, SLOT(gfhighChanged(QString))); connect(ui->lastStop, SIGNAL(toggled(bool)), this, SLOT(lastStopChanged(bool))); + // Creating the plan + connect(ui->buttonBox, SIGNAL(accepted()), plannerModel, SLOT(createPlan())); + connect(ui->buttonBox, SIGNAL(rejected()), plannerModel, SLOT(cancelPlan())); + connect(plannerModel, SIGNAL(planCreated()), mainWindow(), SLOT(showProfile())); + connect(plannerModel, SIGNAL(planCanceled()), mainWindow(), SLOT(showProfile())); + /* set defaults. */ ui->startTime->setTime( QTime(1, 0) ); ui->ATMPressure->setText( "1013" ); @@ -1111,3 +1105,19 @@ struct diveplan DivePlannerPointsModel::getDiveplan() { return diveplan; } + +void DivePlannerPointsModel::cancelPlan() +{ + if(rowCount()){ + if (QMessageBox::warning(mainWindow(), tr("Save the Plan?"), + tr("You have a working plan, \n are you sure that you wanna cancel it?"), + QMessageBox::Ok | QMessageBox::Cancel) != QMessageBox::Ok){ + return; + } + } + + beginRemoveRows(QModelIndex(), 0, rowCount()-1); + divepoints.clear(); + endRemoveRows(); + emit planCanceled(); +} diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h index 1bcea0c27..05191ec85 100644 --- a/qt-ui/diveplanner.h +++ b/qt-ui/diveplanner.h @@ -50,6 +50,11 @@ public slots: void setLastStop6m(bool value); void createPlan(); void remove(const QModelIndex& index); + void cancelPlan(); + +signals: + void planCreated(); + void planCanceled(); private: explicit DivePlannerPointsModel(QObject* parent = 0); @@ -135,7 +140,6 @@ private slots: void decreaseTime(); void decreaseDepth();; void createDecoStops(); - void cancelPlan(); void prepareSelectGas(); void selectGas(const QModelIndex& index); void pointInserted(const QModelIndex&, int start, int end); diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index f2f95897a..740849033 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -45,6 +45,7 @@ MainWindow* mainWindow() MainWindow::MainWindow() : ui(new Ui::MainWindow()), helpView(0) { + instance = this; ui->setupUi(this); setWindowIcon(QIcon(":subsurface-icon")); connect(ui->ListWidget, SIGNAL(currentDiveChanged(int)), this, SLOT(current_dive_changed(int))); @@ -59,7 +60,6 @@ MainWindow::MainWindow() : ui(new Ui::MainWindow()), helpView(0) ui->ListWidget->reloadHeaderActions(); ui->ListWidget->setFocus(); ui->globe->reload(); - instance = this; } // this gets called after we download dives from a divecomputer -- cgit v1.2.3-70-g09d2