mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Move helper function to DiveObjectsHelper
As per Tomaz recomendation the helper functions from19588ce
ande072596
are moved from qmlmanager to DiveObjectsHelper. [Dirk Hohndel: merged with the latest code] Signed-off-by: Joakim Bygdell <j.bygdell@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
4abe73ff2a
commit
9342dedb26
5 changed files with 34 additions and 42 deletions
|
@ -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 {
|
||||
|
@ -168,7 +166,7 @@ Item {
|
|||
}
|
||||
MobileComponents.Label {
|
||||
id: txtWeight
|
||||
text: weight
|
||||
text: dive.sumWeight
|
||||
Layout.fillWidth: true
|
||||
wrapMode: TextEdit.WrapAtWordBoundaryOrAnywhere
|
||||
}
|
||||
|
@ -180,7 +178,7 @@ Item {
|
|||
}
|
||||
MobileComponents.Label {
|
||||
id: txtCylinder
|
||||
text: cylinder
|
||||
text: dive.getCylinder
|
||||
Layout.fillWidth: true
|
||||
wrapMode: TextEdit.WrapAtWordBoundaryOrAnywhere
|
||||
}
|
||||
|
|
|
@ -708,39 +708,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), 'f', 1) + " lbs";
|
||||
}
|
||||
else {
|
||||
weights = QString::number(weight/1000, 'f', 1) + " kg";
|
||||
}
|
||||
}
|
||||
return weights;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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), 'f', 1) + " lbs";
|
||||
}
|
||||
else {
|
||||
sumWeight = QString::number(sum / 1000, 'f', 1) + " 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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue