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>
This commit is contained in:
Jan Mulder 2018-01-28 15:21:28 +01:00
parent 83259008e7
commit 494ad26540
8 changed files with 24 additions and 24 deletions

View file

@ -410,21 +410,3 @@ QString DiveObjectHelper::firstGas() const
gas = get_gas_string(m_dive->cylinder[0].gasmix); gas = get_gas_string(m_dive->cylinder[0].gasmix);
return gas; 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;
}

View file

@ -47,7 +47,6 @@ class DiveObjectHelper : public QObject {
Q_PROPERTY(QString startPressure READ startPressure CONSTANT) Q_PROPERTY(QString startPressure READ startPressure CONSTANT)
Q_PROPERTY(QString endPressure READ endPressure CONSTANT) Q_PROPERTY(QString endPressure READ endPressure CONSTANT)
Q_PROPERTY(QString firstGas READ firstGas CONSTANT) Q_PROPERTY(QString firstGas READ firstGas CONSTANT)
Q_PROPERTY(QStringList locationList READ locationList CONSTANT)
public: public:
DiveObjectHelper(struct dive *dive = NULL); DiveObjectHelper(struct dive *dive = NULL);
~DiveObjectHelper(); ~DiveObjectHelper();
@ -90,7 +89,6 @@ public:
QString startPressure() const; QString startPressure() const;
QString endPressure() const; QString endPressure() const;
QString firstGas() const; QString firstGas() const;
QStringList locationList() const;
private: private:
struct dive *m_dive; struct dive *m_dive;

View file

@ -129,8 +129,7 @@ Item {
} }
HintsTextEdit { HintsTextEdit {
id: txtLocation id: txtLocation
model: diveDetailsListView.currentItem && diveDetailsListView.currentItem.modelData !== null ? model: manager.locationList
diveDetailsListView.currentItem.modelData.dive.locationList : null
inputMethodHints: Qt.ImhNoPredictiveText inputMethodHints: Qt.ImhNoPredictiveText
Layout.fillWidth: true Layout.fillWidth: true
onEditingFinished: { onEditingFinished: {

View file

@ -276,6 +276,7 @@ void QMLManager::openLocalThenRemote(QString url)
buddyModel.updateModel(); emit buddyListChanged(); buddyModel.updateModel(); emit buddyListChanged();
suitModel.updateModel(); emit suitListChanged(); suitModel.updateModel(); emit suitListChanged();
divemasterModel.updateModel(); emit divemasterListChanged(); divemasterModel.updateModel(); emit divemasterListChanged();
locationModel.update(); emit locationListChanged();
} }
void QMLManager::mergeLocalRepo() void QMLManager::mergeLocalRepo()
@ -1567,6 +1568,11 @@ QStringList QMLManager::divemasterList() const
return divemasterModel.stringList(); return divemasterModel.stringList();
} }
QStringList QMLManager::locationList() const
{
return locationModel.allSiteNames();
}
QStringList QMLManager::cylinderInit() const QStringList QMLManager::cylinderInit() const
{ {
QStringList cylinders; QStringList cylinders;

View file

@ -14,6 +14,7 @@
#include "core/downloadfromdcthread.h" #include "core/downloadfromdcthread.h"
#include "qt-models/divelistmodel.h" #include "qt-models/divelistmodel.h"
#include "qt-models/completionmodels.h" #include "qt-models/completionmodels.h"
#include "qt-models/divelocationmodel.h"
class QMLManager : public QObject { class QMLManager : public QObject {
Q_OBJECT Q_OBJECT
@ -39,6 +40,7 @@ class QMLManager : public QObject {
Q_PROPERTY(QStringList suitList READ suitList NOTIFY suitListChanged) Q_PROPERTY(QStringList suitList READ suitList NOTIFY suitListChanged)
Q_PROPERTY(QStringList buddyList READ buddyList NOTIFY buddyListChanged) Q_PROPERTY(QStringList buddyList READ buddyList NOTIFY buddyListChanged)
Q_PROPERTY(QStringList divemasterList READ divemasterList NOTIFY divemasterListChanged) 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(QStringList cylinderInit READ cylinderInit CONSTANT)
Q_PROPERTY(bool showPin MEMBER m_showPin WRITE setShowPin NOTIFY showPinChanged) Q_PROPERTY(bool showPin MEMBER m_showPin WRITE setShowPin NOTIFY showPinChanged)
Q_PROPERTY(QString progressMessage MEMBER m_progressMessage WRITE setProgressMessage NOTIFY progressMessageChanged) Q_PROPERTY(QString progressMessage MEMBER m_progressMessage WRITE setProgressMessage NOTIFY progressMessageChanged)
@ -134,6 +136,7 @@ public:
QStringList suitList() const; QStringList suitList() const;
QStringList buddyList() const; QStringList buddyList() const;
QStringList divemasterList() const; QStringList divemasterList() const;
QStringList locationList() const;
QStringList cylinderInit() const; QStringList cylinderInit() const;
bool showPin() const; bool showPin() const;
void setShowPin(bool enable); void setShowPin(bool enable);
@ -200,6 +203,7 @@ private:
BuddyCompletionModel buddyModel; BuddyCompletionModel buddyModel;
SuitCompletionModel suitModel; SuitCompletionModel suitModel;
DiveMasterCompletionModel divemasterModel; DiveMasterCompletionModel divemasterModel;
LocationInformationModel locationModel;
QString m_cloudUserName; QString m_cloudUserName;
QString m_cloudPassword; QString m_cloudPassword;
QString m_cloudPin; QString m_cloudPin;
@ -274,6 +278,7 @@ signals:
void suitListChanged(); void suitListChanged();
void buddyListChanged(); void buddyListChanged();
void divemasterListChanged(); void divemasterListChanged();
void locationListChanged();
}; };
#endif #endif

View file

@ -6,6 +6,7 @@ set(SUBSURFACE_GENERIC_MODELS_LIB_SRCS
diveplotdatamodel.cpp diveplotdatamodel.cpp
diveimportedmodel.cpp diveimportedmodel.cpp
completionmodels.cpp completionmodels.cpp
divelocationmodel.cpp
) )
# models exclusively used in desktop builds # models exclusively used in desktop builds
@ -25,7 +26,6 @@ set(SUBSURFACE_DESKTOP_MODELS_LIB_SRCS
divetripmodel.cpp divetripmodel.cpp
diveplannermodel.cpp diveplannermodel.cpp
divecomputerextradatamodel.cpp divecomputerextradatamodel.cpp
divelocationmodel.cpp
ssrfsortfilterproxymodel.cpp ssrfsortfilterproxymodel.cpp
) )

View file

@ -128,9 +128,17 @@ void LocationInformationModel::update()
beginResetModel(); beginResetModel();
internalRowCount = dive_site_table.nr; internalRowCount = dive_site_table.nr;
qSort(dive_site_table.dive_sites, dive_site_table.dive_sites + dive_site_table.nr, dive_site_less_than); 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(); endResetModel();
} }
QStringList LocationInformationModel::allSiteNames() const
{
return(locationNames);
}
bool LocationInformationModel::setData(const QModelIndex &index, const QVariant &value, int role) bool LocationInformationModel::setData(const QModelIndex &index, const QVariant &value, int role)
{ {
if (!index.isValid() || index.row() < 2) if (!index.isValid() || index.row() < 2)

View file

@ -17,6 +17,7 @@ bool filter_same_gps_cb (QAbstractItemModel *m, int sourceRow, const QModelIndex
class LocationInformationModel : public QAbstractTableModel { class LocationInformationModel : public QAbstractTableModel {
Q_OBJECT Q_OBJECT
public: public:
LocationInformationModel(QObject *obj = 0);
enum Columns { UUID, NAME, LATITUDE, LONGITUDE, COORDS, DESCRIPTION, NOTES, TAXONOMY_1, TAXONOMY_2, TAXONOMY_3, COLUMNS}; enum Columns { UUID, NAME, LATITUDE, LONGITUDE, COORDS, DESCRIPTION, NOTES, TAXONOMY_1, TAXONOMY_2, TAXONOMY_3, COLUMNS};
enum Roles { UUID_ROLE = Qt::UserRole + 1 }; enum Roles { UUID_ROLE = Qt::UserRole + 1 };
static LocationInformationModel *instance(); static LocationInformationModel *instance();
@ -29,9 +30,10 @@ public:
public slots: public slots:
void update(); void update();
QStringList allSiteNames() const;
private: private:
LocationInformationModel(QObject *obj = 0);
int internalRowCount; int internalRowCount;
QStringList locationNames;
QLineEdit *textField; QLineEdit *textField;
}; };