aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--qt-ui/diveplanner.cpp35
-rw-r--r--qt-ui/diveplanner.h9
-rw-r--r--qt-ui/maintab.cpp2
-rw-r--r--qt-ui/mainwindow.cpp25
4 files changed, 46 insertions, 25 deletions
diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp
index c54cb9b19..a14124abc 100644
--- a/qt-ui/diveplanner.cpp
+++ b/qt-ui/diveplanner.cpp
@@ -431,13 +431,6 @@ void DivePlannerPointsModel::loadFromDive(dive* d)
* as soon as the model is modified, it will
* remove all samples from the current dive.
* */
-
- /* On the safe side, clear everything before
- editing the new dive. */
- beginRemoveRows(QModelIndex(), 0, rowCount()-1);
- divepoints.clear();
- endRemoveRows();
-
backupSamples.clear();
for(int i = 1; i < d->dc.samples-1; i++){
backupSamples.push_back( d->dc.sample[i]);
@@ -940,9 +933,9 @@ void DivePlannerWidget::lastStopChanged(bool checked)
plannerModel->setLastStop6m(checked);
}
-void DivePlannerPointsModel::setPlanMode(bool isPlan)
+void DivePlannerPointsModel::setPlanMode(Mode m)
{
- mode = isPlan ? PLAN : ADD;
+ mode = m;
}
bool DivePlannerPointsModel::isPlanner()
@@ -1028,7 +1021,7 @@ int DivePlannerPointsModel::rowCount(const QModelIndex& parent) const
return divepoints.count();
}
-DivePlannerPointsModel::DivePlannerPointsModel(QObject* parent): QAbstractTableModel(parent)
+DivePlannerPointsModel::DivePlannerPointsModel(QObject* parent): QAbstractTableModel(parent), mode(NOTHING)
{
}
@@ -1168,13 +1161,24 @@ void DivePlannerPointsModel::cancelPlan()
return;
}
}
+ clear();
+ emit planCanceled();
+ setPlanMode(NOTHING);
+}
+
+DivePlannerPointsModel::Mode DivePlannerPointsModel::currentMode() const
+{
+ return mode;
+}
+void DivePlannerPointsModel::clear()
+{
beginRemoveRows(QModelIndex(), 0, rowCount()-1);
divepoints.clear();
endRemoveRows();
- emit planCanceled();
}
+
void DivePlannerPointsModel::createTemporaryPlan()
{
// This needs to be done in the following steps:
@@ -1209,9 +1213,7 @@ void DivePlannerPointsModel::createTemporaryPlan()
void DivePlannerPointsModel::undoEdition()
{
- beginRemoveRows(QModelIndex(), 0, rowCount()-1);
- divepoints.clear();
- endRemoveRows();
+ clear();
Q_FOREACH(const sample &s, backupSamples){
plannerModel->addStop(s.depth.mm, s.time.seconds, tr("Air"), 0);
}
@@ -1249,8 +1251,7 @@ void DivePlannerPointsModel::createPlan()
// Remove and clean the diveplan, so we don't delete
// the dive by mistake.
diveplan.dp = NULL;
- beginRemoveRows(QModelIndex(), 0, rowCount() -1 );
- divepoints.clear();
- endRemoveRows();
+ clear();
planCreated();
+ setPlanMode(NOTHING);
}
diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h
index 6883f62eb..394a83bc0 100644
--- a/qt-ui/diveplanner.h
+++ b/qt-ui/diveplanner.h
@@ -21,6 +21,7 @@ class DivePlannerPointsModel : public QAbstractTableModel{
public:
static DivePlannerPointsModel* instance();
enum Sections{REMOVE, DEPTH, DURATION, GAS, CCSETPOINT, COLUMNS};
+ enum Mode { NOTHING, PLAN, ADD };
virtual int columnCount(const QModelIndex& parent = QModelIndex()) const;
virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;
@@ -28,11 +29,11 @@ public:
virtual bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
virtual Qt::ItemFlags flags(const QModelIndex& index) const;
void removeSelectedPoints(const QVector<int>& rows);
- enum Modes { PLAN, ADD };
- void setPlanMode(bool);
+ void setPlanMode(Mode mode);
bool isPlanner();
void createSimpleDive();
-
+ void clear();
+ Mode currentMode() const;
/**
* @return the row number.
*/
@@ -63,7 +64,7 @@ signals:
private:
explicit DivePlannerPointsModel(QObject* parent = 0);
struct diveplan diveplan;
- Modes mode;
+ Mode mode;
QVector<divedatapoint> divepoints;
struct dive *tempDive;
void deleteTemporaryPlan(struct divedatapoint *dp);
diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
index dfcb48a0c..ef9129c34 100644
--- a/qt-ui/maintab.cpp
+++ b/qt-ui/maintab.cpp
@@ -497,6 +497,7 @@ void MainTab::acceptChanges()
mainWindow()->showProfile();
mainWindow()->refreshDisplay();
mark_divelist_changed(TRUE);
+ DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::NOTHING);
}
editMode = NONE;
@@ -610,6 +611,7 @@ void MainTab::rejectChanges()
updateDiveInfo(selected_dive);
mainWindow()->showProfile();
mainWindow()->refreshDisplay();
+ DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::NOTHING);
}
editMode = NONE;
}
diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp
index 5c0a9b350..f7cd31e0e 100644
--- a/qt-ui/mainwindow.cpp
+++ b/qt-ui/mainwindow.cpp
@@ -219,8 +219,14 @@ void MainWindow::enableDcShortcuts()
void MainWindow::on_actionDivePlanner_triggered()
{
+ if(DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING){
+ qDebug() << DivePlannerPointsModel::instance()->currentMode();
+ QMessageBox::warning(this, tr("Warning"), "First finish the current edition before trying to do another." );
+ return;
+ }
disableDcShortcuts();
- DivePlannerPointsModel::instance()->setPlanMode(true);
+ DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::PLAN);
+ DivePlannerPointsModel::instance()->clear();
ui.stackedWidget->setCurrentIndex(PLANNERPROFILE);
ui.infoPane->setCurrentIndex(PLANNERWIDGET);
}
@@ -271,6 +277,11 @@ void MainWindow::on_actionEditDeviceNames_triggered()
void MainWindow::on_actionAddDive_triggered()
{
+ if(DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING){
+ QMessageBox::warning(this, tr("Warning"), "First finish the current edition before trying to do another." );
+ return;
+ }
+
// clear the selection
for (int i = 0; i < dive_table.nr; i++) {
struct dive *d = get_dive(i);
@@ -278,7 +289,8 @@ void MainWindow::on_actionAddDive_triggered()
deselect_dive(i);
}
disableDcShortcuts();
- DivePlannerPointsModel::instance()->setPlanMode(false);
+ DivePlannerPointsModel::instance()->clear();
+ DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::ADD);
// 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 + gettimezoneoffset();
@@ -825,12 +837,17 @@ void MainWindow::on_actionImportCSV_triggered()
void MainWindow::editCurrentDive()
{
+ if(DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING){
+ QMessageBox::warning(this, tr("Warning"), "First finish the current edition before trying to do another." );
+ return;
+ }
+
struct dive *d = current_dive;
QString defaultDC(d->dc.model);
-
+ DivePlannerPointsModel::instance()->clear();
if (defaultDC == "manually added dive"){
disableDcShortcuts();
- DivePlannerPointsModel::instance()->setPlanMode(false);
+ DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::ADD);
ui.stackedWidget->setCurrentIndex(PLANNERPROFILE); // Planner.
ui.infoPane->setCurrentIndex(MAINTAB);
DivePlannerPointsModel::instance()->loadFromDive(d);