mirror of
				https://github.com/subsurface/subsurface.git
				synced 2025-02-19 22:16:15 +00:00 
			
		
		
		
	Planner: better handle the temporary dive used for planning
This still crashes when you abort the plan. And when you accept the plan, the profile stays stuck in PLAN mode. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
		
							parent
							
								
									7feea7ccfa
								
							
						
					
					
						commit
						d1cd1eb933
					
				
					 3 changed files with 29 additions and 6 deletions
				
			
		| 
						 | 
					@ -247,8 +247,10 @@ DivePlannerWidget::DivePlannerWidget(QWidget *parent, Qt::WindowFlags f) : QWidg
 | 
				
			||||||
	// Creating the plan
 | 
						// Creating the plan
 | 
				
			||||||
	connect(ui.buttonBox, SIGNAL(accepted()), plannerModel, SLOT(createPlan()));
 | 
						connect(ui.buttonBox, SIGNAL(accepted()), plannerModel, SLOT(createPlan()));
 | 
				
			||||||
	connect(ui.buttonBox, SIGNAL(rejected()), plannerModel, SLOT(cancelPlan()));
 | 
						connect(ui.buttonBox, SIGNAL(rejected()), plannerModel, SLOT(cancelPlan()));
 | 
				
			||||||
 | 
						connect(plannerModel, SIGNAL(planCreated()), MainWindow::instance(), SLOT(removeFakeDiveForAddAndPlan()));
 | 
				
			||||||
	connect(plannerModel, SIGNAL(planCreated()), MainWindow::instance(), SLOT(showProfile()));
 | 
						connect(plannerModel, SIGNAL(planCreated()), MainWindow::instance(), SLOT(showProfile()));
 | 
				
			||||||
	connect(plannerModel, SIGNAL(planCreated()), MainWindow::instance(), SLOT(refreshDisplay()));
 | 
						connect(plannerModel, SIGNAL(planCreated()), MainWindow::instance(), SLOT(refreshDisplay()));
 | 
				
			||||||
 | 
						connect(plannerModel, SIGNAL(planCanceled()), MainWindow::instance(), SLOT(removeFakeDiveForAddAndPlan()));
 | 
				
			||||||
	connect(plannerModel, SIGNAL(planCanceled()), MainWindow::instance(), SLOT(showProfile()));
 | 
						connect(plannerModel, SIGNAL(planCanceled()), MainWindow::instance(), SLOT(showProfile()));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* set defaults. */
 | 
						/* set defaults. */
 | 
				
			||||||
| 
						 | 
					@ -647,14 +649,17 @@ void DivePlannerPointsModel::cancelPlan()
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	clear();
 | 
						clear();
 | 
				
			||||||
 | 
						// we unselected all dives earlier, so restore that first and then recreate the dive list
 | 
				
			||||||
 | 
						MainWindow::instance()->dive_list()->restoreSelection();
 | 
				
			||||||
 | 
						MainWindow::instance()->dive_list()->reload(DiveTripModel::CURRENT);
 | 
				
			||||||
 | 
						MainWindow::instance()->refreshDisplay();
 | 
				
			||||||
	emit planCanceled();
 | 
						emit planCanceled();
 | 
				
			||||||
	if (mode != ADD)
 | 
						if (mode != ADD) {
 | 
				
			||||||
		free(stagingDive);
 | 
							free(stagingDive);
 | 
				
			||||||
	setPlanMode(NOTHING);
 | 
					 | 
				
			||||||
		stagingDive = NULL;
 | 
							stagingDive = NULL;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						setPlanMode(NOTHING);
 | 
				
			||||||
	diveplan.dp = NULL;
 | 
						diveplan.dp = NULL;
 | 
				
			||||||
	CylindersModel::instance()->setDive(current_dive);
 | 
					 | 
				
			||||||
	CylindersModel::instance()->update();
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
DivePlannerPointsModel::Mode DivePlannerPointsModel::currentMode() const
 | 
					DivePlannerPointsModel::Mode DivePlannerPointsModel::currentMode() const
 | 
				
			||||||
| 
						 | 
					@ -854,6 +859,9 @@ void DivePlannerPointsModel::createPlan()
 | 
				
			||||||
	// the dive by mistake.
 | 
						// the dive by mistake.
 | 
				
			||||||
	diveplan.dp = NULL;
 | 
						diveplan.dp = NULL;
 | 
				
			||||||
	clear();
 | 
						clear();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// we unselected all dives earlier, so as a side effect recreating the dive list will select the new dive
 | 
				
			||||||
 | 
						MainWindow::instance()->recreateDiveList();
 | 
				
			||||||
	planCreated();
 | 
						planCreated();
 | 
				
			||||||
	setPlanMode(NOTHING);
 | 
						setPlanMode(NOTHING);
 | 
				
			||||||
	free(stagingDive);
 | 
						free(stagingDive);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -58,7 +58,8 @@ MainWindow::MainWindow() : QMainWindow(),
 | 
				
			||||||
	yearlyStats(0),
 | 
						yearlyStats(0),
 | 
				
			||||||
	yearlyStatsModel(0),
 | 
						yearlyStatsModel(0),
 | 
				
			||||||
	state(VIEWALL),
 | 
						state(VIEWALL),
 | 
				
			||||||
	updateManager(0)
 | 
						updateManager(0),
 | 
				
			||||||
 | 
						fakeDiveId(0)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	Q_ASSERT_X(m_Instance == NULL, "MainWindow", "MainWindow recreated!");
 | 
						Q_ASSERT_X(m_Instance == NULL, "MainWindow", "MainWindow recreated!");
 | 
				
			||||||
	m_Instance = this;
 | 
						m_Instance = this;
 | 
				
			||||||
| 
						 | 
					@ -372,6 +373,7 @@ void MainWindow::createFakeDiveForAddAndPlan()
 | 
				
			||||||
	// now cheat - create one dive that we use to store the info tab data in
 | 
						// now cheat - create one dive that we use to store the info tab data in
 | 
				
			||||||
	//TODO: C-function create_temporary_dive ?
 | 
						//TODO: C-function create_temporary_dive ?
 | 
				
			||||||
	struct dive *dive = alloc_dive();
 | 
						struct dive *dive = alloc_dive();
 | 
				
			||||||
 | 
						fakeDiveId = dive->id;
 | 
				
			||||||
	dive->when = QDateTime::currentMSecsSinceEpoch() / 1000L + gettimezoneoffset();
 | 
						dive->when = QDateTime::currentMSecsSinceEpoch() / 1000L + gettimezoneoffset();
 | 
				
			||||||
	dive->dc.model = "manually added dive"; // don't translate! this is stored in the XML file
 | 
						dive->dc.model = "manually added dive"; // don't translate! this is stored in the XML file
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -386,6 +388,16 @@ void MainWindow::createFakeDiveForAddAndPlan()
 | 
				
			||||||
	ui.InfoWidget->updateDiveInfo(selected_dive);
 | 
						ui.InfoWidget->updateDiveInfo(selected_dive);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void MainWindow::removeFakeDiveForAddAndPlan()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						int idx;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!fakeDiveId ||
 | 
				
			||||||
 | 
						    (idx = get_idx_by_uniq_id(fakeDiveId)) == dive_table.nr)
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						delete_single_dive(idx);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void MainWindow::on_actionDivePlanner_triggered()
 | 
					void MainWindow::on_actionDivePlanner_triggered()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	if(!plannerStateClean())
 | 
						if(!plannerStateClean())
 | 
				
			||||||
| 
						 | 
					@ -409,7 +421,8 @@ void MainWindow::on_actionDivePlanner_triggered()
 | 
				
			||||||
	createFakeDiveForAddAndPlan();
 | 
						createFakeDiveForAddAndPlan();
 | 
				
			||||||
	DivePlannerPointsModel::instance()->createSimpleDive(true);
 | 
						DivePlannerPointsModel::instance()->createSimpleDive(true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// disable the dive list
 | 
						// reload and then disable the dive list
 | 
				
			||||||
 | 
						ui.ListWidget->reload(DiveTripModel::CURRENT);
 | 
				
			||||||
	ui.ListWidget->setEnabled(false);
 | 
						ui.ListWidget->setEnabled(false);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -151,6 +151,7 @@ slots:
 | 
				
			||||||
	void recreateDiveList();
 | 
						void recreateDiveList();
 | 
				
			||||||
	void showProfile();
 | 
						void showProfile();
 | 
				
			||||||
	void editCurrentDive();
 | 
						void editCurrentDive();
 | 
				
			||||||
 | 
						void removeFakeDiveForAddAndPlan();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
	Ui::MainWindow ui;
 | 
						Ui::MainWindow ui;
 | 
				
			||||||
| 
						 | 
					@ -175,6 +176,7 @@ private:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	bool plannerStateClean();
 | 
						bool plannerStateClean();
 | 
				
			||||||
	void createFakeDiveForAddAndPlan();
 | 
						void createFakeDiveForAddAndPlan();
 | 
				
			||||||
 | 
						int fakeDiveId;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif // MAINWINDOW_H
 | 
					#endif // MAINWINDOW_H
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue