diff options
author | Jan Mulder <jlmulder@xs4all.nl> | 2018-01-28 15:21:28 +0100 |
---|---|---|
committer | Jan Mulder <jlmulder@xs4all.nl> | 2018-01-31 14:48:14 +0100 |
commit | 494ad2654082d85846cb902556921ab62a6dbb14 (patch) | |
tree | fc130087b7c90cf38b8bbf6513f1ed08cf05755f | |
parent | 83259008e763d3cc120c826f58f91a0ff62b6b92 (diff) | |
download | subsurface-494ad2654082d85846cb902556921ab62a6dbb14.tar.gz |
mobile cleanup: restyle construction of locationlist
See also e6e1473e6. The construction of the locationlist
was not the same as the 3 previous lists, and it needs
the inclusion of a new model file (divelocationmodel.cpp)
in the mobile app. In addition, as the mobile app is mainly
interested in a simple stringList (model) to populate a HintsText
field (or maybe later a combobox), this stringlist is added
to the model, to easy interfacing with QML.
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
-rw-r--r-- | core/subsurface-qt/DiveObjectHelper.cpp | 18 | ||||
-rw-r--r-- | core/subsurface-qt/DiveObjectHelper.h | 2 | ||||
-rw-r--r-- | mobile-widgets/qml/DiveDetailsEdit.qml | 3 | ||||
-rw-r--r-- | mobile-widgets/qmlmanager.cpp | 6 | ||||
-rw-r--r-- | mobile-widgets/qmlmanager.h | 5 | ||||
-rw-r--r-- | qt-models/CMakeLists.txt | 2 | ||||
-rw-r--r-- | qt-models/divelocationmodel.cpp | 8 | ||||
-rw-r--r-- | qt-models/divelocationmodel.h | 4 |
8 files changed, 24 insertions, 24 deletions
diff --git a/core/subsurface-qt/DiveObjectHelper.cpp b/core/subsurface-qt/DiveObjectHelper.cpp index 9372f422f..1d1bb2f00 100644 --- a/core/subsurface-qt/DiveObjectHelper.cpp +++ b/core/subsurface-qt/DiveObjectHelper.cpp @@ -410,21 +410,3 @@ QString DiveObjectHelper::firstGas() const gas = get_gas_string(m_dive->cylinder[0].gasmix); return gas; } - -QStringList DiveObjectHelper::locationList() const -{ - QStringList locations; - struct dive *d; - struct dive_site *ds; - int i = 0; - for_each_dive (i, d) { - if ((ds = get_dive_site_by_uuid(d->dive_site_uuid)) != NULL) { - QString temp = ds->name; - if (!temp.isEmpty()) - locations << temp; - } - } - locations.removeDuplicates(); - locations.sort(); - return locations; -} diff --git a/core/subsurface-qt/DiveObjectHelper.h b/core/subsurface-qt/DiveObjectHelper.h index 5da82c29e..766c20fa5 100644 --- a/core/subsurface-qt/DiveObjectHelper.h +++ b/core/subsurface-qt/DiveObjectHelper.h @@ -47,7 +47,6 @@ class DiveObjectHelper : public QObject { Q_PROPERTY(QString startPressure READ startPressure CONSTANT) Q_PROPERTY(QString endPressure READ endPressure CONSTANT) Q_PROPERTY(QString firstGas READ firstGas CONSTANT) - Q_PROPERTY(QStringList locationList READ locationList CONSTANT) public: DiveObjectHelper(struct dive *dive = NULL); ~DiveObjectHelper(); @@ -90,7 +89,6 @@ public: QString startPressure() const; QString endPressure() const; QString firstGas() const; - QStringList locationList() const; private: struct dive *m_dive; diff --git a/mobile-widgets/qml/DiveDetailsEdit.qml b/mobile-widgets/qml/DiveDetailsEdit.qml index c623a856f..4895ef9d1 100644 --- a/mobile-widgets/qml/DiveDetailsEdit.qml +++ b/mobile-widgets/qml/DiveDetailsEdit.qml @@ -129,8 +129,7 @@ Item { } HintsTextEdit { id: txtLocation - model: diveDetailsListView.currentItem && diveDetailsListView.currentItem.modelData !== null ? - diveDetailsListView.currentItem.modelData.dive.locationList : null + model: manager.locationList inputMethodHints: Qt.ImhNoPredictiveText Layout.fillWidth: true onEditingFinished: { diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp index 57cacba74..d28fa11ae 100644 --- a/mobile-widgets/qmlmanager.cpp +++ b/mobile-widgets/qmlmanager.cpp @@ -276,6 +276,7 @@ void QMLManager::openLocalThenRemote(QString url) buddyModel.updateModel(); emit buddyListChanged(); suitModel.updateModel(); emit suitListChanged(); divemasterModel.updateModel(); emit divemasterListChanged(); + locationModel.update(); emit locationListChanged(); } void QMLManager::mergeLocalRepo() @@ -1567,6 +1568,11 @@ QStringList QMLManager::divemasterList() const return divemasterModel.stringList(); } +QStringList QMLManager::locationList() const +{ + return locationModel.allSiteNames(); +} + QStringList QMLManager::cylinderInit() const { QStringList cylinders; diff --git a/mobile-widgets/qmlmanager.h b/mobile-widgets/qmlmanager.h index 4f188ac7d..17762e0a2 100644 --- a/mobile-widgets/qmlmanager.h +++ b/mobile-widgets/qmlmanager.h @@ -14,6 +14,7 @@ #include "core/downloadfromdcthread.h" #include "qt-models/divelistmodel.h" #include "qt-models/completionmodels.h" +#include "qt-models/divelocationmodel.h" class QMLManager : public QObject { Q_OBJECT @@ -39,6 +40,7 @@ class QMLManager : public QObject { Q_PROPERTY(QStringList suitList READ suitList NOTIFY suitListChanged) Q_PROPERTY(QStringList buddyList READ buddyList NOTIFY buddyListChanged) Q_PROPERTY(QStringList divemasterList READ divemasterList NOTIFY divemasterListChanged) + Q_PROPERTY(QStringList locationList READ locationList NOTIFY locationListChanged) Q_PROPERTY(QStringList cylinderInit READ cylinderInit CONSTANT) Q_PROPERTY(bool showPin MEMBER m_showPin WRITE setShowPin NOTIFY showPinChanged) Q_PROPERTY(QString progressMessage MEMBER m_progressMessage WRITE setProgressMessage NOTIFY progressMessageChanged) @@ -134,6 +136,7 @@ public: QStringList suitList() const; QStringList buddyList() const; QStringList divemasterList() const; + QStringList locationList() const; QStringList cylinderInit() const; bool showPin() const; void setShowPin(bool enable); @@ -200,6 +203,7 @@ private: BuddyCompletionModel buddyModel; SuitCompletionModel suitModel; DiveMasterCompletionModel divemasterModel; + LocationInformationModel locationModel; QString m_cloudUserName; QString m_cloudPassword; QString m_cloudPin; @@ -274,6 +278,7 @@ signals: void suitListChanged(); void buddyListChanged(); void divemasterListChanged(); + void locationListChanged(); }; #endif diff --git a/qt-models/CMakeLists.txt b/qt-models/CMakeLists.txt index f24f6d2a5..d286fd3eb 100644 --- a/qt-models/CMakeLists.txt +++ b/qt-models/CMakeLists.txt @@ -6,6 +6,7 @@ set(SUBSURFACE_GENERIC_MODELS_LIB_SRCS diveplotdatamodel.cpp diveimportedmodel.cpp completionmodels.cpp + divelocationmodel.cpp ) # models exclusively used in desktop builds @@ -25,7 +26,6 @@ set(SUBSURFACE_DESKTOP_MODELS_LIB_SRCS divetripmodel.cpp diveplannermodel.cpp divecomputerextradatamodel.cpp - divelocationmodel.cpp ssrfsortfilterproxymodel.cpp ) diff --git a/qt-models/divelocationmodel.cpp b/qt-models/divelocationmodel.cpp index d6fb09573..ad58f9c2f 100644 --- a/qt-models/divelocationmodel.cpp +++ b/qt-models/divelocationmodel.cpp @@ -128,9 +128,17 @@ void LocationInformationModel::update() beginResetModel(); internalRowCount = dive_site_table.nr; qSort(dive_site_table.dive_sites, dive_site_table.dive_sites + dive_site_table.nr, dive_site_less_than); + locationNames.clear(); + for (int i = 0; i < internalRowCount; i++) + locationNames << QString(dive_site_table.dive_sites[i]->name); endResetModel(); } +QStringList LocationInformationModel::allSiteNames() const +{ + return(locationNames); +} + bool LocationInformationModel::setData(const QModelIndex &index, const QVariant &value, int role) { if (!index.isValid() || index.row() < 2) diff --git a/qt-models/divelocationmodel.h b/qt-models/divelocationmodel.h index 0829abd30..404b66f48 100644 --- a/qt-models/divelocationmodel.h +++ b/qt-models/divelocationmodel.h @@ -17,6 +17,7 @@ bool filter_same_gps_cb (QAbstractItemModel *m, int sourceRow, const QModelIndex class LocationInformationModel : public QAbstractTableModel { Q_OBJECT public: + LocationInformationModel(QObject *obj = 0); enum Columns { UUID, NAME, LATITUDE, LONGITUDE, COORDS, DESCRIPTION, NOTES, TAXONOMY_1, TAXONOMY_2, TAXONOMY_3, COLUMNS}; enum Roles { UUID_ROLE = Qt::UserRole + 1 }; static LocationInformationModel *instance(); @@ -29,9 +30,10 @@ public: public slots: void update(); + QStringList allSiteNames() const; private: - LocationInformationModel(QObject *obj = 0); int internalRowCount; + QStringList locationNames; QLineEdit *textField; }; |