diff options
-rw-r--r-- | desktop-widgets/mainwindow.cpp | 9 | ||||
-rw-r--r-- | desktop-widgets/mainwindow.h | 1 | ||||
-rw-r--r-- | qt-models/diveplannermodel.cpp | 12 | ||||
-rw-r--r-- | qt-models/diveplannermodel.h | 1 |
4 files changed, 13 insertions, 10 deletions
diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp index f3fee7ea5..1e893900b 100644 --- a/desktop-widgets/mainwindow.cpp +++ b/desktop-widgets/mainwindow.cpp @@ -206,7 +206,6 @@ MainWindow::MainWindow() : QMainWindow(), ui.menuFile->insertSeparator(ui.actionQuit); connect(DivePlannerPointsModel::instance(), SIGNAL(planCreated()), this, SLOT(planCreated())); connect(DivePlannerPointsModel::instance(), SIGNAL(planCanceled()), this, SLOT(planCanceled())); - connect(DivePlannerPointsModel::instance(), SIGNAL(variationsComputed(QString)), this, SLOT(updateVariations(QString))); connect(plannerDetails->printPlan(), SIGNAL(pressed()), divePlannerWidget, SLOT(printDecoPlan())); connect(this, &MainWindow::showError, ui.mainErrorMessage, &NotificationWidget::showError, Qt::AutoConnection); @@ -805,14 +804,6 @@ void MainWindow::setPlanNotes() plannerDetails->divePlanOutput()->setHtml(displayed_dive.notes); } -void MainWindow::updateVariations(QString variations) -{ - QString notes = QString(displayed_dive.notes); - free(displayed_dive.notes); - displayed_dive.notes = copy_qstring(notes.replace("VARIATIONS", variations)); - plannerDetails->divePlanOutput()->setHtml(displayed_dive.notes); -} - void MainWindow::printPlan() { #ifndef NO_PRINTING diff --git a/desktop-widgets/mainwindow.h b/desktop-widgets/mainwindow.h index ec09e7223..22cf1c828 100644 --- a/desktop-widgets/mainwindow.h +++ b/desktop-widgets/mainwindow.h @@ -170,7 +170,6 @@ slots: // should only be enabled when the profile's visible. void disableShortcuts(bool disablePaste = true); void enableShortcuts(); - void updateVariations(QString); void startDiveSiteEdit(); private: 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 diff --git a/qt-models/diveplannermodel.h b/qt-models/diveplannermodel.h index 7866591a6..24b153f0e 100644 --- a/qt-models/diveplannermodel.h +++ b/qt-models/diveplannermodel.h @@ -126,6 +126,7 @@ private: void createPlan(bool replanCopy); struct diveplan diveplan; struct divedatapoint *cloneDiveplan(struct diveplan *plan_src, struct diveplan *plan_copy); + void computeVariationsDone(QString text); void computeVariations(struct diveplan *diveplan, const struct deco_state *ds); void computeVariationsFreeDeco(struct diveplan *diveplan, struct deco_state *ds); int analyzeVariations(struct decostop *min, struct decostop *mid, struct decostop *max, const char *unit); |