mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 14:25:27 +00:00
Removed inconsistency when user tried to add dive while planning.
The user could add a dive, and in the middle click on the 'plan' button. Since we didn't cared about that on the widget, a lot of inconsistencies could occour. this fixes that by setting a flag on the Planner, that has now three modes: nothing, plan and add. (maybe in the future an edit mode will be valid too.) If in 'NOTHING' mode, user can enter the addition, edition and planning. If in any other mode, user can't do a thing. The mode gets back to NOTHING when user accepts or cancels a plan / add / edition. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
f850a0817c
commit
8a970c64c2
4 changed files with 46 additions and 25 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue