[PATCH 3/3] QML UI: Add helper function to get weights
Joakim Bygdell
j.bygdell at gmail.com
Mon Jan 25 09:44:52 PST 2016
Helper function that retrieved the total weight for a dive to be displayed
on the DiveDetials page.
Signed-off-by: Joakim Bygdell <j.bygdell at gmail.com>
---
qt-mobile/qml/DiveDetailsView.qml | 2 +-
qt-mobile/qmlmanager.cpp | 20 ++++++++++++++++++++
qt-mobile/qmlmanager.h | 1 +
3 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/qt-mobile/qml/DiveDetailsView.qml b/qt-mobile/qml/DiveDetailsView.qml
index 6c33359..df1d255 100644
--- a/qt-mobile/qml/DiveDetailsView.qml
+++ b/qt-mobile/qml/DiveDetailsView.qml
@@ -13,6 +13,7 @@ Item {
id: detailsView
property int labelWidth: MobileComponents.Units.gridUnit * 10
property string cylinder: manager.getCylinder(dive.id)
+ property string weight: manager.getWeights(dive.id)
width: parent.width
height: mainLayout.implicitHeight + MobileComponents.Units.iconSizes.large
Rectangle {
@@ -171,7 +172,6 @@ Item {
MobileComponents.Label {
id: txtWeight
text: weight
- Layout.fillWidth: true
wrapMode: TextEdit.WrapAtWordBoundaryOrAnywhere
Layout.alignment: Qt.AlignRight
}
diff --git a/qt-mobile/qmlmanager.cpp b/qt-mobile/qmlmanager.cpp
index d2b5c47..a4cfd5f 100644
--- a/qt-mobile/qmlmanager.cpp
+++ b/qt-mobile/qmlmanager.cpp
@@ -718,3 +718,23 @@ QString QMLManager::getCylinder(QString diveId)
cylinder = d->cylinder[0].type.description;
return cylinder;
}
+
+QString QMLManager::getWeights(QString diveId)
+{
+ int dive_id = diveId.toInt();
+ struct dive *d = get_dive_by_uniq_id(dive_id);
+ int weight = 0;
+ QString weights;
+ if (d){
+ for (int i = 0; i < MAX_WEIGHTSYSTEMS; i++)
+ weight += d->weightsystem[i].weight.grams;
+
+ if (informational_prefs.unit_system == IMPERIAL){
+ weights = QString::number(grams_to_lbs(weight)) + " lbs";
+ }
+ else {
+ weights = QString::number(weight/1000) + " kg";
+ }
+ }
+ return weights;
+}
diff --git a/qt-mobile/qmlmanager.h b/qt-mobile/qmlmanager.h
index 57b67c2..bcaf9c7 100644
--- a/qt-mobile/qmlmanager.h
+++ b/qt-mobile/qmlmanager.h
@@ -85,6 +85,7 @@ public slots:
QString getDate(QString diveId);
QString getCurrentPosition();
QString getCylinder(QString diveId);
+ QString getWeights(QString diveId);
void deleteGpsFix(quint64 when);
void refreshDiveList();
--
2.4.9 (Apple Git-60)
More information about the subsurface
mailing list