diff options
author | Joakim Bygdell <j.bygdell@gmail.com> | 2016-08-30 16:24:19 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2016-09-04 07:36:13 -0700 |
commit | 674d8331f5c15a8c3095afd1deca2b087fd82464 (patch) | |
tree | defca414c3ca03c51b8dd65840b1d5ba6dedf963 /mobile-widgets | |
parent | 7b3665827a3fdf6717be5419b41641d8e2d95c93 (diff) | |
download | subsurface-674d8331f5c15a8c3095afd1deca2b087fd82464.tar.gz |
QML UI: Enable cylinder edit
This adds the option to select a cylinder when adding or editing a dive.
Due to limited screen size we restrict the editing to the first cylinder only.
Signed-off-by: Joakim Bygdell <j.bygdell@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'mobile-widgets')
-rw-r--r-- | mobile-widgets/qml/DiveDetails.qml | 3 | ||||
-rw-r--r-- | mobile-widgets/qml/DiveDetailsEdit.qml | 24 | ||||
-rw-r--r-- | mobile-widgets/qmlmanager.cpp | 24 | ||||
-rw-r--r-- | mobile-widgets/qmlmanager.h | 10 |
4 files changed, 52 insertions, 9 deletions
diff --git a/mobile-widgets/qml/DiveDetails.qml b/mobile-widgets/qml/DiveDetails.qml index a66968ad1..b85b59391 100644 --- a/mobile-widgets/qml/DiveDetails.qml +++ b/mobile-widgets/qml/DiveDetails.qml @@ -29,6 +29,8 @@ Kirigami.Page { property alias weight: detailsEdit.weightText property alias startpressure: detailsEdit.startpressureText property alias endpressure: detailsEdit.endpressureText + property alias cylinderIndex: detailsEdit.cylinderIndex + property alias cylinderModel: detailsEdit.cylinderModel property alias gasmix: detailsEdit.gasmixText property alias gpsCheckbox: detailsEdit.gpsCheckbox property int updateCurrentIdx: manager.updateSelectedDive @@ -168,6 +170,7 @@ Kirigami.Page { startpressure = diveDetailsListView.currentItem.modelData.dive.startPressure endpressure = diveDetailsListView.currentItem.modelData.dive.endPressure gasmix = diveDetailsListView.currentItem.modelData.dive.firstGas + cylinderIndex = diveDetailsListView.currentItem.modelData.dive.cylinderList.indexOf(diveDetailsListView.currentItem.modelData.dive.getCylinder) } else { // careful when translating, this text is "magic" in DiveDetailsEdit.qml startpressure = "cannot edit multiple cylinders" diff --git a/mobile-widgets/qml/DiveDetailsEdit.qml b/mobile-widgets/qml/DiveDetailsEdit.qml index ad62997df..b3907c616 100644 --- a/mobile-widgets/qml/DiveDetailsEdit.qml +++ b/mobile-widgets/qml/DiveDetailsEdit.qml @@ -18,6 +18,7 @@ Item { property alias suitIndex: suitBox.currentIndex property alias buddyIndex: buddyBox.currentIndex property alias divemasterIndex: divemasterBox.currentIndex + property alias cylinderIndex: cylinderBox.currentIndex property alias notesText: txtNotes.text property alias durationText: txtDuration.text property alias depthText: txtDepth.text @@ -29,13 +30,14 @@ Item { property alias suitModel: suitBox.model property alias divemasterModel: divemasterBox.model property alias buddyModel: buddyBox.model + property alias cylinderModel: cylinderBox.model function saveData() { // apply the changes to the dive_table manager.commitChanges(dive_id, detailsEdit.dateText, detailsEdit.locationText, detailsEdit.gpsText, detailsEdit.durationText, - detailsEdit.depthText, detailsEdit.airtempText, detailsEdit.watertempText, suitBox.editText, - buddyBox.editText, divemasterBox.editText, detailsEdit.weightText, detailsEdit.notesText, - detailsEdit.startpressureText, detailsEdit.endpressureText, detailsEdit.gasmixText) + detailsEdit.depthText, detailsEdit.airtempText, detailsEdit.watertempText, suitBox.editText, buddyBox.editText, + divemasterBox.editText, detailsEdit.weightText, detailsEdit.notesText, detailsEdit.startpressureText, + detailsEdit.endpressureText, detailsEdit.gasmixText, cylinderBox.editText) // trigger the profile to be redrawn QMLProfile.diveId = dive_id @@ -53,6 +55,7 @@ Item { diveDetailsListView.currentItem.modelData.suit = suitBox.currentText diveDetailsListView.currentItem.modelData.buddy = buddyBox.currentText diveDetailsListView.currentItem.modelData.divemaster = divemasterBox.currentText + diveDetailsListView.currentItem.modelData.cylinder = cylinderBox.currentText diveDetailsListView.currentItem.modelData.notes = detailsEdit.notesText diveDetailsPage.state = "view" Qt.inputMethod.hide() @@ -210,6 +213,21 @@ Item { Kirigami.Label { Layout.alignment: Qt.AlignRight + text: qsTr("Cylinder:") + } + ComboBox { + id: cylinderBox + editable: true + model: diveDetailsListView.currentItem.modelData.dive.cylinderList + inputMethodHints: Qt.ImhNoPredictiveText + Layout.fillWidth: true + style: ComboBoxStyle { + dropDownButtonWidth: 0 + } + } + + Kirigami.Label { + Layout.alignment: Qt.AlignRight text: qsTr("Gas mix:") } StyledTextField { diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp index 89873fbb3..871f93866 100644 --- a/mobile-widgets/qmlmanager.cpp +++ b/mobile-widgets/qmlmanager.cpp @@ -22,6 +22,7 @@ #include "core/cloudstorage.h" #include "core/subsurface-qt/SettingsObjectWrapper.h" #include "core/membuffer.h" +#include "qt-models/tankinfomodel.h" QMLManager *QMLManager::m_instance = NULL; @@ -778,7 +779,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, - QString startpressure, QString endpressure, QString gasmix) + QString startpressure, QString endpressure, QString gasmix, QString cylinder) { struct dive *d = get_dive_by_uniq_id(diveId.toInt()); DiveObjectHelper *myDive = new DiveObjectHelper(d); @@ -840,6 +841,27 @@ void QMLManager::commitChanges(QString diveId, QString date, QString location, Q d->cylinder[0].gasmix.he.permille = he; } } + // info for first cylinder + if (myDive->getCylinder() != cylinder) { + diveChanged = true; + int i, size, wp; + for (i = 0; i < sizeof(tank_info) && tank_info[i].name != NULL; i++) { + if (tank_info[i].name == cylinder ) { + if (tank_info[i].ml > 0){ + size = tank_info[i].ml; + wp = tank_info[i].bar * 1000; + } else { + size = cuft_to_l(tank_info[i].cuft) * 1000 / bar_to_atm(psi_to_bar(tank_info[i].psi)); + wp = psi_to_mbar(tank_info[i].psi); + } + break; + } + + } + d->cylinder[0].type.description = strdup(qPrintable(cylinder)); + d->cylinder[0].type.size.mliter = size; + d->cylinder[0].type.workingpressure.mbar = wp; + } if (myDive->suit() != suit) { diveChanged = true; free(d->suit); diff --git a/mobile-widgets/qmlmanager.h b/mobile-widgets/qmlmanager.h index b7be359ed..8c5b02fa1 100644 --- a/mobile-widgets/qmlmanager.h +++ b/mobile-widgets/qmlmanager.h @@ -124,11 +124,11 @@ public slots: void loadDivesWithValidCredentials(); void loadDiveProgress(int percent); void provideAuth(QNetworkReply *reply, QAuthenticator *auth); - void 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, - QString startpressure, QString endpressure, QString gasmix); + void 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, QString startpressure, + QString endpressure, QString gasmix, QString cylinder); void changesNeedSaving(); void saveChangesLocal(); void saveChangesCloud(bool forceRemoteSync); |