summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-08-15 00:03:15 +0200
committerGravatar bstoeger <32835590+bstoeger@users.noreply.github.com>2019-09-14 13:20:59 +0200
commit54720e6cff65ae860fb78431324b75203e71809a (patch)
tree1986f2fc328ef3f48ccdb70bf54ef0a3454ea81d
parent1b9581369af95bdf366f08c0d00d24c315d339bb (diff)
downloadsubsurface-54720e6cff65ae860fb78431324b75203e71809a.tar.gz
Mobile: move tripNrDive from DiveObjectHelper to DiveListModel
We don't want to generate a DiveObjectHelper numerous times for every item in the dive list. Therefore, return this datum directly from the model. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r--core/subsurface-qt/DiveObjectHelper.cpp6
-rw-r--r--core/subsurface-qt/DiveObjectHelper.h2
-rw-r--r--mobile-widgets/qml/DiveList.qml6
-rw-r--r--qt-models/divelistmodel.cpp2
-rw-r--r--qt-models/divelistmodel.h1
5 files changed, 6 insertions, 11 deletions
diff --git a/core/subsurface-qt/DiveObjectHelper.cpp b/core/subsurface-qt/DiveObjectHelper.cpp
index d4bcfc4e0..e4945f007 100644
--- a/core/subsurface-qt/DiveObjectHelper.cpp
+++ b/core/subsurface-qt/DiveObjectHelper.cpp
@@ -315,12 +315,6 @@ QVector<CylinderObjectHelper> DiveObjectHelper::cylinderObjects() const
return res;
}
-int DiveObjectHelper::tripNrDives() const
-{
- struct dive_trip *dt = m_dive->divetrip;
- return dt ? dt->dives.nr : 0;
-}
-
int DiveObjectHelper::maxcns() const
{
return m_dive->maxcns;
diff --git a/core/subsurface-qt/DiveObjectHelper.h b/core/subsurface-qt/DiveObjectHelper.h
index f08759389..397bc4d36 100644
--- a/core/subsurface-qt/DiveObjectHelper.h
+++ b/core/subsurface-qt/DiveObjectHelper.h
@@ -40,7 +40,6 @@ class DiveObjectHelper : public QObject {
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 tripNrDives READ tripNrDives CONSTANT)
Q_PROPERTY(int maxcns READ maxcns CONSTANT)
Q_PROPERTY(int otu READ otu CONSTANT)
Q_PROPERTY(QString sumWeight READ sumWeight CONSTANT)
@@ -82,7 +81,6 @@ public:
QStringList cylinders() const;
QString cylinder(int idx) const;
QVector<CylinderObjectHelper> cylinderObjects() const;
- int tripNrDives() const;
int maxcns() const;
int otu() const;
QString sumWeight() const;
diff --git a/mobile-widgets/qml/DiveList.qml b/mobile-widgets/qml/DiveList.qml
index 6be6d6d8f..b53a8c42b 100644
--- a/mobile-widgets/qml/DiveList.qml
+++ b/mobile-widgets/qml/DiveList.qml
@@ -40,7 +40,7 @@ Kirigami.ScrollablePage {
id: diveDelegate
Kirigami.AbstractListItem {
// this looks weird, but it's how we can tell that this dive isn't in a trip
- property bool diveOutsideTrip: dive.tripNrDives === 0
+ property bool diveOutsideTrip: tripNrDives === 0
leftPadding: 0
topPadding: 0
id: innerListItem
@@ -85,7 +85,7 @@ Kirigami.ScrollablePage {
}
NumberAnimation {
property: "height"
- duration: 200 + 20 * dive.tripNrDives
+ duration: 200 + 20 * tripNrDives
easing.type: Easing.InOutQuad
}
}
@@ -96,7 +96,7 @@ Kirigami.ScrollablePage {
SequentialAnimation {
NumberAnimation {
property: "height"
- duration: 200 + 20 * dive.tripNrDives
+ duration: 200 + 20 * tripNrDives
easing.type: Easing.InOutQuad
}
NumberAnimation {
diff --git a/qt-models/divelistmodel.cpp b/qt-models/divelistmodel.cpp
index caa31dcae..15934f9d6 100644
--- a/qt-models/divelistmodel.cpp
+++ b/qt-models/divelistmodel.cpp
@@ -245,6 +245,7 @@ QVariant DiveListModel::data(const QModelIndex &index, int role) const
case DiveRole: return QVariant::fromValue<QObject*>(curr_dive);
case DiveDateRole: return (qlonglong)curr_dive->timestamp();
case TripIdRole: return d->divetrip ? QString::number((quint64)d->divetrip, 16) : QString();
+ case TripNrDivesRole: return d->divetrip ? d->divetrip->dives.nr : 0;
}
return QVariant();
@@ -256,6 +257,7 @@ QHash<int, QByteArray> DiveListModel::roleNames() const
roles[DiveRole] = "dive";
roles[DiveDateRole] = "date";
roles[TripIdRole] = "tripId";
+ roles[TripNrDivesRole] = "tripNrDives";
return roles;
}
diff --git a/qt-models/divelistmodel.h b/qt-models/divelistmodel.h
index 1cc3abb7d..e799ecf8a 100644
--- a/qt-models/divelistmodel.h
+++ b/qt-models/divelistmodel.h
@@ -39,6 +39,7 @@ public:
DiveRole = Qt::UserRole + 1,
DiveDateRole,
TripIdRole,
+ TripNrDivesRole,
};
static DiveListModel *instance();