Hook up adding a dive

This gets things mostly right.

It creates a dive and uses the planner widget to create samples which are
copied into the dive. It fills in some reasonable defaults (DC model,
timestamp), but doesn't allow editing the timestamp (or the temperatures
and air pressure).

On accept the planner gets reset and the dive appears correctly in the
dive list.

Cancel still needs to be handled.

And I bet there are many subtle bugs lurking here and there. But it's a
start.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2013-09-18 23:33:39 -05:00
parent 5a96389cd3
commit 46b125782e
6 changed files with 53 additions and 10 deletions

13
dive.c
View file

@ -161,6 +161,19 @@ struct dive *alloc_dive(void)
return dive;
}
void copy_samples(struct dive* s, struct dive* d)
{
/* instead of carefully copying them one by one and calling add_sample
* over and over again, let's just copy the whole blob */
if (!s || !d)
return;
int nr = s->dc.samples;
d->dc.samples = nr;
d->dc.sample = malloc(nr * sizeof(struct sample));
if (d->dc.sample)
memcpy(d->dc.sample, s->dc.sample, nr * sizeof(struct sample));
}
struct sample *prepare_sample(struct divecomputer *dc)
{
if (dc) {

1
dive.h
View file

@ -622,6 +622,7 @@ extern unsigned int dc_airtemp(struct divecomputer *dc);
extern struct dive *merge_dives(struct dive *a, struct dive *b, int offset, gboolean prefer_downloaded);
extern struct dive *try_to_merge(struct dive *a, struct dive *b, gboolean prefer_downloaded);
extern void renumber_dives(int nr);
extern void copy_samples(struct dive *s, struct dive *d);
extern void add_gas_switch_event(struct dive *dive, struct divecomputer *dc, int time, int idx);
extern void add_event(struct divecomputer *dc, int time, int type, int flags, int value, const char *name);

View file

@ -1113,7 +1113,7 @@ struct diveplan DivePlannerPointsModel::getDiveplan()
void DivePlannerPointsModel::cancelPlan()
{
if(rowCount()){
if(mode == PLAN && rowCount()){
if (QMessageBox::warning(mainWindow(), tr("Save the Plan?"),
tr("You have a working plan, \n are you sure that you wanna cancel it?"),
QMessageBox::Ok | QMessageBox::Cancel) != QMessageBox::Ok){
@ -1150,7 +1150,8 @@ void DivePlannerPointsModel::createTemporaryPlan()
tempDive = NULL;
char *errorString = NULL;
plan(&diveplan, &cache, &tempDive, isPlanner(), &errorString);
mainWindow()->information()->updateDiveInfo(get_divenr(tempDive));
if (mode == ADD)
copy_samples(tempDive, current_dive);
#if DEBUG_PLAN
dump_plan(&diveplan);
#endif

View file

@ -14,6 +14,7 @@
#include "modeldelegates.h"
#include "globe.h"
#include "completionmodels.h"
#include "diveplanner.h"
#include <QLabel>
#include <QCompleter>
@ -90,9 +91,15 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
ui->suit->setCompleter(completers.suit);
}
void MainTab::addDiveStarted()
{
enableEdition();
editMode = ADD;
}
void MainTab::enableEdition()
{
if (!selected_dive)
if (selected_dive < 0 || editMode != NONE)
return;
mainWindow()->dive_list()->setEnabled(false);
@ -383,6 +390,13 @@ void MainTab::acceptChanges()
mainWindow()->globe()->centerOn(current_dive);
}
}
if (editMode == ADD) {
// clean up the dive data (get duration, depth information from samples)
fixup_dive(current_dive);
DivePlannerPointsModel::instance()->cancelPlan();
mainWindow()->showProfile();
mainWindow()->refreshDisplay();
}
editMode = NONE;
QPalette p;
@ -500,7 +514,7 @@ void MainTab::on_location_textChanged(const QString& text)
// we are editing a trip
dive_trip_t *currentTrip = *mainWindow()->dive_list()->selectedTrips.begin();
EDIT_TEXT(currentTrip->location, text);
} else if (editMode == DIVE){
} else if (editMode == DIVE || editMode == ADD){
struct dive* dive;
int i = 0;
for_each_dive(i, dive){
@ -535,7 +549,7 @@ void MainTab::on_notes_textChanged()
// we are editing a trip
dive_trip_t *currentTrip = *mainWindow()->dive_list()->selectedTrips.begin();
EDIT_TEXT(currentTrip->notes, ui->notes->toPlainText());
} else if (editMode == DIVE) {
} else if (editMode == DIVE || editMode == ADD) {
EDIT_SELECTED_DIVES( EDIT_TEXT(mydive->notes, ui->notes->toPlainText()) );
}
markChangedWidget(ui->notes);

View file

@ -68,13 +68,14 @@ public slots:
void on_visibility_valueChanged(int value);
void editCylinderWidget(const QModelIndex& index);
void editWeigthWidget(const QModelIndex& index);
void addDiveStarted();
private:
Ui::MainTab *ui;
WeightModel *weightModel;
CylindersModel *cylindersModel;
QMap<dive*, NotesBackup> notesBackup;
enum { NONE, DIVE, TRIP } editMode;
enum { NONE, DIVE, TRIP, ADD } editMode;
Completers completers;
void enableEdition();
};

View file

@ -36,6 +36,8 @@
#include "about.h"
#include "printdialog.h"
#include "glib/gi18n.h"
static MainWindow* instance = 0;
MainWindow* mainWindow()
@ -255,14 +257,25 @@ void MainWindow::on_actionEditDeviceNames_triggered()
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);
}
disableDcShortcuts();
DivePlannerPointsModel::instance()->setPlanMode(false);
// 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;
dive->dc.model = _("manually added dive");
record_dive(dive);
select_dive(get_divenr(dive));
ui->InfoWidget->updateDiveInfo(selected_dive);
ui->stackedWidget->setCurrentIndex(1);
ui->infoPane->setCurrentIndex(0);
ui->InfoWidget->clearStats();
ui->InfoWidget->clearInfo();
ui->InfoWidget->clearEquipment();
ui->InfoWidget->updateDiveInfo(-1);
refreshDisplay();
ui->InfoWidget->addDiveStarted();
}
void MainWindow::on_actionRenumber_triggered()