summaryrefslogtreecommitdiffstats
path: root/qt-models/diveplannermodel.cpp
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-04-13 14:46:15 +0200
committerGravatar Robert C. Helling <helling@atdotde.de>2020-05-04 10:42:07 +0200
commitf123972dbf661c051c37387249ab5fb6d83e24fa (patch)
treef528dd5875cdc96e4c4e01259d2666575d6b527e /qt-models/diveplannermodel.cpp
parent769915f3fe75bcef8029e82fdfed7ae206182390 (diff)
downloadsubsurface-f123972dbf661c051c37387249ab5fb6d83e24fa.tar.gz
planner: update variations in planner not mainwindow
When calculating variations, they were sent to the mainwindow, which updated displayed_dive accordingly. Do this directly in the planner-model. The idea is to detangle interdependencies and to make the code reusable (planner on mobile?). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'qt-models/diveplannermodel.cpp')
-rw-r--r--qt-models/diveplannermodel.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/qt-models/diveplannermodel.cpp b/qt-models/diveplannermodel.cpp
index 5132df45f..5d0375e69 100644
--- a/qt-models/diveplannermodel.cpp
+++ b/qt-models/diveplannermodel.cpp
@@ -423,6 +423,9 @@ DivePlannerPointsModel::DivePlannerPointsModel(QObject *parent) : QAbstractTable
{
memset(&diveplan, 0, sizeof(diveplan));
startTime.setTimeSpec(Qt::UTC);
+ // use a Qt-connection to send the variations text across thread boundary (in case we
+ // are calculating the variations in a background thread).
+ connect(this, &DivePlannerPointsModel::variationsComputed, this, &DivePlannerPointsModel::computeVariationsDone);
}
DivePlannerPointsModel *DivePlannerPointsModel::instance()
@@ -1147,6 +1150,7 @@ void DivePlannerPointsModel::computeVariations(struct diveplan *original_plan, c
FRACTION(analyzeVariations(shallower, original, deeper, qPrintable(depth_units)), 60), qPrintable(depth_units),
FRACTION(analyzeVariations(shorter, original, longer, qPrintable(time_units)), 60));
+ // By using a signal, we can transport the variations to the main thread.
emit variationsComputed(QString(buf));
#ifdef DEBUG_STOPVAR
printf("\n\n");
@@ -1161,6 +1165,14 @@ finish:
// setRecalc(oldRecalc);
}
+void DivePlannerPointsModel::computeVariationsDone(QString variations)
+{
+ QString notes = QString(displayed_dive.notes);
+ free(displayed_dive.notes);
+ displayed_dive.notes = copy_qstring(notes.replace("VARIATIONS", variations));
+ emit calculatedPlanNotes();
+}
+
void DivePlannerPointsModel::createPlan(bool replanCopy)
{
// Ok, so, here the diveplan creates a dive