diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2016-01-01 17:23:29 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2016-01-01 17:26:26 -0800 |
commit | fa338a26b8b4e390c6acc391e159dff8859dd519 (patch) | |
tree | 308b43a85884b069cc207c565a4d731097c1f421 | |
parent | 14a09689a421a32e812094b5fb99f33b99443266 (diff) | |
download | subsurface-fa338a26b8b4e390c6acc391e159dff8859dd519.tar.gz |
QML UI: add feature to add current position when editing dive
This isn't quite perfect yet. If it takes too long to get the GPS fix (i.e., if
you save it before you get the fix), this will simply fail and not store a
position. But in normal conditions (you check the box, you edit the data, you
save), especially when outside on a dive boat, this should work fine.
For the other cases we need to implement some kind of callback to still collect
the data.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | qt-mobile/qml/DiveDetailsEdit.qml | 11 | ||||
-rw-r--r-- | qt-mobile/qmlmanager.cpp | 31 | ||||
-rw-r--r-- | qt-mobile/qmlmanager.h | 1 |
3 files changed, 37 insertions, 6 deletions
diff --git a/qt-mobile/qml/DiveDetailsEdit.qml b/qt-mobile/qml/DiveDetailsEdit.qml index 051e38676..9a639ddb7 100644 --- a/qt-mobile/qml/DiveDetailsEdit.qml +++ b/qt-mobile/qml/DiveDetailsEdit.qml @@ -49,6 +49,17 @@ Item { // 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: "Use current\nGPS location:" + } + CheckBox { + id: checkboxGPS + onCheckedChanged: { + if (checked) + gpsText = manager.getCurrentPosition() + } + } MobileComponents.Label { Layout.alignment: Qt.AlignRight diff --git a/qt-mobile/qmlmanager.cpp b/qt-mobile/qmlmanager.cpp index 70bc5264a..f976a4bb6 100644 --- a/qt-mobile/qmlmanager.cpp +++ b/qt-mobile/qmlmanager.cpp @@ -328,12 +328,26 @@ void QMLManager::commitChanges(QString diveId, QString location, QString gps, QS 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 depth - // and do something useful... - // - // FIXME - // - // TODO + QString gpsString = getCurrentPosition(); + if (gpsString != QString("waiting for the next gps location")) { + qDebug() << "from commitChanges call to getCurrentPosition returns" << gpsString; + double lat, lon; + if (parseGpsText(qPrintable(gpsString), &lat, &lon)) { + struct dive_site *ds = get_dive_site_by_uuid(d->dive_site_uuid); + if (ds) { + ds->latitude.udeg = lat * 1000000; + ds->longitude.udeg = lon * 1000000; + } else { + degrees_t latData, lonData; + latData.udeg = lat; + lonData.udeg = lon; + d->dive_site_uuid = create_dive_site_with_gps("new site", latData, lonData, d->when); + } + qDebug() << "set up dive site with new GPS data"; + } + } else { + qDebug() << "still don't have a position - will need to implement some sort of callback"; + } if (get_dive_duration_string(d->duration.seconds, tr("h:"), tr("min")) != duration) { diveChanged = true; int h = 0, m = 0, s = 0; @@ -442,6 +456,11 @@ QString QMLManager::addDive() return DiveListModel::instance()->startAddDive(); } +QString QMLManager::getCurrentPosition() +{ + return locationProvider->currentPosition(); +} + void QMLManager::applyGpsData() { locationProvider->applyLocations(); diff --git a/qt-mobile/qmlmanager.h b/qt-mobile/qmlmanager.h index 6d019a480..097aca3a2 100644 --- a/qt-mobile/qmlmanager.h +++ b/qt-mobile/qmlmanager.h @@ -82,6 +82,7 @@ public slots: void showMap(QString location); QString getNumber(QString diveId); QString getDate(QString diveId); + QString getCurrentPosition(); private: QString m_cloudUserName; |