UI restructure: use displayed_dive for add dive and plan dive

This gets rid of the stagingDive and stops the constant adding and
removing of dives from the divelist (that was an INSANE design,
seriously).

When adding or planning a dive all work is now done in the dedicated
displayed_dive.

Add dive mostly works - when the user clicks save the dive is added to the
dive list and selected.

Plan dive is mostly untested. It passed trivial "start planner, save"
testing so it's not entirely broken, but I'm sure there's more work to be
done there.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2014-07-03 14:45:01 -07:00
parent d8c3113584
commit 611bae3441
6 changed files with 113 additions and 137 deletions

View file

@ -257,14 +257,14 @@ static void create_dive_from_plan(struct diveplan *diveplan)
printf("in create_dive_from_plan\n"); printf("in create_dive_from_plan\n");
dump_plan(diveplan); dump_plan(diveplan);
#endif #endif
// clear out the dive, fill in the basics and get started // reset the cylinders and clear out the samples of the displayed dive so we can restart
clear_dive(&displayed_dive);
displayed_dive.when = diveplan->when;
displayed_dive.dc.surface_pressure.mbar = diveplan->surface_pressure;
dc = &displayed_dive.dc;
dc->model = "planned dive"; /* do not translate here ! */
dp = diveplan->dp;
reset_cylinders(&displayed_dive); reset_cylinders(&displayed_dive);
dc = &displayed_dive.dc;
free(dc->sample);
dc->sample = NULL;
dc->samples = 0;
dc->alloc_samples = 0;
dp = diveplan->dp;
cyl = &displayed_dive.cylinder[0]; cyl = &displayed_dive.cylinder[0];
oldgasmix = cyl->gasmix; oldgasmix = cyl->gasmix;
sample = prepare_sample(dc); sample = prepare_sample(dc);

View file

@ -66,9 +66,13 @@ void DivePlannerPointsModel::removeSelectedPoints(const QVector<int> &rows)
void DivePlannerPointsModel::createSimpleDive() void DivePlannerPointsModel::createSimpleDive()
{ {
struct gasmix gas = { 0 }; struct gasmix gas = { 0 };
// set the start time of the plan
diveplan.when = displayed_dive.when;
if (isPlanner()) if (isPlanner())
// let's use the gas from the first cylinder // let's use the gas from the first cylinder
gas = stagingDive->cylinder[0].gasmix; gas = displayed_dive.cylinder[0].gasmix;
// If we're in drop_stone_mode, don't add a first point. // If we're in drop_stone_mode, don't add a first point.
// It will be added implicit. // It will be added implicit.
@ -110,15 +114,6 @@ void DivePlannerPointsModel::loadFromDive(dive *d)
// but this whole section needs to be rewritten, anyway // but this whole section needs to be rewritten, anyway
copy_samples(&d->dc, &backupDive.dc); copy_samples(&d->dc, &backupDive.dc);
copy_events(&d->dc, &backupDive.dc); copy_events(&d->dc, &backupDive.dc);
copy_cylinders(d, stagingDive, false); // this way the correct cylinder data is shown
// FIXME -- need to get rid of stagingDIve
// the following now uses displayed_dive !!!!
CylindersModel::instance()->updateDive(); CylindersModel::instance()->updateDive();
int lasttime = 0; int lasttime = 0;
@ -139,57 +134,40 @@ void DivePlannerPointsModel::restoreBackupDive()
memcpy(current_dive, &backupDive, sizeof(struct dive)); memcpy(current_dive, &backupDive, sizeof(struct dive));
} }
void DivePlannerPointsModel::copyCylinders(dive *d)
{
copy_cylinders(stagingDive, d, false);
}
// copy the tanks from the current dive, or the default cylinder // copy the tanks from the current dive, or the default cylinder
// or an unknown cylinder // or an unknown cylinder
// setup the cylinder widget accordingly // setup the cylinder widget accordingly
void DivePlannerPointsModel::setupCylinders() void DivePlannerPointsModel::setupCylinders()
{ {
if (!stagingDive) if (mode == PLAN && current_dive) {
return;
if (stagingDive != current_dive) {
// we are planning a dive
if (current_dive) {
// take the used cylinders from the selected dive as starting point // take the used cylinders from the selected dive as starting point
CylindersModel::instance()->copyFromDive(current_dive); CylindersModel::instance()->copyFromDive(current_dive);
copy_cylinders(current_dive, stagingDive, true); copy_cylinders(current_dive, &displayed_dive, true);
reset_cylinders(stagingDive); reset_cylinders(&displayed_dive);
return; return;
} else { }
if (!same_string(prefs.default_cylinder, "")) { if (!same_string(prefs.default_cylinder, "")) {
fill_default_cylinder(&stagingDive->cylinder[0]); fill_default_cylinder(&displayed_dive.cylinder[0]);
} else { } else {
// roughly an AL80 // roughly an AL80
stagingDive->cylinder[0].type.description = strdup(tr("unknown").toUtf8().constData()); displayed_dive.cylinder[0].type.description = strdup(tr("unknown").toUtf8().constData());
stagingDive->cylinder[0].type.size.mliter = 11100; displayed_dive.cylinder[0].type.size.mliter = 11100;
stagingDive->cylinder[0].type.workingpressure.mbar = 207000; displayed_dive.cylinder[0].type.workingpressure.mbar = 207000;
} }
} reset_cylinders(&displayed_dive);
} CylindersModel::instance()->copyFromDive(&displayed_dive);
reset_cylinders(stagingDive);
CylindersModel::instance()->copyFromDive(stagingDive);
} }
QStringList &DivePlannerPointsModel::getGasList() QStringList &DivePlannerPointsModel::getGasList()
{ {
struct dive *activeDive = isPlanner() ? stagingDive : current_dive;
static QStringList list; static QStringList list;
list.clear(); list.clear();
if (!activeDive) {
list.push_back(tr("AIR"));
} else {
for (int i = 0; i < MAX_CYLINDERS; i++) { for (int i = 0; i < MAX_CYLINDERS; i++) {
cylinder_t *cyl = &activeDive->cylinder[i]; cylinder_t *cyl = &displayed_dive.cylinder[i];
if (cylinder_nodata(cyl)) if (cylinder_nodata(cyl))
break; break;
list.push_back(gasToStr(cyl->gasmix)); list.push_back(gasToStr(cyl->gasmix));
} }
}
return list; return list;
} }
@ -501,8 +479,6 @@ void PlannerSettingsWidget::setDecoPo2(double po2)
void DivePlannerPointsModel::setPlanMode(Mode m) void DivePlannerPointsModel::setPlanMode(Mode m)
{ {
mode = m; mode = m;
if (m == NOTHING)
stagingDive = NULL;
// the planner may reset our GF settings that are used to show deco // the planner may reset our GF settings that are used to show deco
// reset them to what's in the preferences // reset them to what's in the preferences
if (m != PLAN) if (m != PLAN)
@ -643,7 +619,7 @@ int DivePlannerPointsModel::rowCount(const QModelIndex &parent) const
return divepoints.count(); return divepoints.count();
} }
DivePlannerPointsModel::DivePlannerPointsModel(QObject *parent) : QAbstractTableModel(parent), mode(NOTHING), tempDive(NULL), stagingDive(NULL) DivePlannerPointsModel::DivePlannerPointsModel(QObject *parent) : QAbstractTableModel(parent), mode(NOTHING)
{ {
memset(&diveplan, 0, sizeof(diveplan)); memset(&diveplan, 0, sizeof(diveplan));
memset(&backupDive, 0, sizeof(backupDive)); memset(&backupDive, 0, sizeof(backupDive));
@ -767,7 +743,7 @@ bool DivePlannerPointsModel::addGas(struct gasmix mix)
sanitize_gasmix(&mix); sanitize_gasmix(&mix);
for (int i = 0; i < MAX_CYLINDERS; i++) { for (int i = 0; i < MAX_CYLINDERS; i++) {
cylinder_t *cyl = &stagingDive->cylinder[i]; cylinder_t *cyl = &displayed_dive.cylinder[i];
if (cylinder_nodata(cyl)) { if (cylinder_nodata(cyl)) {
fill_default_cylinder(cyl); fill_default_cylinder(cyl);
cyl->gasmix = mix; cyl->gasmix = mix;
@ -827,7 +803,7 @@ int DivePlannerPointsModel::addStop(int milimeters, int seconds, gasmix *gas_in,
milimeters = M_OR_FT(5, 15); // 5m / 15ft milimeters = M_OR_FT(5, 15); // 5m / 15ft
seconds = 600; // 10 min seconds = 600; // 10 min
//Default to the first defined gas, if we got one. //Default to the first defined gas, if we got one.
cylinder_t *cyl = &stagingDive->cylinder[0]; cylinder_t *cyl = &displayed_dive.cylinder[0];
if (cyl) if (cyl)
gas = cyl->gasmix; gas = cyl->gasmix;
} }
@ -927,12 +903,16 @@ void DivePlannerPointsModel::cancelPlan()
return; return;
} }
} }
if (mode != ADD) // for ADD stagingDive points at current_dive
free(stagingDive);
stagingDive = NULL; // always reset the stagingDive to NULL
setPlanMode(NOTHING); setPlanMode(NOTHING);
diveplan.dp = NULL; diveplan.dp = NULL;
// somewhere, somehow we need to make sure that the current_dive is displayed again
emit planCanceled(); emit planCanceled();
} }
@ -953,7 +933,7 @@ QVector<QPair<int, int> > DivePlannerPointsModel::collectGases(struct dive *d)
} }
void DivePlannerPointsModel::rememberTanks() void DivePlannerPointsModel::rememberTanks()
{ {
oldGases = collectGases(stagingDive); oldGases = collectGases(&displayed_dive);
} }
bool DivePlannerPointsModel::tankInUse(struct gasmix gasmix) bool DivePlannerPointsModel::tankInUse(struct gasmix gasmix)
@ -976,7 +956,7 @@ void DivePlannerPointsModel::tanksUpdated()
// "did a gas change on us". So we look through the diveplan to // "did a gas change on us". So we look through the diveplan to
// see if there is a gas that is now missing and if there is, we // see if there is a gas that is now missing and if there is, we
// replace it with the matching new gas. // replace it with the matching new gas.
QVector<QPair<int, int> > gases = collectGases(stagingDive); QVector<QPair<int, int> > gases = collectGases(&displayed_dive);
if (gases.count() == oldGases.count()) { if (gases.count() == oldGases.count()) {
// either nothing relevant changed, or exactly ONE gasmix changed // either nothing relevant changed, or exactly ONE gasmix changed
for (int i = 0; i < gases.count(); i++) { for (int i = 0; i < gases.count(); i++) {
@ -1005,12 +985,6 @@ void DivePlannerPointsModel::tanksUpdated()
void DivePlannerPointsModel::clear() void DivePlannerPointsModel::clear()
{ {
Q_ASSERT(stagingDive == 0);
if (mode == ADD) {
stagingDive = current_dive;
} else {
stagingDive = alloc_dive();
}
bool oldRecalc = setRecalc(false); bool oldRecalc = setRecalc(false);
@ -1033,13 +1007,7 @@ void DivePlannerPointsModel::clear()
void DivePlannerPointsModel::createTemporaryPlan() void DivePlannerPointsModel::createTemporaryPlan()
{ {
// This needs to be done in the following steps:
// Get the user-input and calculate the dive info // Get the user-input and calculate the dive info
// Not sure if this is the place to create the diveplan...
// We just start with a surface node at time = 0
if (!stagingDive)
return;
//TODO: this thingy looks like it could be a good C-based function
diveplan.dp = NULL; diveplan.dp = NULL;
int lastIndex = -1; int lastIndex = -1;
for (int i = 0; i < rowCount(); i++) { for (int i = 0; i < rowCount(); i++) {
@ -1054,11 +1022,12 @@ void DivePlannerPointsModel::createTemporaryPlan()
if (p.entered) if (p.entered)
plan_add_segment(&diveplan, deltaT, p.depth, p.gasmix, p.po2, true); plan_add_segment(&diveplan, deltaT, p.depth, p.gasmix, p.po2, true);
} }
// what does the cache do???
char *cache = NULL; char *cache = NULL;
tempDive = NULL;
struct divedatapoint *dp = NULL; struct divedatapoint *dp = NULL;
for (int i = 0; i < MAX_CYLINDERS; i++) { for (int i = 0; i < MAX_CYLINDERS; i++) {
cylinder_t *cyl = &stagingDive->cylinder[i]; cylinder_t *cyl = &displayed_dive.cylinder[i];
if (cyl->depth.mm) { if (cyl->depth.mm) {
dp = create_dp(0, cyl->depth.mm, cyl->gasmix, 0); dp = create_dp(0, cyl->depth.mm, cyl->gasmix, 0);
if (diveplan.dp) { if (diveplan.dp) {
@ -1074,19 +1043,12 @@ void DivePlannerPointsModel::createTemporaryPlan()
dump_plan(&diveplan); dump_plan(&diveplan);
#endif #endif
if (plannerModel->recalcQ() && !diveplan_empty(&diveplan)) { if (plannerModel->recalcQ() && !diveplan_empty(&diveplan)) {
plan(&diveplan, &cache, &tempDive, stagingDive, isPlanner(), false); plan(&diveplan, &cache, isPlanner(), false);
MainWindow::instance()->setPlanNotes(tempDive->notes);
if (mode == ADD || mode == PLAN) {
// copy the samples and events of the first dive computer, but don't overwrite the cylinders
// FIXME this needs to be rewritten
copy_samples(&tempDive->dc, &current_dive->dc);
copy_events(&tempDive->dc, &current_dive->dc);
copy_cylinders(tempDive, current_dive, false);
}
} }
// throw away the cache // throw away the cache
free(cache); free(cache);
#if DEBUG_PLAN #if DEBUG_PLAN
save_dive(stderr, &displayed_dive);
dump_plan(&diveplan); dump_plan(&diveplan);
#endif #endif
} }
@ -1095,8 +1057,6 @@ void DivePlannerPointsModel::deleteTemporaryPlan()
{ {
deleteTemporaryPlan(diveplan.dp); deleteTemporaryPlan(diveplan.dp);
diveplan.dp = NULL; diveplan.dp = NULL;
delete_single_dive(get_divenr(tempDive));
tempDive = NULL;
} }
void DivePlannerPointsModel::deleteTemporaryPlan(struct divedatapoint *dp) void DivePlannerPointsModel::deleteTemporaryPlan(struct divedatapoint *dp)
@ -1110,27 +1070,21 @@ void DivePlannerPointsModel::deleteTemporaryPlan(struct divedatapoint *dp)
void DivePlannerPointsModel::createPlan() void DivePlannerPointsModel::createPlan()
{ {
// Ok, so, here the diveplan creates a dive, // Ok, so, here the diveplan creates a dive
// puts it on the dive list, and we need to remember
// to not delete it later. mumble. ;p
char *cache = NULL; char *cache = NULL;
tempDive = NULL;
bool oldRecalc = plannerModel->setRecalc(false); bool oldRecalc = plannerModel->setRecalc(false);
removeDeco(); removeDeco();
createTemporaryPlan(); createTemporaryPlan();
plannerModel->setRecalc(oldRecalc); plannerModel->setRecalc(oldRecalc);
//TODO: C-based function here? //TODO: C-based function here?
plan(&diveplan, &cache, &tempDive, stagingDive, isPlanner(), true); plan(&diveplan, &cache, isPlanner(), true);
record_dive(tempDive); record_dive(clone_dive(&displayed_dive));
mark_divelist_changed(true); mark_divelist_changed(true);
// Remove and clean the diveplan, so we don't delete // Remove and clean the diveplan, so we don't delete
// the dive by mistake. // the dive by mistake.
diveplan.dp = NULL; diveplan.dp = NULL;
setPlanMode(NOTHING); setPlanMode(NOTHING);
free(stagingDive);
stagingDive = NULL;
planCreated(); planCreated();
} }

View file

@ -46,7 +46,6 @@ public:
void tanksUpdated(); void tanksUpdated();
void rememberTanks(); void rememberTanks();
bool tankInUse(struct gasmix gasmix); bool tankInUse(struct gasmix gasmix);
void copyCylinders(struct dive *d);
void setupCylinders(); void setupCylinders();
/** /**
* @return the row number. * @return the row number.
@ -100,11 +99,9 @@ private:
Mode mode; Mode mode;
bool recalc; bool recalc;
QVector<divedatapoint> divepoints; QVector<divedatapoint> divepoints;
struct dive *tempDive;
struct dive backupDive; struct dive backupDive;
void deleteTemporaryPlan(struct divedatapoint *dp); void deleteTemporaryPlan(struct divedatapoint *dp);
QVector<sample> backupSamples; // For editing added dives. QVector<sample> backupSamples; // For editing added dives.
struct dive *stagingDive;
QVector<QPair<int, int> > oldGases; QVector<QPair<int, int> > oldGases;
bool drop_stone_mode; bool drop_stone_mode;
QDateTime startTime; QDateTime startTime;

View file

@ -249,7 +249,7 @@ void MainTab::updateTextLabels(bool showUnits)
void MainTab::enableEdition(EditMode newEditMode) void MainTab::enableEdition(EditMode newEditMode)
{ {
if (current_dive == NULL || editMode != NONE) if (((newEditMode == DIVE || newEditMode == NONE) && current_dive == NULL) || editMode != NONE)
return; return;
modified = false; modified = false;
if ((newEditMode == DIVE || newEditMode == NONE) && if ((newEditMode == DIVE || newEditMode == NONE) &&
@ -257,12 +257,22 @@ void MainTab::enableEdition(EditMode newEditMode)
strcmp(current_dive->dc.model, "manually added dive") == 0) { strcmp(current_dive->dc.model, "manually added dive") == 0) {
// editCurrentDive will call enableEdition with newEditMode == MANUALLY_ADDED_DIVE // editCurrentDive will call enableEdition with newEditMode == MANUALLY_ADDED_DIVE
// so exit this function here after editCurrentDive() returns // so exit this function here after editCurrentDive() returns
// FIXME : can we get rid of this recursive crap?
MainWindow::instance()->editCurrentDive(); MainWindow::instance()->editCurrentDive();
return; return;
} }
MainWindow::instance()->dive_list()->setEnabled(false); MainWindow::instance()->dive_list()->setEnabled(false);
if (amount_selected == 1)
// only setup the globe for editing if we are editing exactly one existing dive
if (amount_selected == 1 && newEditMode != ADD)
MainWindow::instance()->globe()->prepareForGetDiveCoordinates(); MainWindow::instance()->globe()->prepareForGetDiveCoordinates();
if (MainWindow::instance() && MainWindow::instance()->dive_list()->selectedTrips().count() == 1) { if (MainWindow::instance() && MainWindow::instance()->dive_list()->selectedTrips().count() == 1) {
// we are editing trip location and notes // we are editing trip location and notes
displayMessage(tr("This trip is being edited.")); displayMessage(tr("This trip is being edited."));
@ -276,8 +286,6 @@ void MainTab::enableEdition(EditMode newEditMode)
} else { } else {
displayMessage(tr("This dive is being edited.")); displayMessage(tr("This dive is being edited."));
} }
// editedDive already contains the current dive (we set this up in updateDiveInfo),
// so all we need to do is update the editMode if necessary
editMode = newEditMode != NONE ? newEditMode : DIVE; editMode = newEditMode != NONE ? newEditMode : DIVE;
} }
} }
@ -598,14 +606,24 @@ void MainTab::reload()
void MainTab::acceptChanges() void MainTab::acceptChanges()
{ {
int i; int i, addedId = -1;
struct dive *d; struct dive *d;
tabBar()->setTabIcon(0, QIcon()); // Notes tabBar()->setTabIcon(0, QIcon()); // Notes
tabBar()->setTabIcon(1, QIcon()); // Equipment tabBar()->setTabIcon(1, QIcon()); // Equipment
hideMessage(); hideMessage();
ui.equipmentTab->setEnabled(true); ui.equipmentTab->setEnabled(true);
if (editMode == ADD) {
// we need to add the dive we just created to the dive list and select it.
// Easy, right?
struct dive *added_dive = clone_dive(&displayed_dive);
record_dive(added_dive);
addedId = added_dive->id;
// unselect everything as far as the UI is concerned - we'll fix that below
MainWindow::instance()->dive_list()->unselectDives();
selected_dive = get_divenr(added_dive);
amount_selected = 1;
} else if (MainWindow::instance() && MainWindow::instance()->dive_list()->selectedTrips().count() == 1) {
/* now figure out if things have changed */ /* now figure out if things have changed */
if (MainWindow::instance() && MainWindow::instance()->dive_list()->selectedTrips().count() == 1) {
if (!same_string(displayed_dive.notes, current_dive->divetrip->notes)) { if (!same_string(displayed_dive.notes, current_dive->divetrip->notes)) {
current_dive->divetrip->notes = strdup(displayed_dive.notes); current_dive->divetrip->notes = strdup(displayed_dive.notes);
mark_divelist_changed(true); mark_divelist_changed(true);
@ -670,9 +688,13 @@ void MainTab::acceptChanges()
} }
if (tagsChanged(&displayed_dive, cd)) if (tagsChanged(&displayed_dive, cd))
saveTags(); saveTags();
#if 0 // with the new architecture this shouldn't be needed anymore
if (editMode == MANUALLY_ADDED_DIVE) { if (editMode == MANUALLY_ADDED_DIVE) {
DivePlannerPointsModel::instance()->copyCylinders(cd); DivePlannerPointsModel::instance()->copyCylinders(cd);
} else if (editMode != ADD && cylindersModel->changed) { } else
#endif
if (editMode != ADD && cylindersModel->changed) {
mark_divelist_changed(true); mark_divelist_changed(true);
MODIFY_SELECTED_DIVES( MODIFY_SELECTED_DIVES(
for (int i = 0; i < MAX_CYLINDERS; i++) { for (int i = 0; i < MAX_CYLINDERS; i++) {
@ -733,6 +755,12 @@ void MainTab::acceptChanges()
int scrolledBy = MainWindow::instance()->dive_list()->verticalScrollBar()->sliderPosition(); int scrolledBy = MainWindow::instance()->dive_list()->verticalScrollBar()->sliderPosition();
resetPallete(); resetPallete();
if (editMode == ADD || editMode == MANUALLY_ADDED_DIVE) { if (editMode == ADD || editMode == MANUALLY_ADDED_DIVE) {
// now let's resort the dive list and make sure the newly added dive is still selected
sort_table(&dive_table);
MainWindow::instance()->dive_list()->unselectDives();
int newDiveNr = get_divenr(get_dive_by_uniq_id(addedId));
MainWindow::instance()->dive_list()->selectDive(newDiveNr, true);
#if 0
// it's tricky to keep the right dive selected; // it's tricky to keep the right dive selected;
// first remember which one is selected in the current sort order // first remember which one is selected in the current sort order
// and unselect all dives // and unselect all dives
@ -753,7 +781,7 @@ void MainTab::acceptChanges()
// selected - but that may not be the right one, so select the one // selected - but that may not be the right one, so select the one
// we remembered instead // we remembered instead
MainWindow::instance()->dive_list()->selectDive(rememberSelected, true); MainWindow::instance()->dive_list()->selectDive(rememberSelected, true);
#endif
editMode = NONE; editMode = NONE;
MainWindow::instance()->refreshDisplay(); MainWindow::instance()->refreshDisplay();
MainWindow::instance()->graphics()->replot(); MainWindow::instance()->graphics()->replot();

View file

@ -63,7 +63,6 @@ MainWindow::MainWindow() : QMainWindow(),
yearlyStatsModel(0), yearlyStatsModel(0),
state(VIEWALL), state(VIEWALL),
updateManager(0), updateManager(0),
fakeDiveId(0),
survey(0) survey(0)
{ {
Q_ASSERT_X(m_Instance == NULL, "MainWindow", "MainWindow recreated!"); Q_ASSERT_X(m_Instance == NULL, "MainWindow", "MainWindow recreated!");
@ -392,48 +391,38 @@ bool MainWindow::plannerStateClean()
return true; return true;
} }
// setup displayed_dive so we can start planning with it
void MainWindow::createFakeDiveForAddAndPlan() void MainWindow::createFakeDiveForAddAndPlan()
{ {
// now cheat - create one dive that we use to store the info tab data in clear_dive(&displayed_dive);
//TODO: C-function create_temporary_dive ? displayed_dive.when = QDateTime::currentMSecsSinceEpoch() / 1000L + gettimezoneoffset() + 3600;
struct dive *dive = alloc_dive(); displayed_dive.dc.model = "manually added dive"; // don't translate! this is stored in the XML file
fakeDiveId = dive->id; // now show the mostly empty main tab
dive->when = QDateTime::currentMSecsSinceEpoch() / 1000L + gettimezoneoffset(); ui.InfoWidget->updateDiveInfo();
dive->dc.model = "manually added dive"; // don't translate! this is stored in the XML file
dive->latitude.udeg = 0; #if 0 // don't want to do any of this, I think
dive->longitude.udeg = 0;
record_dive(dive);
// select this new dive (but remember the old selection // select this new dive (but remember the old selection
ui.ListWidget->rememberSelection(); ui.ListWidget->rememberSelection();
ui.ListWidget->unselectDives(); ui.ListWidget->unselectDives();
ui.ListWidget->reload(DiveTripModel::CURRENT); ui.ListWidget->reload(DiveTripModel::CURRENT);
ui.ListWidget->selectDives(QList<int>() << dive_table.nr - 1); ui.ListWidget->selectDives(QList<int>() << dive_table.nr - 1);
ui.InfoWidget->updateDiveInfo(); ui.InfoWidget->updateDiveInfo();
} showProfile();
#endif
void MainWindow::removeFakeDiveForAddAndPlan()
{
int idx;
if (!fakeDiveId ||
(idx = get_idx_by_uniq_id(fakeDiveId)) == dive_table.nr)
return;
delete_single_dive(idx);
} }
void MainWindow::planCanceled() void MainWindow::planCanceled()
{ {
removeFakeDiveForAddAndPlan();
showProfile(); showProfile();
#if 0 // shouldn't need this
ui.ListWidget->reload(DiveTripModel::CURRENT); ui.ListWidget->reload(DiveTripModel::CURRENT);
ui.ListWidget->restoreSelection(); ui.ListWidget->restoreSelection();
#endif
refreshDisplay(); refreshDisplay();
} }
void MainWindow::planCreated() void MainWindow::planCreated()
{ {
removeFakeDiveForAddAndPlan();
showProfile(); showProfile();
refreshDisplay(); refreshDisplay();
} }
@ -501,16 +490,26 @@ void MainWindow::on_actionAddDive_triggered()
ui.ListWidget->endSearch(); ui.ListWidget->endSearch();
DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::ADD); DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::ADD);
createFakeDiveForAddAndPlan(); clear_dive(&displayed_dive);
displayed_dive.when = QDateTime::currentMSecsSinceEpoch() / 1000L + gettimezoneoffset() + 3600;
displayed_dive.dc.model = "manually added dive"; // don't translate! this is stored in the XML file
// setup the dive cylinders
DivePlannerPointsModel::instance()->setupCylinders();
// now show the mostly empty main tab
ui.InfoWidget->updateDiveInfo();
// show main tab
ui.InfoWidget->setCurrentIndex(0); ui.InfoWidget->setCurrentIndex(0);
ui.InfoWidget->addDiveStarted(); ui.InfoWidget->addDiveStarted();
ui.infoPane->setCurrentIndex(MAINTAB); ui.infoPane->setCurrentIndex(MAINTAB);
ui.newProfile->setAddState(); ui.newProfile->setAddState();
DivePlannerPointsModel::instance()->clear(); DivePlannerPointsModel::instance()->clear();
DivePlannerPointsModel::instance()->createSimpleDive(); DivePlannerPointsModel::instance()->createSimpleDive();
ui.ListWidget->reload(DiveTripModel::CURRENT); ui.newProfile->plotDive();
} }
void MainWindow::on_actionRenumber_triggered() void MainWindow::on_actionRenumber_triggered()

View file

@ -156,7 +156,6 @@ slots:
void recreateDiveList(); void recreateDiveList();
void showProfile(); void showProfile();
void editCurrentDive(); void editCurrentDive();
void removeFakeDiveForAddAndPlan();
void planCanceled(); void planCanceled();
void planCreated(); void planCreated();
@ -185,7 +184,6 @@ private:
bool plannerStateClean(); bool plannerStateClean();
void createFakeDiveForAddAndPlan(); void createFakeDiveForAddAndPlan();
int fakeDiveId;
QDialog *survey; QDialog *survey;
}; };