mobile cleanup: unduplicate code and do not loop over dives (3)

See e6e1473e6. Exact same commit but here for the
list of divemaster. The careful reader will spot a
small addition to the clearDetailsEdit() QML function.
Two more field are cleared.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
This commit is contained in:
Jan Mulder 2018-01-28 11:28:01 +01:00
parent 572fc47071
commit 83259008e7
7 changed files with 12 additions and 35 deletions

View file

@ -428,18 +428,3 @@ QStringList DiveObjectHelper::locationList() const
locations.sort(); locations.sort();
return locations; return locations;
} }
QStringList DiveObjectHelper::divemasterList() const
{
QStringList divemasters;
struct dive *d;
int i = 0;
for_each_dive (i, d) {
QString temp = d->divemaster;
if (!temp.isEmpty())
divemasters << d->divemaster;
}
divemasters.removeDuplicates();
divemasters.sort();
return divemasters;
}

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 divemasterList READ divemasterList CONSTANT)
Q_PROPERTY(QStringList locationList READ locationList CONSTANT) Q_PROPERTY(QStringList locationList READ locationList CONSTANT)
public: public:
DiveObjectHelper(struct dive *dive = NULL); DiveObjectHelper(struct dive *dive = NULL);
@ -92,7 +91,6 @@ public:
QString endPressure() const; QString endPressure() const;
QString firstGas() const; QString firstGas() const;
QStringList locationList() const; QStringList locationList() const;
QStringList divemasterList() const;
private: private:
struct dive *m_dive; struct dive *m_dive;

View file

@ -241,7 +241,7 @@ Kirigami.Page {
} else { } else {
buddyIndex = manager.buddyList.indexOf(currentItem.modelData.dive.buddy) buddyIndex = manager.buddyList.indexOf(currentItem.modelData.dive.buddy)
} }
divemasterIndex = currentItem.modelData.dive.divemasterList.indexOf(currentItem.modelData.dive.divemaster) divemasterIndex = manager.divemasterList.indexOf(currentItem.modelData.dive.divemaster)
notes = currentItem.modelData.dive.notes notes = currentItem.modelData.dive.notes
if (currentItem.modelData.dive.singleWeight) { if (currentItem.modelData.dive.singleWeight) {
// we have only one weight, go ahead, have fun and edit it // we have only one weight, go ahead, have fun and edit it

View file

@ -48,6 +48,8 @@ Item {
detailsEdit.depthText = "" detailsEdit.depthText = ""
detailsEdit.airtempText = "" detailsEdit.airtempText = ""
detailsEdit.watertempText = "" detailsEdit.watertempText = ""
detailsEdit.divemasterText = ""
detailsEdit.buddyText = ""
suitBox.currentIndex = -1 suitBox.currentIndex = -1
buddyBox.currentIndex = -1 buddyBox.currentIndex = -1
divemasterBox.currentIndex = -1 divemasterBox.currentIndex = -1
@ -248,8 +250,7 @@ Item {
} }
HintsTextEdit { HintsTextEdit {
id: divemasterBox id: divemasterBox
model: diveDetailsListView.currentItem && diveDetailsListView.currentItem.modelData !== null ? model: manager.divemasterList
diveDetailsListView.currentItem.modelData.dive.divemasterList : null
inputMethodHints: Qt.ImhNoPredictiveText inputMethodHints: Qt.ImhNoPredictiveText
Layout.fillWidth: true Layout.fillWidth: true
} }

View file

@ -85,7 +85,7 @@ Kirigami.ApplicationWindow {
detailsWindow.buddyIndex = -1 detailsWindow.buddyIndex = -1
detailsWindow.buddyText = "" detailsWindow.buddyText = ""
detailsWindow.depth = "" detailsWindow.depth = ""
detailsWindow.divemasterModel = manager.divemasterInit detailsWindow.divemasterModel = manager.divemasterList
detailsWindow.divemasterIndex = -1 detailsWindow.divemasterIndex = -1
detailsWindow.divemasterText = "" detailsWindow.divemasterText = ""
detailsWindow.notes = "" detailsWindow.notes = ""

View file

@ -275,6 +275,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();
} }
void QMLManager::mergeLocalRepo() void QMLManager::mergeLocalRepo()
@ -1561,19 +1562,9 @@ QStringList QMLManager::buddyList() const
return buddyModel.stringList(); return buddyModel.stringList();
} }
QStringList QMLManager::divemasterInit() const QStringList QMLManager::divemasterList() const
{ {
QStringList divemasters; return divemasterModel.stringList();
struct dive *d;
int i = 0;
for_each_dive (i, d) {
QString temp = d->divemaster;
if (!temp.isEmpty())
divemasters << d->divemaster;
}
divemasters.removeDuplicates();
divemasters.sort();
return divemasters;
} }
QStringList QMLManager::cylinderInit() const QStringList QMLManager::cylinderInit() const

View file

@ -38,7 +38,7 @@ class QMLManager : public QObject {
Q_PROPERTY(int selectedDiveTimestamp MEMBER m_selectedDiveTimestamp WRITE setSelectedDiveTimestamp NOTIFY selectedDiveTimestampChanged) Q_PROPERTY(int selectedDiveTimestamp MEMBER m_selectedDiveTimestamp WRITE setSelectedDiveTimestamp NOTIFY selectedDiveTimestampChanged)
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 divemasterInit READ divemasterInit CONSTANT) Q_PROPERTY(QStringList divemasterList READ divemasterList NOTIFY divemasterListChanged)
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)
@ -133,7 +133,7 @@ public:
QStringList suitList() const; QStringList suitList() const;
QStringList buddyList() const; QStringList buddyList() const;
QStringList divemasterInit() const; QStringList divemasterList() const;
QStringList cylinderInit() const; QStringList cylinderInit() const;
bool showPin() const; bool showPin() const;
void setShowPin(bool enable); void setShowPin(bool enable);
@ -199,6 +199,7 @@ public slots:
private: private:
BuddyCompletionModel buddyModel; BuddyCompletionModel buddyModel;
SuitCompletionModel suitModel; SuitCompletionModel suitModel;
DiveMasterCompletionModel divemasterModel;
QString m_cloudUserName; QString m_cloudUserName;
QString m_cloudPassword; QString m_cloudPassword;
QString m_cloudPin; QString m_cloudPin;
@ -272,6 +273,7 @@ signals:
void btEnabledChanged(); void btEnabledChanged();
void suitListChanged(); void suitListChanged();
void buddyListChanged(); void buddyListChanged();
void divemasterListChanged();
}; };
#endif #endif