summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Jan Mulder <jlmulder@xs4all.nl>2018-01-28 10:26:45 +0100
committerGravatar Jan Mulder <jlmulder@xs4all.nl>2018-01-31 14:48:14 +0100
commit572fc470718e4a11d5df60b37e7a2a91639285c7 (patch)
tree012052da9ce773463550741c33e33a00626c3434
parentfed2c5b6a1c71649bcb310c0bd118cb1abcf9ea0 (diff)
downloadsubsurface-572fc470718e4a11d5df60b37e7a2a91639285c7.tar.gz
mobile cleanup: unduplicate code and do not loop over dives (2)
See e6e1473e6. Exact same commit but here for the list of buddies. Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
-rw-r--r--core/subsurface-qt/DiveObjectHelper.cpp22
-rw-r--r--core/subsurface-qt/DiveObjectHelper.h2
-rw-r--r--mobile-widgets/qml/DiveDetails.qml3
-rw-r--r--mobile-widgets/qml/DiveDetailsEdit.qml3
-rw-r--r--mobile-widgets/qml/main.qml2
-rw-r--r--mobile-widgets/qmlmanager.cpp22
-rw-r--r--mobile-widgets/qmlmanager.h5
7 files changed, 9 insertions, 50 deletions
diff --git a/core/subsurface-qt/DiveObjectHelper.cpp b/core/subsurface-qt/DiveObjectHelper.cpp
index 4a7bc70f9..2e18b8f0a 100644
--- a/core/subsurface-qt/DiveObjectHelper.cpp
+++ b/core/subsurface-qt/DiveObjectHelper.cpp
@@ -429,28 +429,6 @@ QStringList DiveObjectHelper::locationList() const
return locations;
}
-QStringList DiveObjectHelper::buddyList() const
-{
- QStringList buddies;
- struct dive *d;
- int i = 0;
- for_each_dive (i, d) {
- QString temp = d->buddy;
- if (!temp.isEmpty() && !temp.contains(",")){
- buddies << d->buddy;
- }
- else if (!temp.isEmpty()){
- QRegExp sep("(,\\s)");
- QStringList tempList = temp.split(sep);
- buddies << tempList;
- buddies << tr("Multiple Buddies");
- }
- }
- buddies.removeDuplicates();
- buddies.sort();
- return buddies;
-}
-
QStringList DiveObjectHelper::divemasterList() const
{
QStringList divemasters;
diff --git a/core/subsurface-qt/DiveObjectHelper.h b/core/subsurface-qt/DiveObjectHelper.h
index a8ecc638c..28eaa6a41 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 buddyList READ buddyList CONSTANT)
Q_PROPERTY(QStringList divemasterList READ divemasterList CONSTANT)
Q_PROPERTY(QStringList locationList READ locationList CONSTANT)
public:
@@ -93,7 +92,6 @@ public:
QString endPressure() const;
QString firstGas() const;
QStringList locationList() const;
- QStringList buddyList() const;
QStringList divemasterList() const;
private:
diff --git a/mobile-widgets/qml/DiveDetails.qml b/mobile-widgets/qml/DiveDetails.qml
index a285e62e4..787c826db 100644
--- a/mobile-widgets/qml/DiveDetails.qml
+++ b/mobile-widgets/qml/DiveDetails.qml
@@ -18,7 +18,6 @@ Kirigami.Page {
property alias watertemp: detailsEdit.watertempText
property alias buddyIndex: detailsEdit.buddyIndex
property alias buddyText: detailsEdit.buddyText
- property alias buddyModel: detailsEdit.buddyModel
property alias divemasterIndex: detailsEdit.divemasterIndex
property alias divemasterText: detailsEdit.divemasterText
property alias divemasterModel: detailsEdit.divemasterModel
@@ -240,7 +239,7 @@ Kirigami.Page {
if (currentItem.modelData.dive.buddy.indexOf(",") > 0) {
buddyText = currentItem.modelData.dive.buddy;
} else {
- buddyIndex = currentItem.modelData.dive.buddyList.indexOf(currentItem.modelData.dive.buddy)
+ buddyIndex = manager.buddyList.indexOf(currentItem.modelData.dive.buddy)
}
divemasterIndex = currentItem.modelData.dive.divemasterList.indexOf(currentItem.modelData.dive.divemaster)
notes = currentItem.modelData.dive.notes
diff --git a/mobile-widgets/qml/DiveDetailsEdit.qml b/mobile-widgets/qml/DiveDetailsEdit.qml
index 5808f78a7..8373ba5b7 100644
--- a/mobile-widgets/qml/DiveDetailsEdit.qml
+++ b/mobile-widgets/qml/DiveDetailsEdit.qml
@@ -236,8 +236,7 @@ Item {
}
HintsTextEdit {
id: buddyBox
- model: diveDetailsListView.currentItem && diveDetailsListView.currentItem.modelData !== null ?
- diveDetailsListView.currentItem.modelData.dive.buddyList : null
+ model: manager.buddyList
inputMethodHints: Qt.ImhNoPredictiveText
Layout.fillWidth: true
}
diff --git a/mobile-widgets/qml/main.qml b/mobile-widgets/qml/main.qml
index 2df8d9f67..ad073a08b 100644
--- a/mobile-widgets/qml/main.qml
+++ b/mobile-widgets/qml/main.qml
@@ -81,7 +81,7 @@ Kirigami.ApplicationWindow {
detailsWindow.date = manager.getDate(detailsWindow.dive_id)
detailsWindow.airtemp = ""
detailsWindow.watertemp = ""
- detailsWindow.buddyModel = manager.buddyInit
+ detailsWindow.buddyModel = manager.buddyList
detailsWindow.buddyIndex = -1
detailsWindow.buddyText = ""
detailsWindow.depth = ""
diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp
index 4846dcdec..36f7768e5 100644
--- a/mobile-widgets/qmlmanager.cpp
+++ b/mobile-widgets/qmlmanager.cpp
@@ -273,7 +273,7 @@ void QMLManager::openLocalThenRemote(QString url)
appendTextToLog(QStringLiteral("have cloud credentials, trying to connect"));
tryRetrieveDataFromBackend();
}
- buddyModel.updateModel();
+ buddyModel.updateModel(); emit buddyListChanged();
suitModel.updateModel(); emit suitListChanged();
}
@@ -1556,25 +1556,9 @@ QStringList QMLManager::suitList() const
return suitModel.stringList();
}
-QStringList QMLManager::buddyInit() const
+QStringList QMLManager::buddyList() const
{
- QStringList buddies;
- struct dive *d;
- int i = 0;
- for_each_dive (i, d) {
- QString temp = d->buddy;
- if (!temp.isEmpty() && !temp.contains(",")){
- buddies << d->buddy;
- }
- else if (!temp.isEmpty()){
- QRegExp sep("(,\\s)");
- QStringList tempList = temp.split(sep);
- buddies << tempList;
- }
- }
- buddies.removeDuplicates();
- buddies.sort();
- return buddies;
+ return buddyModel.stringList();
}
QStringList QMLManager::divemasterInit() const
diff --git a/mobile-widgets/qmlmanager.h b/mobile-widgets/qmlmanager.h
index d0f1c09a2..c8c6a9906 100644
--- a/mobile-widgets/qmlmanager.h
+++ b/mobile-widgets/qmlmanager.h
@@ -37,7 +37,7 @@ class QMLManager : public QObject {
Q_PROPERTY(int updateSelectedDive MEMBER m_updateSelectedDive WRITE setUpdateSelectedDive NOTIFY updateSelectedDiveChanged)
Q_PROPERTY(int selectedDiveTimestamp MEMBER m_selectedDiveTimestamp WRITE setSelectedDiveTimestamp NOTIFY selectedDiveTimestampChanged)
Q_PROPERTY(QStringList suitList READ suitList NOTIFY suitListChanged)
- Q_PROPERTY(QStringList buddyInit READ buddyInit CONSTANT)
+ Q_PROPERTY(QStringList buddyList READ buddyList NOTIFY buddyListChanged)
Q_PROPERTY(QStringList divemasterInit READ divemasterInit CONSTANT)
Q_PROPERTY(QStringList cylinderInit READ cylinderInit CONSTANT)
Q_PROPERTY(bool showPin MEMBER m_showPin WRITE setShowPin NOTIFY showPinChanged)
@@ -132,7 +132,7 @@ public:
DiveListSortModel *dlSortModel;
QStringList suitList() const;
- QStringList buddyInit() const;
+ QStringList buddyList() const;
QStringList divemasterInit() const;
QStringList cylinderInit() const;
bool showPin() const;
@@ -271,6 +271,7 @@ signals:
void developerChanged();
void btEnabledChanged();
void suitListChanged();
+ void buddyListChanged();
};
#endif