Mobile: fix saving new dive

With the new setup we need to know which state we are coming from
when we are saving cylinder related info. When we are adding
a new dive we explicitly should save cylinder data to the first cylinder.

Signed-off-by: Joakim Bygdell <j.bygdell@gmail.com>
This commit is contained in:
Jocke 2018-07-29 15:42:56 +02:00 committed by Dirk Hohndel
parent bd8eec5c8e
commit 0fb086a4a5
3 changed files with 8 additions and 7 deletions

View file

@ -73,6 +73,7 @@ Item {
}
function saveData() {
var state = diveDetailsPage.state
diveDetailsPage.state = "view" // run the transition
// join cylinder info from separate string into a list.
if (usedCyl[0] != null) {
@ -114,7 +115,7 @@ Item {
detailsEdit.weightText, detailsEdit.notesText, startpressure,
endpressure, usedGas, usedCyl ,
detailsEdit.rating,
detailsEdit.visibility)
detailsEdit.visibility, state)
// trigger the profile to be redrawn
QMLProfile.diveId = dive_id

View file

@ -1004,7 +1004,7 @@ bool QMLManager::checkDepth(DiveObjectHelper *myDive, dive *d, QString depth)
// update the dive and return the notes field, stripped of the HTML junk
void QMLManager::commitChanges(QString diveId, QString date, QString location, QString gps, QString duration, QString depth,
QString airtemp, QString watertemp, QString suit, QString buddy, QString diveMaster, QString weight, QString notes,
QStringList startpressure, QStringList endpressure, QStringList gasmix, QStringList usedCylinder, int rating, int visibility)
QStringList startpressure, QStringList endpressure, QStringList gasmix, QStringList usedCylinder, int rating, int visibility, QString state)
{
struct dive *d = get_dive_by_uniq_id(diveId.toInt());
@ -1051,7 +1051,7 @@ void QMLManager::commitChanges(QString diveId, QString date, QString location, Q
if (myDive->startPressure() != startpressure || myDive->endPressure() != endpressure) {
diveChanged = true;
for ( int i = 0, j = 0 ; j < startpressure.length() && j < endpressure.length() ; i++ ) {
if (!is_cylinder_used(d, i))
if (state != "add" && !is_cylinder_used(d, i))
continue;
d->cylinder[i].start.mbar = parsePressureToMbar(startpressure[j]);
@ -1065,7 +1065,7 @@ void QMLManager::commitChanges(QString diveId, QString date, QString location, Q
// gasmix for first cylinder
if (myDive->firstGas() != gasmix) {
for ( int i = 0, j = 0 ; j < gasmix.length() ; i++ ) {
if (!is_cylinder_used(d, i))
if (state != "add" && !is_cylinder_used(d, i))
continue;
int o2 = parseGasMixO2(gasmix[j]);
@ -1086,8 +1086,8 @@ void QMLManager::commitChanges(QString diveId, QString date, QString location, Q
diveChanged = true;
unsigned long i;
int size = 0, wp = 0, j = 0, k = 0;
for (j = 0; k < usedCylinder.length() ; j++) {
if (!is_cylinder_used(d, j))
for (j = 0; k < usedCylinder.length() && j < MAX_CYLINDERS; j++) {
if (state != "add" && !is_cylinder_used(d, j))
continue;
for (i = 0; i < MAX_TANK_INFO && tank_info[i].name != NULL; i++) {

View file

@ -158,7 +158,7 @@ public slots:
QString duration, QString depth, QString airtemp,
QString watertemp, QString suit, QString buddy,
QString diveMaster, QString weight, QString notes, QStringList startpressure,
QStringList endpressure, QStringList gasmix, QStringList usedCylinder, int rating, int visibility);
QStringList endpressure, QStringList gasmix, QStringList usedCylinder, int rating, int visibility, QString state);
void changesNeedSaving();
void openNoCloudRepo();
void saveChangesLocal();