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 728e007c5c
commit fed2c5b6a1
8 changed files with 15 additions and 37 deletions

View file

@ -13,6 +13,7 @@
#include "core/gpslocation.h"
#include "core/downloadfromdcthread.h"
#include "qt-models/divelistmodel.h"
#include "qt-models/completionmodels.h"
class QMLManager : public QObject {
Q_OBJECT
@ -35,7 +36,7 @@ class QMLManager : public QObject {
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 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 divemasterInit READ divemasterInit CONSTANT)
Q_PROPERTY(QStringList cylinderInit READ cylinderInit CONSTANT)
@ -130,7 +131,7 @@ public:
DiveListSortModel *dlSortModel;
QStringList suitInit() const;
QStringList suitList() const;
QStringList buddyInit() const;
QStringList divemasterInit() const;
QStringList cylinderInit() const;
@ -196,6 +197,8 @@ public slots:
private:
BuddyCompletionModel buddyModel;
SuitCompletionModel suitModel;
QString m_cloudUserName;
QString m_cloudPassword;
QString m_cloudPin;
@ -267,6 +270,7 @@ signals:
void libdcLogChanged();
void developerChanged();
void btEnabledChanged();
void suitListChanged();
};
#endif