From 64704d6e5a0865c5acb6ce40cc32ba929f41ba00 Mon Sep 17 00:00:00 2001 From: Jan Mulder Date: Wed, 22 Nov 2017 16:19:44 +0100 Subject: mobile: autocomplete location names Add the capability to select the location name from a list, constructed from the known dive sites in the logbook. Fixes: #546 Signed-off-by: Jan Mulder --- core/subsurface-qt/DiveObjectHelper.cpp | 17 +++++++++++++++++ core/subsurface-qt/DiveObjectHelper.h | 2 ++ mobile-widgets/qml/DiveDetails.qml | 1 + mobile-widgets/qml/DiveDetailsEdit.qml | 11 ++++++----- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/core/subsurface-qt/DiveObjectHelper.cpp b/core/subsurface-qt/DiveObjectHelper.cpp index 8e5890b4c..7a3767409 100644 --- a/core/subsurface-qt/DiveObjectHelper.cpp +++ b/core/subsurface-qt/DiveObjectHelper.cpp @@ -426,6 +426,23 @@ QStringList DiveObjectHelper::suitList() const return suits; } +QStringList DiveObjectHelper::locationList() const +{ + QStringList locations; + struct dive *d; + struct dive_site *ds; + int i = 0; + for_each_dive (i, d) { + ds = get_dive_site_by_uuid(d->dive_site_uuid); + QString temp = ds->name; + if (!temp.isEmpty()) + locations << temp; + } + locations.removeDuplicates(); + locations.sort(); + return locations; +} + QStringList DiveObjectHelper::buddyList() const { QStringList buddies; diff --git a/core/subsurface-qt/DiveObjectHelper.h b/core/subsurface-qt/DiveObjectHelper.h index 83aea4841..49542ca62 100644 --- a/core/subsurface-qt/DiveObjectHelper.h +++ b/core/subsurface-qt/DiveObjectHelper.h @@ -50,6 +50,7 @@ class DiveObjectHelper : public QObject { Q_PROPERTY(QStringList suitList READ suitList CONSTANT) Q_PROPERTY(QStringList buddyList READ buddyList CONSTANT) Q_PROPERTY(QStringList divemasterList READ divemasterList CONSTANT) + Q_PROPERTY(QStringList locationList READ locationList CONSTANT) public: DiveObjectHelper(struct dive *dive = NULL); ~DiveObjectHelper(); @@ -93,6 +94,7 @@ public: QString endPressure() const; QString firstGas() const; QStringList suitList() const; + QStringList locationList() const; QStringList buddyList() const; QStringList divemasterList() const; diff --git a/mobile-widgets/qml/DiveDetails.qml b/mobile-widgets/qml/DiveDetails.qml index 2287b6348..dc0af53b6 100644 --- a/mobile-widgets/qml/DiveDetails.qml +++ b/mobile-widgets/qml/DiveDetails.qml @@ -24,6 +24,7 @@ Kirigami.Page { property alias depth: detailsEdit.depthText property alias duration: detailsEdit.durationText property alias location: detailsEdit.locationText + property alias locationModel: detailsEdit.locationModel property alias gps: detailsEdit.gpsText property alias notes: detailsEdit.notesText property alias suitIndex: detailsEdit.suitIndex diff --git a/mobile-widgets/qml/DiveDetailsEdit.qml b/mobile-widgets/qml/DiveDetailsEdit.qml index 431a0e22f..4c4f8e47c 100644 --- a/mobile-widgets/qml/DiveDetailsEdit.qml +++ b/mobile-widgets/qml/DiveDetailsEdit.qml @@ -35,6 +35,7 @@ Item { property alias divemasterModel: divemasterBox.model property alias buddyModel: buddyBox.model property alias cylinderModel: cylinderBox.model + property alias locationModel: txtLocation.model property int rating property int visibility @@ -105,12 +106,12 @@ Item { text: qsTr("Location:") font.pointSize: subsurfaceTheme.smallPointSize } - Controls.TextField { - id: txtLocation; + HintsTextEdit { + id: txtLocation + model: diveDetailsListView.currentItem && diveDetailsListView.currentItem.modelData !== null ? + diveDetailsListView.currentItem.modelData.dive.locationList : null + inputMethodHints: Qt.ImhNoPredictiveText Layout.fillWidth: true - onEditingFinished: { - focus = false - } } Controls.Label { -- cgit v1.2.3-70-g09d2