diff options
-rw-r--r-- | core/subsurface-qt/CylinderObjectHelper.cpp | 44 | ||||
-rw-r--r-- | core/subsurface-qt/CylinderObjectHelper.h | 35 | ||||
-rw-r--r-- | core/subsurface-qt/DiveObjectHelper.cpp | 11 | ||||
-rw-r--r-- | core/subsurface-qt/DiveObjectHelper.h | 8 | ||||
-rw-r--r-- | desktop-widgets/templatelayout.cpp | 2 | ||||
-rw-r--r-- | desktop-widgets/templatelayout.h | 19 |
6 files changed, 55 insertions, 64 deletions
diff --git a/core/subsurface-qt/CylinderObjectHelper.cpp b/core/subsurface-qt/CylinderObjectHelper.cpp index f2216af6f..f8386c402 100644 --- a/core/subsurface-qt/CylinderObjectHelper.cpp +++ b/core/subsurface-qt/CylinderObjectHelper.cpp @@ -3,36 +3,16 @@ #include "../qthelper.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); +CylinderObjectHelper::CylinderObjectHelper(cylinder_t *cylinder) +{ + if (!cylinder) + return; + + description = cylinder->type.description ? cylinder->type.description: + EMPTY_CYLINDER_STRING; + size = get_volume_string(cylinder->type.size, true); + workingPressure = get_pressure_string(cylinder->type.workingpressure, true); + startPressure = get_pressure_string(cylinder->start, true); + endPressure = get_pressure_string(cylinder->end, true); + gasMix = get_gas_string(cylinder->gasmix); } diff --git a/core/subsurface-qt/CylinderObjectHelper.h b/core/subsurface-qt/CylinderObjectHelper.h index 8453bac01..f7df7f746 100644 --- a/core/subsurface-qt/CylinderObjectHelper.h +++ b/core/subsurface-qt/CylinderObjectHelper.h @@ -6,27 +6,24 @@ #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) +class CylinderObjectHelper { + Q_GADGET + Q_PROPERTY(QString description MEMBER description CONSTANT) + Q_PROPERTY(QString size MEMBER size CONSTANT) + Q_PROPERTY(QString workingPressure MEMBER workingPressure CONSTANT) + Q_PROPERTY(QString startPressure MEMBER startPressure CONSTANT) + Q_PROPERTY(QString endPressure MEMBER endPressure CONSTANT) + Q_PROPERTY(QString gasMix MEMBER 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; + QString description; + QString size; + QString workingPressure; + QString startPressure; + QString endPressure; + QString gasMix; }; - Q_DECLARE_METATYPE(CylinderObjectHelper *) +Q_DECLARE_METATYPE(CylinderObjectHelper) + #endif diff --git a/core/subsurface-qt/DiveObjectHelper.cpp b/core/subsurface-qt/DiveObjectHelper.cpp index 6d625473e..ec4c8d65f 100644 --- a/core/subsurface-qt/DiveObjectHelper.cpp +++ b/core/subsurface-qt/DiveObjectHelper.cpp @@ -60,20 +60,13 @@ DiveObjectHelper::DiveObjectHelper(struct dive *d) : { if (!m_dive) qWarning("Creating DiveObjectHelper from NULL dive"); - 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])); + m_cyls.append(CylinderObjectHelper(&m_dive->cylinder[i])); } } -DiveObjectHelper::~DiveObjectHelper() -{ -while (!m_cyls.isEmpty()) - delete m_cyls.takeFirst(); -} - int DiveObjectHelper::number() const { return m_dive->number; @@ -316,7 +309,7 @@ QString DiveObjectHelper::cylinder(int idx) const return getFormattedCylinder(m_dive, idx); } -QList<CylinderObjectHelper*> DiveObjectHelper::cylinderObjects() const +QVector<CylinderObjectHelper> DiveObjectHelper::cylinderObjects() const { return m_cyls; } diff --git a/core/subsurface-qt/DiveObjectHelper.h b/core/subsurface-qt/DiveObjectHelper.h index 7e3073c00..a090811de 100644 --- a/core/subsurface-qt/DiveObjectHelper.h +++ b/core/subsurface-qt/DiveObjectHelper.h @@ -6,6 +6,7 @@ #include <QObject> #include <QString> #include <QStringList> +#include <QVector> #include <QVariant> class DiveObjectHelper : public QObject { @@ -38,7 +39,7 @@ class DiveObjectHelper : public QObject { Q_PROPERTY(QString suit READ suit CONSTANT) Q_PROPERTY(QStringList cylinderList READ cylinderList CONSTANT) Q_PROPERTY(QStringList cylinders READ cylinders CONSTANT) - Q_PROPERTY(QList<CylinderObjectHelper*> cylinderObjects READ cylinderObjects CONSTANT) + Q_PROPERTY(QVector<CylinderObjectHelper> cylinderObjects READ cylinderObjects CONSTANT) Q_PROPERTY(QString tripId READ tripId CONSTANT) Q_PROPERTY(int tripNrDives READ tripNrDives CONSTANT) Q_PROPERTY(int maxcns READ maxcns CONSTANT) @@ -52,7 +53,6 @@ class DiveObjectHelper : public QObject { Q_PROPERTY(QString fullTextNoNotes READ fullTextNoNotes CONSTANT) public: DiveObjectHelper(struct dive *dive); - ~DiveObjectHelper(); int number() const; int id() const; struct dive *getDive() const; @@ -84,7 +84,7 @@ public: QStringList cylinderList() const; QStringList cylinders() const; QString cylinder(int idx) const; - QList<CylinderObjectHelper*> cylinderObjects() const; + QVector<CylinderObjectHelper> cylinderObjects() const; QString tripId() const; int tripNrDives() const; int maxcns() const; @@ -99,7 +99,7 @@ public: private: struct dive *m_dive; - QList<CylinderObjectHelper*> m_cyls; + QVector<CylinderObjectHelper> m_cyls; }; Q_DECLARE_METATYPE(DiveObjectHelper *) diff --git a/desktop-widgets/templatelayout.cpp b/desktop-widgets/templatelayout.cpp index ce70dc44e..99deeef97 100644 --- a/desktop-widgets/templatelayout.cpp +++ b/desktop-widgets/templatelayout.cpp @@ -133,6 +133,7 @@ QString TemplateLayout::generate() Grantlee::Engine engine(this); Grantlee::registerMetaType<template_options>(); Grantlee::registerMetaType<print_options>(); + Grantlee::registerMetaType<CylinderObjectHelper>(); // TODO: Remove when grantlee supports Q_GADGET // Note: Currently, this should not be transformed into a QVector<> or std::vector<>, // as diveList contains pointers to elements in this list. But vectors might relocate @@ -196,6 +197,7 @@ QString TemplateLayout::generateStatistics() Grantlee::registerMetaType<YearInfo>(); Grantlee::registerMetaType<template_options>(); Grantlee::registerMetaType<print_options>(); + Grantlee::registerMetaType<CylinderObjectHelper>(); // TODO: Remove when grantlee supports Q_GADGET QVariantList years; diff --git a/desktop-widgets/templatelayout.h b/desktop-widgets/templatelayout.h index 49aa51613..10c5e96cc 100644 --- a/desktop-widgets/templatelayout.h +++ b/desktop-widgets/templatelayout.h @@ -9,6 +9,7 @@ #include "core/statistics.h" #include "core/qthelper.h" #include "core/subsurface-qt/DiveObjectHelper.h" +#include "core/subsurface-qt/CylinderObjectHelper.h" // TODO: remove once grantlee supports Q_GADGET objects int getTotalWork(print_options *printOptions); void find_all_templates(); @@ -120,4 +121,22 @@ if (property == "year") { } GRANTLEE_END_LOOKUP +// TODO: This is currently needed because our grantlee version +// doesn't support Q_GADGET based classes. A patch to fix this +// exists. Remove in due course. +GRANTLEE_BEGIN_LOOKUP(CylinderObjectHelper) +if (property == "description") { + return object.description; +} else if (property == "size") { + return object.size; +} else if (property == "workingPressure") { + return object.workingPressure; +} else if (property == "startPressure") { + return object.startPressure; +} else if (property == "endPressure") { + return object.endPressure; +} else if (property == "gasMix") { + return object.gasMix; +} +GRANTLEE_END_LOOKUP #endif |