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

This is the first of a set of commits that are (very) similar.
It appeared that a number of more or less static lists, which are
constructed by a loop over all dives in the logbook, were executed
when changing focus to a next dive. For example, the in this
commit addressed list of used dive suits.

What was wrong was that the suitList was linked to a dive. There
is only a need to construct the list of used suits when data is
changed (and obviously, once on startup of the app). Further, it
appeared that a lot of code was duplicated and that we can use
(in this case) the same code from the desktop completionmodels.cpp.

Basically, this commit involves the following changes:
- include completionmodels.cpp in mobile and desktop (so move
it from the desktop only category to the generic category).
- remove double code from DiveObjectHelper.cpp
- Do not differentiate in the init phase and the normal refresh
of the list
- the per dive logic is now only the getting of a previously
constructed list (in init or update of the divelist).

There are no visible changes in the UI, other than a better
performance when scrolling over dive details.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
This commit is contained in:
Jan Mulder 2018-01-28 09:52:51 +01:00
parent 79ce3c02cb
commit e6e1473e6a
8 changed files with 15 additions and 37 deletions

View file

@ -411,21 +411,6 @@ QString DiveObjectHelper::firstGas() const
return gas; return gas;
} }
QStringList DiveObjectHelper::suitList() const
{
QStringList suits;
struct dive *d;
int i = 0;
for_each_dive (i, d) {
QString temp = d->suit;
if (!temp.isEmpty())
suits << d->suit;
}
suits.removeDuplicates();
suits.sort();
return suits;
}
QStringList DiveObjectHelper::locationList() const QStringList DiveObjectHelper::locationList() const
{ {
QStringList locations; QStringList 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 suitList READ suitList CONSTANT)
Q_PROPERTY(QStringList buddyList READ buddyList CONSTANT) Q_PROPERTY(QStringList buddyList READ buddyList CONSTANT)
Q_PROPERTY(QStringList divemasterList READ divemasterList CONSTANT) Q_PROPERTY(QStringList divemasterList READ divemasterList CONSTANT)
Q_PROPERTY(QStringList locationList READ locationList CONSTANT) Q_PROPERTY(QStringList locationList READ locationList CONSTANT)
@ -93,7 +92,6 @@ public:
QString startPressure() const; QString startPressure() const;
QString endPressure() const; QString endPressure() const;
QString firstGas() const; QString firstGas() const;
QStringList suitList() const;
QStringList locationList() const; QStringList locationList() const;
QStringList buddyList() const; QStringList buddyList() const;
QStringList divemasterList() const; QStringList divemasterList() const;

View file

@ -30,7 +30,6 @@ Kirigami.Page {
property alias notes: detailsEdit.notesText property alias notes: detailsEdit.notesText
property alias suitIndex: detailsEdit.suitIndex property alias suitIndex: detailsEdit.suitIndex
property alias suitText: detailsEdit.suitText property alias suitText: detailsEdit.suitText
property alias suitModel: detailsEdit.suitModel
property alias weight: detailsEdit.weightText property alias weight: detailsEdit.weightText
property alias startpressure: detailsEdit.startpressureText property alias startpressure: detailsEdit.startpressureText
property alias endpressure: detailsEdit.endpressureText property alias endpressure: detailsEdit.endpressureText
@ -237,7 +236,7 @@ Kirigami.Page {
depth = currentItem.modelData.dive.depth depth = currentItem.modelData.dive.depth
airtemp = currentItem.modelData.dive.airTemp airtemp = currentItem.modelData.dive.airTemp
watertemp = currentItem.modelData.dive.waterTemp watertemp = currentItem.modelData.dive.waterTemp
suitIndex = currentItem.modelData.dive.suitList.indexOf(currentItem.modelData.dive.suit) suitIndex = manager.suitList.indexOf(currentItem.modelData.dive.suit)
if (currentItem.modelData.dive.buddy.indexOf(",") > 0) { if (currentItem.modelData.dive.buddy.indexOf(",") > 0) {
buddyText = currentItem.modelData.dive.buddy; buddyText = currentItem.modelData.dive.buddy;
} else { } else {

View file

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

View file

@ -92,7 +92,7 @@ Kirigami.ApplicationWindow {
detailsWindow.location = "" detailsWindow.location = ""
detailsWindow.gps = "" detailsWindow.gps = ""
detailsWindow.duration = "" detailsWindow.duration = ""
detailsWindow.suitModel = manager.suitInit detailsWindow.suitModel = manager.suitList
detailsWindow.suitIndex = -1 detailsWindow.suitIndex = -1
detailsWindow.suitText = "" detailsWindow.suitText = ""
detailsWindow.cylinderModel = manager.cylinderInit detailsWindow.cylinderModel = manager.cylinderInit

View file

@ -17,6 +17,7 @@
#include "qt-models/divelistmodel.h" #include "qt-models/divelistmodel.h"
#include "qt-models/gpslistmodel.h" #include "qt-models/gpslistmodel.h"
#include "qt-models/completionmodels.h"
#include "core/divelist.h" #include "core/divelist.h"
#include "core/device.h" #include "core/device.h"
#include "core/pref.h" #include "core/pref.h"
@ -247,6 +248,8 @@ void QMLManager::openLocalThenRemote(QString url)
appendTextToLog(QStringLiteral("have cloud credentials, trying to connect")); appendTextToLog(QStringLiteral("have cloud credentials, trying to connect"));
tryRetrieveDataFromBackend(); tryRetrieveDataFromBackend();
} }
buddyModel.updateModel();
suitModel.updateModel(); emit suitListChanged();
} }
void QMLManager::mergeLocalRepo() void QMLManager::mergeLocalRepo()
@ -1534,19 +1537,9 @@ void QMLManager::quit()
QApplication::quit(); QApplication::quit();
} }
QStringList QMLManager::suitInit() const QStringList QMLManager::suitList() const
{ {
QStringList suits; return suitModel.stringList();
struct dive *d;
int i = 0;
for_each_dive (i, d) {
QString temp = d->suit;
if (!temp.isEmpty())
suits << d->suit;
}
suits.removeDuplicates();
suits.sort();
return suits;
} }
QStringList QMLManager::buddyInit() const QStringList QMLManager::buddyInit() const

View file

@ -13,6 +13,7 @@
#include "core/gpslocation.h" #include "core/gpslocation.h"
#include "core/downloadfromdcthread.h" #include "core/downloadfromdcthread.h"
#include "qt-models/divelistmodel.h" #include "qt-models/divelistmodel.h"
#include "qt-models/completionmodels.h"
class QMLManager : public QObject { class QMLManager : public QObject {
Q_OBJECT Q_OBJECT
@ -35,7 +36,7 @@ class QMLManager : public QObject {
Q_PROPERTY(bool syncToCloud MEMBER m_syncToCloud WRITE setSyncToCloud NOTIFY syncToCloudChanged) Q_PROPERTY(bool syncToCloud MEMBER m_syncToCloud WRITE setSyncToCloud NOTIFY syncToCloudChanged)
Q_PROPERTY(int updateSelectedDive MEMBER m_updateSelectedDive WRITE setUpdateSelectedDive NOTIFY updateSelectedDiveChanged) Q_PROPERTY(int updateSelectedDive MEMBER m_updateSelectedDive WRITE setUpdateSelectedDive NOTIFY updateSelectedDiveChanged)
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 suitInit READ suitInit CONSTANT) Q_PROPERTY(QStringList suitList READ suitList NOTIFY suitListChanged)
Q_PROPERTY(QStringList buddyInit READ buddyInit CONSTANT) Q_PROPERTY(QStringList buddyInit READ buddyInit CONSTANT)
Q_PROPERTY(QStringList divemasterInit READ divemasterInit CONSTANT) Q_PROPERTY(QStringList divemasterInit READ divemasterInit CONSTANT)
Q_PROPERTY(QStringList cylinderInit READ cylinderInit CONSTANT) Q_PROPERTY(QStringList cylinderInit READ cylinderInit CONSTANT)
@ -128,7 +129,7 @@ public:
DiveListSortModel *dlSortModel; DiveListSortModel *dlSortModel;
QStringList suitInit() const; QStringList suitList() const;
QStringList buddyInit() const; QStringList buddyInit() const;
QStringList divemasterInit() const; QStringList divemasterInit() const;
QStringList cylinderInit() const; QStringList cylinderInit() const;
@ -194,6 +195,8 @@ public slots:
private: private:
BuddyCompletionModel buddyModel;
SuitCompletionModel suitModel;
QString m_cloudUserName; QString m_cloudUserName;
QString m_cloudPassword; QString m_cloudPassword;
QString m_cloudPin; QString m_cloudPin;
@ -264,6 +267,7 @@ signals:
void libdcLogChanged(); void libdcLogChanged();
void developerChanged(); void developerChanged();
void btEnabledChanged(); void btEnabledChanged();
void suitListChanged();
}; };
#endif #endif

View file

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