QML UI: enable editing of weight

But only if there is only one weight system defined in the dive. Otherwise
display a read only text that explains that this cannot be edited.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2016-02-05 22:54:47 -08:00
parent ad7fb80d0a
commit a4ec520601
4 changed files with 26 additions and 5 deletions

View file

@ -70,7 +70,14 @@ MobileComponents.Page {
buddy = diveDetailsListView.currentItem.modelData.dive.buddy buddy = diveDetailsListView.currentItem.modelData.dive.buddy
divemaster = diveDetailsListView.currentItem.modelData.dive.divemaster divemaster = diveDetailsListView.currentItem.modelData.dive.divemaster
notes = diveDetailsListView.currentItem.modelData.dive.notes notes = diveDetailsListView.currentItem.modelData.dive.notes
weight = diveDetailsListView.currentItem.modelData.dive.sumWeight if (diveDetailsListView.currentItem.modelData.dive.singleWeight) {
// we have only one weight, go ahead, have fun and edit it
weight = diveDetailsListView.currentItem.modelData.dive.sumWeight
} else {
// careful when translating, this text is "magic" in DiveDetailsEdit.qml
weight = "cannot edit multiple weight systems"
}
diveDetailsPage.state = "edit" diveDetailsPage.state = "edit"
} }
} }

View file

@ -139,6 +139,7 @@ Item {
} }
TextField { TextField {
id: txtWeight id: txtWeight
readOnly: (text == "cannot edit multiple weight systems" ? true : false)
Layout.fillWidth: true Layout.fillWidth: true
} }
@ -167,7 +168,7 @@ Item {
// apply the changes to the dive_table // apply the changes to the dive_table
manager.commitChanges(dive_id, detailsEdit.dateText, detailsEdit.locationText, detailsEdit.gpsText, detailsEdit.durationText, manager.commitChanges(dive_id, detailsEdit.dateText, detailsEdit.locationText, detailsEdit.gpsText, detailsEdit.durationText,
detailsEdit.depthText, detailsEdit.airtempText, detailsEdit.watertempText, detailsEdit.suitText, detailsEdit.depthText, detailsEdit.airtempText, detailsEdit.watertempText, detailsEdit.suitText,
detailsEdit.buddyText, detailsEdit.divemasterText, detailsEdit.notesText) detailsEdit.buddyText, detailsEdit.divemasterText, detailsEdit.weightText, detailsEdit.notesText)
// apply the changes to the dive detail view - since the edit could have changed the order // apply the changes to the dive detail view - since the edit could have changed the order
// first make sure that we are looking at the correct dive - our model allows us to look // first make sure that we are looking at the correct dive - our model allows us to look
// up the index based on the unique dive_id // up the index based on the unique dive_id

View file

@ -329,7 +329,7 @@ void QMLManager::refreshDiveList()
// update the dive and return the notes field, stripped of the HTML junk // update the dive and return the notes field, stripped of the HTML junk
QString QMLManager::commitChanges(QString diveId, QString date, QString location, QString gps, QString duration, QString depth, QString 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 notes) QString airtemp, QString watertemp, QString suit, QString buddy, QString diveMaster, QString weight, QString notes)
{ {
#define DROP_EMPTY_PLACEHOLDER(_s) if ((_s) == QLatin1Literal("--")) (_s).clear() #define DROP_EMPTY_PLACEHOLDER(_s) if ((_s) == QLatin1Literal("--")) (_s).clear()
@ -341,6 +341,7 @@ QString QMLManager::commitChanges(QString diveId, QString date, QString location
DROP_EMPTY_PLACEHOLDER(suit); DROP_EMPTY_PLACEHOLDER(suit);
DROP_EMPTY_PLACEHOLDER(buddy); DROP_EMPTY_PLACEHOLDER(buddy);
DROP_EMPTY_PLACEHOLDER(diveMaster); DROP_EMPTY_PLACEHOLDER(diveMaster);
DROP_EMPTY_PLACEHOLDER(weight);
DROP_EMPTY_PLACEHOLDER(notes); DROP_EMPTY_PLACEHOLDER(notes);
#undef DROP_EMPTY_PLACEHOLDER #undef DROP_EMPTY_PLACEHOLDER
@ -470,6 +471,18 @@ QString QMLManager::commitChanges(QString diveId, QString date, QString location
prefs.units.temperature = units::FAHRENHEIT; prefs.units.temperature = units::FAHRENHEIT;
d->watertemp.mkelvin = parseTemperatureToMkelvin(watertemp); d->watertemp.mkelvin = parseTemperatureToMkelvin(watertemp);
} }
// not sure what we'd do if there was more than one weight system
// defined - for now just ignore that case
if (weightsystem_none((void *)&d->weightsystem[1])) {
if (get_weight_string(d->weightsystem[0].weight, true) != weight) {
diveChanged = true;
if (weight.contains(tr("kg")))
prefs.units.weight = units::KG;
else if (weight.contains(tr("lbs")))
prefs.units.weight = units::LBS;
d->weightsystem[0].weight.grams = parseWeightToGrams(weight);
}
}
if (!same_string(d->suit, qPrintable(suit))) { if (!same_string(d->suit, qPrintable(suit))) {
diveChanged = true; diveChanged = true;
free(d->suit); free(d->suit);

View file

@ -70,10 +70,10 @@ public slots:
void loadDivesWithValidCredentials(); void loadDivesWithValidCredentials();
void loadDiveProgress(int percent); void loadDiveProgress(int percent);
void provideAuth(QNetworkReply *reply, QAuthenticator *auth); void provideAuth(QNetworkReply *reply, QAuthenticator *auth);
QString commitChanges(QString diveId,QString date, QString location, QString commitChanges(QString diveId, QString date, QString location,
QString gps, QString duration, QString depth, QString gps, QString duration, QString depth,
QString airtemp, QString watertemp, QString suit, QString airtemp, QString watertemp, QString suit,
QString buddy, QString diveMaster, QString notes); QString buddy, QString diveMaster, QString weight, QString notes);
void saveChanges(); void saveChanges();
QString addDive(); QString addDive();