Cleanup: turn CylinderObjectHelper into value type

CylinderObjectHelper is used for structured formatting of cylinder
values in grantlee types. Instead of keeping a reference to a
cylinder, turn it into a value type containing the formatted strings.

This should be distinctly safer, as we don't risk having stale
references flying around. Moreover, we don't have to use pointers
but can use containers containing plain CylinderObjectHelper. Thus,
no explicit memory management is needed, making the code distinctly
easier to understand.

Sadly, currently grantlee does not support Q_GADGET based Q_PROPERTY.
Therefore a GRANTLEE_*_LOOKUP block has to be added. This can be
removed in due course, as a patch to remedy this issue is in current
grantlee master.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2019-08-12 18:26:42 +02:00 committed by Dirk Hohndel
parent 0d045f8c14
commit f25fa2adc5
6 changed files with 54 additions and 63 deletions

View file

@ -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