diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2016-01-05 22:53:32 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2016-01-05 22:53:32 -0800 |
commit | e774c8077b516652dc0139a5bac93e60f0ed9b9f (patch) | |
tree | be63b54c6b66198e11c18564e83e56bce6db20eb | |
parent | 415536aba9cc805c2ed2df2e6981820e2b0680b2 (diff) | |
download | subsurface-e774c8077b516652dc0139a5bac93e60f0ed9b9f.tar.gz |
QML UI: allow edit of dive date and time
This is a bit more complicated because we are asking the user to edit the text
field instead of giving them a date and time picker. This is not a great
choice, but let's run with it for now.
One downside is that the user is likely going to edit the date "Oct 29" -> "Oct
25" without adjusting the day of the week. And if we then try to parse that Qt
correctly complains about an invalid date. So we hack around this by removing
the day of the week from both the format and the date entered (which of course
now will break things if the user did, in fact, adjust the day of the week). As
I said, not a great solution.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | qt-mobile/qml/DiveDetails.qml | 3 | ||||
-rw-r--r-- | qt-mobile/qmlmanager.cpp | 21 | ||||
-rw-r--r-- | qt-mobile/qmlmanager.h | 2 |
3 files changed, 23 insertions, 3 deletions
diff --git a/qt-mobile/qml/DiveDetails.qml b/qt-mobile/qml/DiveDetails.qml index a99aa628c..27a8996da 100644 --- a/qt-mobile/qml/DiveDetails.qml +++ b/qt-mobile/qml/DiveDetails.qml @@ -52,9 +52,10 @@ MobileComponents.Page { iconName: checked ? "view-readermode" : "document-edit" onTriggered: { if (diveDetailsWindow.state == "edit") { - manager.commitChanges(dive_id, 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.buddyText, detailsEdit.divemasterText, detailsEdit.notesText) + date = detailsEdit.dateText location = detailsEdit.locationText // gps = detailsEdit.gps duration = detailsEdit.durationText diff --git a/qt-mobile/qmlmanager.cpp b/qt-mobile/qmlmanager.cpp index 90293e8bf..9b6911b3a 100644 --- a/qt-mobile/qmlmanager.cpp +++ b/qt-mobile/qmlmanager.cpp @@ -303,7 +303,7 @@ void QMLManager::loadDivesWithValidCredentials() setLoadFromCloud(true); } -void QMLManager::commitChanges(QString diveId, 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 notes) { struct dive *d = get_dive_by_uniq_id(diveId.toInt()); @@ -315,6 +315,25 @@ void QMLManager::commitChanges(QString diveId, QString location, QString gps, QS } bool diveChanged = false; + if (date != get_dive_date_string(d->when)) { + diveChanged = true; + QDateTime newDate; + // what a pain - Qt will not parse dates if the day of the week is incorrect + // so if the user changed the date but didn't update the day of the week (most likely behavior, actually), + // we need to make sure we don't try to parse that + QString format(QString(prefs.date_format) + " " + prefs.time_format); + if (format.contains("ddd") || format.contains("dddd")) { + QString dateFormatToDrop = format.contains("ddd") ? "ddd" : "dddd"; + QDateTime ts; + QLocale loc = getLocale(); + ts.setMSecsSinceEpoch(d->when * 1000L); + QString drop = loc.toString(ts.toUTC(), dateFormatToDrop); + format.replace(dateFormatToDrop, ""); + date.replace(drop, ""); + } + newDate = QDateTime::fromString(date, format); + d->when = newDate.toMSecsSinceEpoch() / 1000 + gettimezoneoffset(newDate.toMSecsSinceEpoch() / 1000); + } struct dive_site *ds = get_dive_site_by_uuid(d->dive_site_uuid); char *locationtext = NULL; if (ds) diff --git a/qt-mobile/qmlmanager.h b/qt-mobile/qmlmanager.h index 097aca3a2..24ca265e6 100644 --- a/qt-mobile/qmlmanager.h +++ b/qt-mobile/qmlmanager.h @@ -71,7 +71,7 @@ public slots: void loadDivesWithValidCredentials(); void loadDiveProgress(int percent); void provideAuth(QNetworkReply *reply, QAuthenticator *auth); - void commitChanges(QString diveId, QString location, QString gps, QString duration, QString depth, + 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 notes); void saveChanges(); QString addDive(); |