mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
Adds Cylinder helper class for cylinder info access in grantlee templates
to allow grantlee to access individual fields of the cylinder_t struct rather than a string representation of the whole cylinder info using a grantlee structure like this one: <table class="table_class"> <tr> <td>Cylinder</td> <td>Start press.</td> <td>End press.</td> <td>Gas mix</td> </tr> {% for cylinderObject in dive.cylinderObjects %} <tr> <td>{{ cylinderObject.description }}</td> <td>{{ cylinderObject.startPressure }}</td> <td>{{ cylinderObject.endPressure }}</td> <td>{{ cylinderObject.gasMix }}</td> </tr> {% endfor %} </table> Signed-off-by: Tim Wootton <tim@tee-jay.org.uk> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
430f5b77c5
commit
bd40ef7f42
5 changed files with 86 additions and 0 deletions
|
@ -86,6 +86,7 @@ set(SUBSURFACE_CORE_LIB_SRCS
|
|||
|
||||
#Subsurface Qt have the Subsurface structs QObjectified for easy access via QML.
|
||||
subsurface-qt/DiveObjectHelper.cpp
|
||||
subsurface-qt/CylinderObjectHelper.cpp
|
||||
subsurface-qt/SettingsObjectWrapper.cpp
|
||||
${SERIAL_FTDI}
|
||||
${PLATFORM_SRC}
|
||||
|
|
37
core/subsurface-qt/CylinderObjectHelper.cpp
Normal file
37
core/subsurface-qt/CylinderObjectHelper.cpp
Normal file
|
@ -0,0 +1,37 @@
|
|||
#include "CylinderObjectHelper.h"
|
||||
#include "../helpers.h"
|
||||
|
||||
static QString EMPTY_CYLINDER_STRING = QStringLiteral("");
|
||||
CylinderObjectHelper::CylinderObjectHelper(cylinder_t *cylinder) :
|
||||
m_cyl(cylinder) {
|
||||
}
|
||||
|
||||
CylinderObjectHelper::~CylinderObjectHelper() {
|
||||
}
|
||||
|
||||
QString CylinderObjectHelper::description() const {
|
||||
if (!m_cyl->type.description)
|
||||
return QString(EMPTY_CYLINDER_STRING);
|
||||
else
|
||||
return QString(m_cyl->type.description);
|
||||
}
|
||||
|
||||
QString CylinderObjectHelper::size() const {
|
||||
return get_volume_string(m_cyl->type.size, true);
|
||||
}
|
||||
|
||||
QString CylinderObjectHelper::workingPressure() const {
|
||||
return get_pressure_string(m_cyl->type.workingpressure, true);
|
||||
}
|
||||
|
||||
QString CylinderObjectHelper::startPressure() const {
|
||||
return get_pressure_string(m_cyl->start, true);
|
||||
}
|
||||
|
||||
QString CylinderObjectHelper::endPressure() const {
|
||||
return get_pressure_string(m_cyl->end, true);
|
||||
}
|
||||
|
||||
QString CylinderObjectHelper::gasMix() const {
|
||||
return get_gas_string(m_cyl->gasmix);
|
||||
}
|
31
core/subsurface-qt/CylinderObjectHelper.h
Normal file
31
core/subsurface-qt/CylinderObjectHelper.h
Normal file
|
@ -0,0 +1,31 @@
|
|||
#ifndef CYLINDER_QOBJECT_H
|
||||
#define CYLINDER_QOBJECT_H
|
||||
|
||||
#include "../dive.h"
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
|
||||
class CylinderObjectHelper : public QObject {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString description READ description CONSTANT)
|
||||
Q_PROPERTY(QString size READ size CONSTANT)
|
||||
Q_PROPERTY(QString workingPressure READ workingPressure CONSTANT)
|
||||
Q_PROPERTY(QString startPressure READ startPressure CONSTANT)
|
||||
Q_PROPERTY(QString endPressure READ endPressure CONSTANT)
|
||||
Q_PROPERTY(QString gasMix READ gasMix CONSTANT)
|
||||
public:
|
||||
CylinderObjectHelper(cylinder_t *cylinder = NULL);
|
||||
~CylinderObjectHelper();
|
||||
QString description() const;
|
||||
QString size() const;
|
||||
QString workingPressure() const;
|
||||
QString startPressure() const;
|
||||
QString endPressure() const;
|
||||
QString gasMix() const;
|
||||
|
||||
private:
|
||||
cylinder_t *m_cyl;
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(CylinderObjectHelper *)
|
||||
#endif
|
|
@ -55,10 +55,18 @@ static QString getPressures(struct dive *dive, enum returnPressureSelector ret)
|
|||
DiveObjectHelper::DiveObjectHelper(struct dive *d) :
|
||||
m_dive(d)
|
||||
{
|
||||
m_cyls.clear();
|
||||
for (int i = 0; i < MAX_CYLINDERS; i++) {
|
||||
//Don't add blank cylinders, only those that have been defined.
|
||||
if (m_dive->cylinder[i].type.description)
|
||||
m_cyls.append(new CylinderObjectHelper(&m_dive->cylinder[i]));
|
||||
}
|
||||
}
|
||||
|
||||
DiveObjectHelper::~DiveObjectHelper()
|
||||
{
|
||||
while (!m_cyls.isEmpty())
|
||||
delete m_cyls.takeFirst();
|
||||
}
|
||||
|
||||
int DiveObjectHelper::number() const
|
||||
|
@ -275,6 +283,11 @@ QString DiveObjectHelper::cylinder(int idx) const
|
|||
return getFormattedCylinder(m_dive, idx);
|
||||
}
|
||||
|
||||
QList<CylinderObjectHelper*> DiveObjectHelper::cylinderObjects() const
|
||||
{
|
||||
return m_cyls;
|
||||
}
|
||||
|
||||
QString DiveObjectHelper::trip() const
|
||||
{
|
||||
return m_dive->divetrip ? m_dive->divetrip->location : EMPTY_DIVE_STRING;
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define DIVE_QOBJECT_H
|
||||
|
||||
#include "../dive.h"
|
||||
#include "CylinderObjectHelper.h"
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
|
@ -34,6 +35,7 @@ class DiveObjectHelper : public QObject {
|
|||
Q_PROPERTY(QString suit READ suit CONSTANT)
|
||||
Q_PROPERTY(QString cylinderList READ cylinderList CONSTANT)
|
||||
Q_PROPERTY(QStringList cylinders READ cylinders CONSTANT)
|
||||
Q_PROPERTY(QList<CylinderObjectHelper*> cylinderObjects READ cylinderObjects CONSTANT)
|
||||
Q_PROPERTY(QString trip READ trip CONSTANT)
|
||||
Q_PROPERTY(QString tripMeta READ tripMeta CONSTANT)
|
||||
Q_PROPERTY(int maxcns READ maxcns CONSTANT)
|
||||
|
@ -77,6 +79,7 @@ public:
|
|||
QString cylinderList() const;
|
||||
QStringList cylinders() const;
|
||||
QString cylinder(int idx) const;
|
||||
QList<CylinderObjectHelper*> cylinderObjects() const;
|
||||
QString trip() const;
|
||||
QString tripMeta() const;
|
||||
int maxcns() const;
|
||||
|
@ -92,6 +95,7 @@ public:
|
|||
|
||||
private:
|
||||
struct dive *m_dive;
|
||||
QList<CylinderObjectHelper*> m_cyls;
|
||||
};
|
||||
Q_DECLARE_METATYPE(DiveObjectHelper *)
|
||||
|
||||
|
|
Loading…
Reference in a new issue