[PATCH] Move helper function to DiveObjectsHelper
Tomaz Canabrava
tcanabrava at kde.org
Wed Jan 27 09:42:39 PST 2016
On Wed, Jan 27, 2016 at 3:34 PM, Joakim Bygdell <j.bygdell at gmail.com> wrote:
> As per Tomaz recomendation the helper functions from 19588ce and e072596
> are
> moved from qmlmanager to DiveObjectsHelper.
>
Thank you, much better. :)
we may need to other 'ObjectHelpers' for DiveTrip, Cylinder, Weight later.
>
> Signed-off-by: Joakim Bygdell <j.bygdell at gmail.com>
> ---
> qt-mobile/qml/DiveDetailsView.qml | 6 ++--
> qt-mobile/qmlmanager.cpp | 36
> ----------------------
> qt-mobile/qmlmanager.h | 2 --
> subsurface-core/subsurface-qt/DiveObjectHelper.cpp | 28 +++++++++++++++++
> subsurface-core/subsurface-qt/DiveObjectHelper.h | 4 +++
> 5 files changed, 34 insertions(+), 42 deletions(-)
>
> diff --git a/qt-mobile/qml/DiveDetailsView.qml
> b/qt-mobile/qml/DiveDetailsView.qml
> index df1d255..a47cea1 100644
> --- a/qt-mobile/qml/DiveDetailsView.qml
> +++ b/qt-mobile/qml/DiveDetailsView.qml
> @@ -12,8 +12,6 @@ import org.kde.plasma.mobilecomponents 0.2 as
> MobileComponents
> 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 +169,7 @@ Item {
> }
> MobileComponents.Label {
> id: txtWeight
> - text: weight
> + text: dive.sumWeight
> wrapMode: TextEdit.WrapAtWordBoundaryOrAnywhere
> Layout.alignment: Qt.AlignRight
> }
> @@ -183,7 +181,7 @@ Item {
> }
> MobileComponents.Label {
> id: txtCylinder
> - text: cylinder
> + text: dive.getCylinder
> Layout.fillWidth: true
> wrapMode: TextEdit.WordWrap
> }
> diff --git a/qt-mobile/qmlmanager.cpp b/qt-mobile/qmlmanager.cpp
> index 336774c..a26e183 100644
> --- a/qt-mobile/qmlmanager.cpp
> +++ b/qt-mobile/qmlmanager.cpp
> @@ -706,39 +706,3 @@ QString QMLManager::getDate(const QString& diveId)
> datestring = get_dive_date_string(d->when);
> return datestring;
> }
> -
> -QString QMLManager::getCylinder(const QString& diveId)
> -{
> - int dive_id = diveId.toInt();
> - struct dive *d = get_dive_by_uniq_id(dive_id);
> - QString cylinder;
> - if (d){
> - if (d->cylinder[1].type.description != NULL){
> - cylinder = "Multiple";
> - }
> - else {
> - cylinder = d->cylinder[0].type.description;
> - }
> - }
> - return cylinder;
> -}
> -
> -QString QMLManager::getWeights(const 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 b53af4d..eb225a6 100644
> --- a/qt-mobile/qmlmanager.h
> +++ b/qt-mobile/qmlmanager.h
> @@ -87,8 +87,6 @@ public slots:
> QString getNumber(const QString& diveId);
> QString getDate(const QString& diveId);
> QString getCurrentPosition();
> - QString getCylinder(const QString& diveId);
> - QString getWeights(const QString& diveId);
> void deleteGpsFix(quint64 when);
> void refreshDiveList();
>
> diff --git a/subsurface-core/subsurface-qt/DiveObjectHelper.cpp
> b/subsurface-core/subsurface-qt/DiveObjectHelper.cpp
> index e29bd38..3f05363 100644
> --- a/subsurface-core/subsurface-qt/DiveObjectHelper.cpp
> +++ b/subsurface-core/subsurface-qt/DiveObjectHelper.cpp
> @@ -243,3 +243,31 @@ int DiveObjectHelper::rating() const
> {
> return m_dive->rating;
> }
> +
> +QString DiveObjectHelper::sumWeight() const
> +{
> + int sum = 0;
> + QString sumWeight;
> + for (int i = 0; i < MAX_WEIGHTSYSTEMS; i++){
> + sum += m_dive->weightsystem[i].weight.grams;
> + }
> + if (informational_prefs.unit_system == IMPERIAL){
> + sumWeight = QString::number(grams_to_lbs(sum)) + " lbs";
> + }
> + else {
> + sumWeight = QString::number(sum/1000) + " kg";
> + }
> + return sumWeight;
> +}
> +
> +QString DiveObjectHelper::getCylinder() const
> +{
> + QString getCylinder;
> + if (m_dive->cylinder[1].type.description != NULL){
> + getCylinder = QObject::tr("Multiple");
> + }
> + else {
> + getCylinder = m_dive->cylinder[0].type.description;
> + }
> + return getCylinder;
> +}
> diff --git a/subsurface-core/subsurface-qt/DiveObjectHelper.h
> b/subsurface-core/subsurface-qt/DiveObjectHelper.h
> index 84c9346..f44971f 100644
> --- a/subsurface-core/subsurface-qt/DiveObjectHelper.h
> +++ b/subsurface-core/subsurface-qt/DiveObjectHelper.h
> @@ -32,6 +32,8 @@ class DiveObjectHelper : public QObject {
> Q_PROPERTY(QString tripMeta READ tripMeta CONSTANT)
> Q_PROPERTY(QString maxcns READ maxcns CONSTANT)
> Q_PROPERTY(QString otu READ otu CONSTANT)
> + Q_PROPERTY(QString sumWeight READ sumWeight CONSTANT)
> + Q_PROPERTY(QString getCylinder READ getCylinder CONSTANT)
> public:
> DiveObjectHelper(struct dive *dive = NULL);
> ~DiveObjectHelper();
> @@ -62,6 +64,8 @@ public:
> QString tripMeta() const;
> QString maxcns() const;
> QString otu() const;
> + QString sumWeight() const;
> + QString getCylinder() const;
>
> private:
> struct dive *m_dive;
> --
> 2.4.9 (Apple Git-60)
>
> _______________________________________________
> subsurface mailing list
> subsurface at subsurface-divelog.org
> http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.subsurface-divelog.org/pipermail/subsurface/attachments/20160127/c25fdf02/attachment-0001.html>
More information about the subsurface
mailing list