diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2015-12-26 22:57:47 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2015-12-26 22:57:47 -0800 |
commit | 99a5a743c48e88d94bce96a78bc9bea9d8f4343e (patch) | |
tree | d479334671c548bcca14ea5cb60500642c67459c | |
parent | 9be42fff813ab959e23a813b37319ebf75a1951b (diff) | |
download | subsurface-99a5a743c48e88d94bce96a78bc9bea9d8f4343e.tar.gz |
QML UI: change the way we extract input data from dive edit
Instead of doing the silly "onEditingFinished" we get the strings from the QML
components at the time we commit the change. Much more logical, much more
straight forward, no issues with the TextArea not having an onEditingFinished
signal.
This still has a few open todos: the temperatures aren't parsed, the edit
screen is missing depth and duration, we can't edit the dive time (and it isn't
passed in on the commit). But it's progress.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | qt-mobile/qml/DiveDetails.qml | 8 | ||||
-rw-r--r-- | qt-mobile/qml/DiveDetailsEdit.qml | 29 | ||||
-rw-r--r-- | qt-mobile/qmlmanager.cpp | 37 | ||||
-rw-r--r-- | qt-mobile/qmlmanager.h | 3 |
4 files changed, 49 insertions, 28 deletions
diff --git a/qt-mobile/qml/DiveDetails.qml b/qt-mobile/qml/DiveDetails.qml index ca2e04f08..912a97840 100644 --- a/qt-mobile/qml/DiveDetails.qml +++ b/qt-mobile/qml/DiveDetails.qml @@ -53,9 +53,13 @@ MobileComponents.Page { iconName: checked ? "view-readermode" : "document-edit" onTriggered: { if (diveDetailsWindow.state == "edit") { - manager.commitChanges(dive_id, suit, buddy, divemaster, notes); + manager.commitChanges(dive_id, detailsEdit.locationText, detailsEdit.gpsText, detailsEdit.durationText, + detailsEdit.depthText, detailsEdit.airtempText, detailsEdit.watertempText, detailsEdit.suitText, + detailsEdit.buddyText, detailsEdit.divemasterText, detailsEdit.notesText); + diveDetailsWindow.state = "view"; + } else { + diveDetailsWindow.state = "edit"; } - diveDetailsWindow.state = checked ? "edit" : "view"; contextDrawer.close(); // close drawer? } diff --git a/qt-mobile/qml/DiveDetailsEdit.qml b/qt-mobile/qml/DiveDetailsEdit.qml index e3545535c..4ed90cd2d 100644 --- a/qt-mobile/qml/DiveDetailsEdit.qml +++ b/qt-mobile/qml/DiveDetailsEdit.qml @@ -7,7 +7,14 @@ import org.subsurfacedivelog.mobile 1.0 import org.kde.plasma.mobilecomponents 0.2 as MobileComponents Item { - + property alias locationText: txtLocation.text + property string gpsText + property alias airtempText: txtAirTemp.text + property alias watertempText: txtWaterTemp.text + property alias suitText: txtSuit.text + property alias buddyText: txtBuddy.text + property alias divemasterText: txtDiveMaster.text + property alias notesText: txtNotes.text ColumnLayout { anchors { left: parent.left @@ -36,6 +43,11 @@ Item { Layout.fillWidth: true } + // we should add a checkbox here that allows the user + // to add the current location as the dive location + // (think of someone adding a dive while on the boat or + // at the dive site) + MobileComponents.Label { Layout.alignment: Qt.AlignRight text: "Air Temp:" @@ -59,15 +71,11 @@ Item { MobileComponents.Label { Layout.alignment: Qt.AlignRight text: "Suit:" - } TextField { id: txtSuit text: suit Layout.fillWidth: true - onEditingFinished: { - suit = text; - } } MobileComponents.Label { @@ -78,9 +86,6 @@ Item { id: txtBuddy text: buddy Layout.fillWidth: true - onEditingFinished: { - buddy = text; - } } MobileComponents.Label { @@ -91,9 +96,6 @@ Item { id: txtDiveMaster text: divemaster Layout.fillWidth: true - onEditingFinished: { - divemaster = text; - } } MobileComponents.Label { @@ -109,11 +111,6 @@ Item { Layout.minimumHeight: MobileComponents.Units.gridUnit * 6 selectByMouse: true wrapMode: TextEdit.WrapAtWordBoundaryOrAnywhere -// there is no onEditingFinished signal... not sure how to get the value -// out of this field when we're done editing -// onEditingFinished: { -// diveDetailsWindow.notes = text; -// } } } Item { diff --git a/qt-mobile/qmlmanager.cpp b/qt-mobile/qmlmanager.cpp index cdf844492..c0a2149b3 100644 --- a/qt-mobile/qmlmanager.cpp +++ b/qt-mobile/qmlmanager.cpp @@ -276,7 +276,8 @@ void QMLManager::loadDivesWithValidCredentials() setLoadFromCloud(true); } -void QMLManager::commitChanges(QString diveId, QString suit, QString buddy, QString diveMaster, QString notes) +void QMLManager::commitChanges(QString diveId, QString location, QString gps, QString duration, QString depth, + QString airtemp, QString watertemp, QString suit, QString buddy, QString diveMaster, QString notes) { struct dive *d = get_dive_by_uniq_id(diveId.toInt()); qDebug() << diveId.toInt() << (d != 0 ? d->number : -1); @@ -287,25 +288,43 @@ void QMLManager::commitChanges(QString diveId, QString suit, QString buddy, QStr } bool diveChanged = false; - if (!same_string(d->suit, suit.toUtf8().data())) { + struct dive_site *ds = get_dive_site_by_uuid(d->dive_site_uuid); + char *locationtext = NULL; + if (ds) + locationtext = ds->name; + if (!same_string(locationtext, qPrintable(location))) { + diveChanged = true; + // this is not ideal - and it's missing the gps information + // but for now let's just create a new dive site + ds = get_dive_site_by_uuid(create_dive_site(qPrintable(location), d->when)); + d->dive_site_uuid = ds->uuid; + } + // now we need to handle the string representations of duration, depth, airtemp and watertemp + // and do something useful... + // + // FIXME + // + // TODO + + if (!same_string(d->suit, qPrintable(suit))) { diveChanged = true; free(d->suit); - d->suit = strdup(suit.toUtf8().data()); + d->suit = strdup(qPrintable(suit)); } - if (!same_string(d->buddy, buddy.toUtf8().data())) { + if (!same_string(d->buddy, qPrintable(buddy))) { diveChanged = true; free(d->buddy); - d->buddy = strdup(buddy.toUtf8().data()); + d->buddy = strdup(qPrintable(buddy)); } - if (!same_string(d->divemaster, diveMaster.toUtf8().data())) { + if (!same_string(d->divemaster, qPrintable(diveMaster))) { diveChanged = true; free(d->divemaster); - d->divemaster = strdup(diveMaster.toUtf8().data()); + d->divemaster = strdup(qPrintable(diveMaster)); } - if (!same_string(d->notes, notes.toUtf8().data())) { + if (!same_string(d->notes, qPrintable(notes))) { diveChanged = true; free(d->notes); - d->notes = strdup(notes.toUtf8().data()); + d->notes = strdup(qPrintable(notes)); } if (diveChanged) { DiveListModel::instance()->updateDive(d); diff --git a/qt-mobile/qmlmanager.h b/qt-mobile/qmlmanager.h index 23b6bd41f..6d019a480 100644 --- a/qt-mobile/qmlmanager.h +++ b/qt-mobile/qmlmanager.h @@ -71,7 +71,8 @@ public slots: void loadDivesWithValidCredentials(); void loadDiveProgress(int percent); void provideAuth(QNetworkReply *reply, QAuthenticator *auth); - void commitChanges(QString diveId, QString suit, QString buddy, QString diveMaster, QString notes); + void commitChanges(QString diveId, QString location, QString gps, QString duration, QString depth, + QString airtemp, QString watertemp, QString suit, QString buddy, QString diveMaster, QString notes); void saveChanges(); QString addDive(); void applyGpsData(); |