mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-31 20:43:24 +00:00
First steps to make add dive work with the correct infrastructure
This just makes sure that we do the right thing with the staging drive, that we don't mess up the selection, the we are smart about using our helper functions, etc. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
94222fbe49
commit
a683a217b9
3 changed files with 20 additions and 11 deletions
|
@ -1251,8 +1251,9 @@ void DivePlannerPointsModel::cancelPlan()
|
|||
}
|
||||
clear();
|
||||
emit planCanceled();
|
||||
if (mode != ADD)
|
||||
free(stagingDive);
|
||||
setPlanMode(NOTHING);
|
||||
free(stagingDive);
|
||||
stagingDive = NULL;
|
||||
CylindersModel::instance()->setDive(current_dive);
|
||||
CylindersModel::instance()->update();
|
||||
|
@ -1265,9 +1266,13 @@ DivePlannerPointsModel::Mode DivePlannerPointsModel::currentMode() const
|
|||
|
||||
void DivePlannerPointsModel::clear()
|
||||
{
|
||||
if (!stagingDive)
|
||||
stagingDive = alloc_dive();
|
||||
memset(stagingDive->cylinder, 0, MAX_CYLINDERS * sizeof(cylinder_t));
|
||||
if (mode == ADD) {
|
||||
stagingDive = current_dive;
|
||||
} else {
|
||||
if (!stagingDive)
|
||||
stagingDive = alloc_dive();
|
||||
memset(stagingDive->cylinder, 0, MAX_CYLINDERS * sizeof(cylinder_t));
|
||||
}
|
||||
CylindersModel::instance()->setDive(stagingDive);
|
||||
beginRemoveRows(QModelIndex(), 0, rowCount()-1);
|
||||
divepoints.clear();
|
||||
|
|
|
@ -497,9 +497,15 @@ void MainTab::acceptChanges()
|
|||
fixup_dive(current_dive);
|
||||
if (dive_table.nr == 1)
|
||||
current_dive->number = 1;
|
||||
else if (current_dive == get_dive(dive_table.nr - 1) && get_dive(dive_table.nr - 2)->number)
|
||||
else if (selected_dive == dive_table.nr - 1 && get_dive(dive_table.nr - 2)->number)
|
||||
current_dive->number = get_dive(dive_table.nr - 2)->number + 1;
|
||||
DivePlannerPointsModel::instance()->cancelPlan();
|
||||
// now make sure the selection logic is in a sane state
|
||||
// it's ok to hold on to the dive pointer for this short stretch of code
|
||||
// unselectDives() doesn't mess with the dive_table at all
|
||||
struct dive *addedDive = current_dive;
|
||||
mainWindow()->dive_list()->unselectDives();
|
||||
mainWindow()->dive_list()->selectDive(addedDive, true, true);
|
||||
mainWindow()->showProfile();
|
||||
mainWindow()->refreshDisplay();
|
||||
mark_divelist_changed(TRUE);
|
||||
|
@ -548,8 +554,8 @@ void MainTab::rejectChanges()
|
|||
} else {
|
||||
if (editMode == ADD) {
|
||||
// clean up
|
||||
delete_single_dive(selected_dive);
|
||||
DivePlannerPointsModel::instance()->cancelPlan();
|
||||
delete_single_dive(selected_dive);
|
||||
} else if (editMode == MANUALLY_ADDED_DIVE ) {
|
||||
DivePlannerPointsModel::instance()->undoEdition(); // that's BOGUS... just copy the original dive back and be done with it...
|
||||
}
|
||||
|
|
|
@ -283,11 +283,7 @@ void MainWindow::on_actionAddDive_triggered()
|
|||
}
|
||||
|
||||
// clear the selection
|
||||
for (int i = 0; i < dive_table.nr; i++) {
|
||||
struct dive *d = get_dive(i);
|
||||
if (d && d->selected)
|
||||
deselect_dive(i);
|
||||
}
|
||||
dive_list()->unselectDives();
|
||||
disableDcShortcuts();
|
||||
DivePlannerPointsModel::instance()->clear();
|
||||
DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::ADD);
|
||||
|
@ -296,6 +292,8 @@ void MainWindow::on_actionAddDive_triggered()
|
|||
dive->when = QDateTime::currentMSecsSinceEpoch() / 1000L + gettimezoneoffset();
|
||||
dive->dc.model = "manually added dive"; // don't translate! this is stored in the XML file
|
||||
record_dive(dive);
|
||||
// this isn't in the UI yet, so let's call the C helper function - we'll fix this up when
|
||||
// accepting the dive
|
||||
select_dive(get_divenr(dive));
|
||||
ui.InfoWidget->updateDiveInfo(selected_dive);
|
||||
ui.stackedWidget->setCurrentIndex(PLANNERPROFILE); // Planner.
|
||||
|
|
Loading…
Add table
Reference in a new issue