Mobile: transform DiveObjectHelper into value-type

Instead of handing a reference-to-dive to QML, prerender all the needed
properties and store them as values in DiveObjectHelper. Exception:
 - date(): generated from timestamp
 - time(): generated from timestamp
 - cylinderList(): does not depend on dive anyway and should be made
   static.

This hopefully avoids the random mobile crashes that we are seeing.
Clearly, this code needs to be optimized, but it is a start.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2019-08-13 22:48:18 +02:00 committed by bstoeger
parent 981c230706
commit 6a9df3bba3
4 changed files with 258 additions and 341 deletions

View file

@ -11,84 +11,81 @@
class DiveObjectHelper {
Q_GADGET
Q_PROPERTY(int number READ number CONSTANT)
Q_PROPERTY(int id READ id CONSTANT)
Q_PROPERTY(int rating READ rating CONSTANT)
Q_PROPERTY(int visibility READ visibility CONSTANT)
Q_PROPERTY(int number MEMBER number CONSTANT)
Q_PROPERTY(int id MEMBER id CONSTANT)
Q_PROPERTY(int rating MEMBER rating CONSTANT)
Q_PROPERTY(int visibility MEMBER visibility CONSTANT)
Q_PROPERTY(QString date READ date CONSTANT)
Q_PROPERTY(QString time READ time CONSTANT)
Q_PROPERTY(int timestamp READ timestamp CONSTANT)
Q_PROPERTY(QString location READ location CONSTANT)
Q_PROPERTY(QString gps READ gps CONSTANT)
Q_PROPERTY(QString gps_decimal READ gps_decimal CONSTANT)
Q_PROPERTY(QVariant dive_site READ dive_site CONSTANT)
Q_PROPERTY(QString duration READ duration CONSTANT)
Q_PROPERTY(bool noDive READ noDive CONSTANT)
Q_PROPERTY(QString depth READ depth CONSTANT)
Q_PROPERTY(QString divemaster READ divemaster CONSTANT)
Q_PROPERTY(QString buddy READ buddy CONSTANT)
Q_PROPERTY(QString airTemp READ airTemp CONSTANT)
Q_PROPERTY(QString waterTemp READ waterTemp CONSTANT)
Q_PROPERTY(QString notes READ notes CONSTANT)
Q_PROPERTY(QString tags READ tags CONSTANT)
Q_PROPERTY(QString gas READ gas CONSTANT)
Q_PROPERTY(QString sac READ sac CONSTANT)
Q_PROPERTY(QString weightList READ weightList CONSTANT)
Q_PROPERTY(QStringList weights READ weights CONSTANT)
Q_PROPERTY(bool singleWeight READ singleWeight CONSTANT)
Q_PROPERTY(QString suit READ suit CONSTANT)
Q_PROPERTY(int timestamp MEMBER timestamp CONSTANT)
Q_PROPERTY(QString location MEMBER location CONSTANT)
Q_PROPERTY(QString gps MEMBER gps CONSTANT)
Q_PROPERTY(QString gps_decimal MEMBER gps_decimal CONSTANT)
Q_PROPERTY(QVariant dive_site MEMBER dive_site CONSTANT)
Q_PROPERTY(QString duration MEMBER duration CONSTANT)
Q_PROPERTY(bool noDive MEMBER noDive CONSTANT)
Q_PROPERTY(QString depth MEMBER depth CONSTANT)
Q_PROPERTY(QString divemaster MEMBER divemaster CONSTANT)
Q_PROPERTY(QString buddy MEMBER buddy CONSTANT)
Q_PROPERTY(QString airTemp MEMBER airTemp CONSTANT)
Q_PROPERTY(QString waterTemp MEMBER waterTemp CONSTANT)
Q_PROPERTY(QString notes MEMBER notes CONSTANT)
Q_PROPERTY(QString tags MEMBER tags CONSTANT)
Q_PROPERTY(QString gas MEMBER gas CONSTANT)
Q_PROPERTY(QString sac MEMBER sac CONSTANT)
Q_PROPERTY(QString weightList MEMBER weightList CONSTANT)
Q_PROPERTY(QStringList weights MEMBER weights CONSTANT)
Q_PROPERTY(bool singleWeight MEMBER singleWeight CONSTANT)
Q_PROPERTY(QString suit MEMBER suit CONSTANT)
Q_PROPERTY(QStringList cylinderList READ cylinderList CONSTANT)
Q_PROPERTY(QStringList cylinders READ cylinders CONSTANT)
Q_PROPERTY(QVector<CylinderObjectHelper> cylinderObjects READ cylinderObjects CONSTANT)
Q_PROPERTY(int maxcns READ maxcns CONSTANT)
Q_PROPERTY(int otu READ otu CONSTANT)
Q_PROPERTY(QString sumWeight READ sumWeight CONSTANT)
Q_PROPERTY(QStringList getCylinder READ getCylinder CONSTANT)
Q_PROPERTY(QStringList startPressure READ startPressure CONSTANT)
Q_PROPERTY(QStringList endPressure READ endPressure CONSTANT)
Q_PROPERTY(QStringList firstGas READ firstGas CONSTANT)
Q_PROPERTY(QStringList cylinders MEMBER cylinders CONSTANT)
Q_PROPERTY(QVector<CylinderObjectHelper> cylinderObjects MEMBER cylinderObjects CONSTANT)
Q_PROPERTY(int maxcns MEMBER maxcns CONSTANT)
Q_PROPERTY(int otu MEMBER otu CONSTANT)
Q_PROPERTY(QString sumWeight MEMBER sumWeight CONSTANT)
Q_PROPERTY(QStringList getCylinder MEMBER getCylinder CONSTANT)
Q_PROPERTY(QStringList startPressure MEMBER startPressure CONSTANT)
Q_PROPERTY(QStringList endPressure MEMBER endPressure CONSTANT)
Q_PROPERTY(QStringList firstGas MEMBER firstGas CONSTANT)
public:
DiveObjectHelper(); // This is only to be used by Qt's metatype system!
DiveObjectHelper(struct dive *dive);
int number() const;
int id() const;
int rating() const;
int visibility() const;
DiveObjectHelper(const struct dive *dive);
int number;
int id;
int rating;
int visibility;
QString date() const;
timestamp_t timestamp() const;
timestamp_t timestamp;
QString time() const;
QString location() const;
QString gps() const;
QString gps_decimal() const;
QVariant dive_site() const;
QString duration() const;
bool noDive() const;
QString depth() const;
QString divemaster() const;
QString buddy() const;
QString airTemp() const;
QString waterTemp() const;
QString notes() const;
QString tags() const;
QString gas() const;
QString sac() const;
QString weightList() const;
QStringList weights() const;
bool singleWeight() const;
QString suit() const;
QString location;
QString gps;
QString gps_decimal;
QVariant dive_site;
QString duration;
bool noDive;
QString depth;
QString divemaster;
QString buddy;
QString airTemp;
QString waterTemp;
QString notes;
QString tags;
QString gas;
QString sac;
QString weightList;
QStringList weights;
bool singleWeight;
QString suit;
QStringList cylinderList() const;
QStringList cylinders() const;
QVector<CylinderObjectHelper> cylinderObjects() const;
int maxcns() const;
int otu() const;
QString sumWeight() const;
QStringList getCylinder() const;
QStringList startPressure() const;
QStringList endPressure() const;
QStringList firstGas() const;
private:
struct dive *m_dive;
QStringList cylinders;
QVector<CylinderObjectHelper> cylinderObjects;
int maxcns;
int otu;
QString sumWeight;
QStringList getCylinder;
QStringList startPressure;
QStringList endPressure;
QStringList firstGas;
};
Q_DECLARE_METATYPE(DiveObjectHelper)