summaryrefslogtreecommitdiffstats
path: root/desktop-widgets/templatelayout.cpp
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-08-13 07:28:24 +0200
committerGravatar bstoeger <32835590+bstoeger@users.noreply.github.com>2019-09-14 13:20:59 +0200
commitbe763452adc110cfcc011322d989698d897dd6ed (patch)
treeb4185f9d99a237621caa262a44340a9300396e7b /desktop-widgets/templatelayout.cpp
parenta79c45e4010a18f8ffe0742ab844743eeeebab9e (diff)
downloadsubsurface-be763452adc110cfcc011322d989698d897dd6ed.tar.gz
DiveObjectHelper: Turn DiveObjectHelper into Q_GADGET based object
DiveObjectHelper is a tiny wrapper around dive * to allow access to dive data from QML and grantlee. It doesn't have to be a full-fledged QObject with support for signals, etc. Therefore, turn it into a Q_GADGET based object. This allows us passing the object around as object, not as pointer to DiveObjectHelper. This makes memory-management distinctly easier. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets/templatelayout.cpp')
-rw-r--r--desktop-widgets/templatelayout.cpp14
1 files changed, 4 insertions, 10 deletions
diff --git a/desktop-widgets/templatelayout.cpp b/desktop-widgets/templatelayout.cpp
index 99deeef97..bdcdfbbe9 100644
--- a/desktop-widgets/templatelayout.cpp
+++ b/desktop-widgets/templatelayout.cpp
@@ -134,19 +134,13 @@ QString TemplateLayout::generate()
Grantlee::registerMetaType<template_options>();
Grantlee::registerMetaType<print_options>();
Grantlee::registerMetaType<CylinderObjectHelper>(); // TODO: Remove when grantlee supports Q_GADGET
+ Grantlee::registerMetaType<DiveObjectHelper>(); // 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
- // and thus invalidate the pointers! std::list<> is used here, because the new elements
- // can be directly constructed in the list with the emplace_back() call.
- // Ultimately, the memory management should be fixed.
- std::list<DiveObjectHelper> diveObjectList;
QVariantList diveList;
struct dive *dive;
if (in_planner()) {
- diveObjectList.emplace_back(&displayed_dive);
- diveList.append(QVariant::fromValue(&diveObjectList.back()));
+ diveList.append(QVariant::fromValue(DiveObjectHelper(&displayed_dive)));
emit progressUpdated(100.0);
} else {
int i;
@@ -154,8 +148,7 @@ QString TemplateLayout::generate()
//TODO check for exporting selected dives only
if (!dive->selected && printOptions->print_selected)
continue;
- diveObjectList.emplace_back(dive);
- diveList.append(QVariant::fromValue(&diveObjectList.back()));
+ diveList.append(QVariant::fromValue(DiveObjectHelper(dive)));
progress++;
emit progressUpdated(lrint(progress * 100.0 / totalWork));
}
@@ -198,6 +191,7 @@ QString TemplateLayout::generateStatistics()
Grantlee::registerMetaType<template_options>();
Grantlee::registerMetaType<print_options>();
Grantlee::registerMetaType<CylinderObjectHelper>(); // TODO: Remove when grantlee supports Q_GADGET
+ Grantlee::registerMetaType<DiveObjectHelper>(); // TODO: Remove when grantlee supports Q_GADGET
QVariantList years;