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>
This commit is contained in:
Joakim Bygdell 2016-08-30 16:24:19 +02:00 committed by Dirk Hohndel
parent 7b3665827a
commit 674d8331f5
6 changed files with 74 additions and 16 deletions

View file

@ -5,6 +5,7 @@
#include "../qthelper.h" #include "../qthelper.h"
#include "../helpers.h" #include "../helpers.h"
#include "../../qt-models/tankinfomodel.h"
static QString EMPTY_DIVE_STRING = QStringLiteral(""); static QString EMPTY_DIVE_STRING = QStringLiteral("");
enum returnPressureSelector {START_PRESSURE, END_PRESSURE}; enum returnPressureSelector {START_PRESSURE, END_PRESSURE};
@ -252,15 +253,29 @@ QString DiveObjectHelper::suit() const
return m_dive->suit ? m_dive->suit : EMPTY_DIVE_STRING; return m_dive->suit ? m_dive->suit : EMPTY_DIVE_STRING;
} }
QString DiveObjectHelper::cylinderList() const QStringList DiveObjectHelper::cylinderList() const
{ {
QString cylinders; QStringList cylinders;
for (int i = 0; i < MAX_CYLINDERS; i++) { struct dive *d;
QString cyl = getFormattedCylinder(m_dive, i); int i = 0;
for_each_dive (i, d) {
for (int j = 0; j < MAX_CYLINDERS; j++) {
QString cyl = d->cylinder[j].type.description;
if (cyl == EMPTY_DIVE_STRING) if (cyl == EMPTY_DIVE_STRING)
continue; continue;
cylinders += cyl + "; "; cylinders << cyl;
} }
}
for (i = 0; i < sizeof(tank_info) && tank_info[i].name != NULL; i++) {
QString cyl = tank_info[i].name;
if (cyl == EMPTY_DIVE_STRING)
continue;
cylinders << cyl;
}
cylinders.removeDuplicates();
cylinders.sort();
return cylinders; return cylinders;
} }

View file

@ -33,7 +33,7 @@ class DiveObjectHelper : public QObject {
Q_PROPERTY(QStringList weights READ weights CONSTANT) Q_PROPERTY(QStringList weights READ weights CONSTANT)
Q_PROPERTY(bool singleWeight READ singleWeight CONSTANT) Q_PROPERTY(bool singleWeight READ singleWeight CONSTANT)
Q_PROPERTY(QString suit READ suit CONSTANT) Q_PROPERTY(QString suit READ suit CONSTANT)
Q_PROPERTY(QString cylinderList READ cylinderList CONSTANT) Q_PROPERTY(QStringList cylinderList READ cylinderList CONSTANT)
Q_PROPERTY(QStringList cylinders READ cylinders CONSTANT) Q_PROPERTY(QStringList cylinders READ cylinders CONSTANT)
Q_PROPERTY(QList<CylinderObjectHelper*> cylinderObjects READ cylinderObjects CONSTANT) Q_PROPERTY(QList<CylinderObjectHelper*> cylinderObjects READ cylinderObjects CONSTANT)
Q_PROPERTY(QString trip READ trip CONSTANT) Q_PROPERTY(QString trip READ trip CONSTANT)
@ -76,7 +76,7 @@ public:
QString weight(int idx) const; QString weight(int idx) const;
bool singleWeight() const; bool singleWeight() const;
QString suit() const; QString suit() const;
QString cylinderList() const; QStringList cylinderList() const;
QStringList cylinders() const; QStringList cylinders() const;
QString cylinder(int idx) const; QString cylinder(int idx) const;
QList<CylinderObjectHelper*> cylinderObjects() const; QList<CylinderObjectHelper*> cylinderObjects() const;

View file

@ -29,6 +29,8 @@ Kirigami.Page {
property alias weight: detailsEdit.weightText property alias weight: detailsEdit.weightText
property alias startpressure: detailsEdit.startpressureText property alias startpressure: detailsEdit.startpressureText
property alias endpressure: detailsEdit.endpressureText property alias endpressure: detailsEdit.endpressureText
property alias cylinderIndex: detailsEdit.cylinderIndex
property alias cylinderModel: detailsEdit.cylinderModel
property alias gasmix: detailsEdit.gasmixText property alias gasmix: detailsEdit.gasmixText
property alias gpsCheckbox: detailsEdit.gpsCheckbox property alias gpsCheckbox: detailsEdit.gpsCheckbox
property int updateCurrentIdx: manager.updateSelectedDive property int updateCurrentIdx: manager.updateSelectedDive
@ -168,6 +170,7 @@ Kirigami.Page {
startpressure = diveDetailsListView.currentItem.modelData.dive.startPressure startpressure = diveDetailsListView.currentItem.modelData.dive.startPressure
endpressure = diveDetailsListView.currentItem.modelData.dive.endPressure endpressure = diveDetailsListView.currentItem.modelData.dive.endPressure
gasmix = diveDetailsListView.currentItem.modelData.dive.firstGas gasmix = diveDetailsListView.currentItem.modelData.dive.firstGas
cylinderIndex = diveDetailsListView.currentItem.modelData.dive.cylinderList.indexOf(diveDetailsListView.currentItem.modelData.dive.getCylinder)
} else { } else {
// careful when translating, this text is "magic" in DiveDetailsEdit.qml // careful when translating, this text is "magic" in DiveDetailsEdit.qml
startpressure = "cannot edit multiple cylinders" startpressure = "cannot edit multiple cylinders"

View file

@ -18,6 +18,7 @@ Item {
property alias suitIndex: suitBox.currentIndex property alias suitIndex: suitBox.currentIndex
property alias buddyIndex: buddyBox.currentIndex property alias buddyIndex: buddyBox.currentIndex
property alias divemasterIndex: divemasterBox.currentIndex property alias divemasterIndex: divemasterBox.currentIndex
property alias cylinderIndex: cylinderBox.currentIndex
property alias notesText: txtNotes.text property alias notesText: txtNotes.text
property alias durationText: txtDuration.text property alias durationText: txtDuration.text
property alias depthText: txtDepth.text property alias depthText: txtDepth.text
@ -29,13 +30,14 @@ Item {
property alias suitModel: suitBox.model property alias suitModel: suitBox.model
property alias divemasterModel: divemasterBox.model property alias divemasterModel: divemasterBox.model
property alias buddyModel: buddyBox.model property alias buddyModel: buddyBox.model
property alias cylinderModel: cylinderBox.model
function saveData() { function saveData() {
// 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, suitBox.editText, detailsEdit.depthText, detailsEdit.airtempText, detailsEdit.watertempText, suitBox.editText, buddyBox.editText,
buddyBox.editText, divemasterBox.editText, detailsEdit.weightText, detailsEdit.notesText, divemasterBox.editText, detailsEdit.weightText, detailsEdit.notesText, detailsEdit.startpressureText,
detailsEdit.startpressureText, detailsEdit.endpressureText, detailsEdit.gasmixText) detailsEdit.endpressureText, detailsEdit.gasmixText, cylinderBox.editText)
// trigger the profile to be redrawn // trigger the profile to be redrawn
QMLProfile.diveId = dive_id QMLProfile.diveId = dive_id
@ -53,6 +55,7 @@ Item {
diveDetailsListView.currentItem.modelData.suit = suitBox.currentText diveDetailsListView.currentItem.modelData.suit = suitBox.currentText
diveDetailsListView.currentItem.modelData.buddy = buddyBox.currentText diveDetailsListView.currentItem.modelData.buddy = buddyBox.currentText
diveDetailsListView.currentItem.modelData.divemaster = divemasterBox.currentText diveDetailsListView.currentItem.modelData.divemaster = divemasterBox.currentText
diveDetailsListView.currentItem.modelData.cylinder = cylinderBox.currentText
diveDetailsListView.currentItem.modelData.notes = detailsEdit.notesText diveDetailsListView.currentItem.modelData.notes = detailsEdit.notesText
diveDetailsPage.state = "view" diveDetailsPage.state = "view"
Qt.inputMethod.hide() Qt.inputMethod.hide()
@ -208,6 +211,21 @@ Item {
Layout.fillWidth: true Layout.fillWidth: true
} }
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 { Kirigami.Label {
Layout.alignment: Qt.AlignRight Layout.alignment: Qt.AlignRight
text: qsTr("Gas mix:") text: qsTr("Gas mix:")

View file

@ -22,6 +22,7 @@
#include "core/cloudstorage.h" #include "core/cloudstorage.h"
#include "core/subsurface-qt/SettingsObjectWrapper.h" #include "core/subsurface-qt/SettingsObjectWrapper.h"
#include "core/membuffer.h" #include "core/membuffer.h"
#include "qt-models/tankinfomodel.h"
QMLManager *QMLManager::m_instance = NULL; 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 // 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, 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 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()); struct dive *d = get_dive_by_uniq_id(diveId.toInt());
DiveObjectHelper *myDive = new DiveObjectHelper(d); 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; 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) { if (myDive->suit() != suit) {
diveChanged = true; diveChanged = true;
free(d->suit); free(d->suit);

View file

@ -124,11 +124,11 @@ 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);
void commitChanges(QString diveId, QString date, QString location, void commitChanges(QString diveId, QString date, QString location, QString gps,
QString gps, QString duration, QString depth, QString duration, QString depth, QString airtemp,
QString airtemp, QString watertemp, QString suit, QString watertemp, QString suit, QString buddy,
QString buddy, QString diveMaster, QString weight, QString notes, QString diveMaster, QString weight, QString notes, QString startpressure,
QString startpressure, QString endpressure, QString gasmix); QString endpressure, QString gasmix, QString cylinder);
void changesNeedSaving(); void changesNeedSaving();
void saveChangesLocal(); void saveChangesLocal();
void saveChangesCloud(bool forceRemoteSync); void saveChangesCloud(bool forceRemoteSync);