summaryrefslogtreecommitdiffstats
path: root/qt-models/diveplannermodel.cpp
diff options
context:
space:
mode:
authorGravatar Robert C. Helling <helling@atdotde.de>2017-08-29 11:41:30 +0200
committerGravatar Robert C. Helling <helling@atdotde.de>2017-11-25 20:13:01 +0100
commita9ceecc2e3646432d6688d04b592c48f9c63ae65 (patch)
treeb568677f20ab7be870f5e0ada75fc6e5cb11fe51 /qt-models/diveplannermodel.cpp
parentbe6b50fce403ab6fd7d9b99167f57e4aa31d2a77 (diff)
downloadsubsurface-a9ceecc2e3646432d6688d04b592c48f9c63ae65.tar.gz
Run variations calculation in background
but there are still side effects and thus it crashes. Signed-off-by: Robert C. Helling <helling@atdotde.de>
Diffstat (limited to 'qt-models/diveplannermodel.cpp')
-rw-r--r--qt-models/diveplannermodel.cpp14
1 files changed, 13 insertions, 1 deletions
diff --git a/qt-models/diveplannermodel.cpp b/qt-models/diveplannermodel.cpp
index 127ea8649..acf2d9c6f 100644
--- a/qt-models/diveplannermodel.cpp
+++ b/qt-models/diveplannermodel.cpp
@@ -9,6 +9,7 @@
#include "core/subsurface-qt/SettingsObjectWrapper.h"
#include <QApplication>
#include <QTextDocument>
+#include <QtConcurrent>
#define UNIT_FACTOR ((prefs.units.length == units::METERS) ? 1000.0 / 60.0 : feet_to_mm(1.0) / 60.0)
@@ -920,7 +921,7 @@ void DivePlannerPointsModel::createTemporaryPlan()
if (recalcQ() && !diveplan_empty(&diveplan)) {
struct decostop stoptable[60];
plan(&diveplan, &displayed_dive, DECOTIMESTEP, stoptable, &cache, isPlanner(), false);
- computeVariations();
+ QtConcurrent::run(this, &DivePlannerPointsModel::computeVariations);
emit calculatedPlanNotes();
}
// throw away the cache
@@ -1013,8 +1014,11 @@ void DivePlannerPointsModel::computeVariations()
struct divedatapoint *last_segment;
if(in_planner() && prefs.display_variations) {
+ int my_instance = ++instanceCounter;
cache_deco_state(&save);
cloneDiveplan(&plan_copy);
+ if (my_instance != instanceCounter)
+ return;
plan(&plan_copy, dive, 1, original, &cache, true, false);
free_dps(&plan_copy);
restore_deco_state(save, false);
@@ -1022,6 +1026,8 @@ void DivePlannerPointsModel::computeVariations()
last_segment = cloneDiveplan(&plan_copy);
last_segment->depth.mm += 1000;
last_segment->next->depth.mm += 1000;
+ if (my_instance != instanceCounter)
+ return;
plan(&plan_copy, dive, 1, deeper, &cache, true, false);
free_dps(&plan_copy);
restore_deco_state(save, false);
@@ -1029,18 +1035,24 @@ void DivePlannerPointsModel::computeVariations()
last_segment = cloneDiveplan(&plan_copy);
last_segment->depth.mm -= 1000;
last_segment->next->depth.mm -= 1000;
+ if (my_instance != instanceCounter)
+ return;
plan(&plan_copy, dive, 1, shallower, &cache, true, false);
free_dps(&plan_copy);
restore_deco_state(save, false);
last_segment = cloneDiveplan(&plan_copy);
last_segment->next->time += 60;
+ if (my_instance != instanceCounter)
+ return;
plan(&plan_copy, dive, 1, longer, &cache, true, false);
free_dps(&plan_copy);
restore_deco_state(save, false);
last_segment = cloneDiveplan(&plan_copy);
last_segment->next->time -= 60;
+ if (my_instance != instanceCounter)
+ return;
plan(&plan_copy, dive, 1, shorter, &cache, true, false);
free_dps(&plan_copy);
restore_deco_state(save, false);