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:
Dirk Hohndel 2013-11-12 14:21:50 +09:00
parent 94222fbe49
commit a683a217b9
3 changed files with 20 additions and 11 deletions

View file

@ -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();