From 2789bb05b133a7cf54081d58d4f5c51c8977e951 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Thu, 28 Jan 2021 14:24:38 +0100 Subject: profile: display arbitrary dive So far the profile operated on the global displayed_dive. Instead, take the dive to be displayed as a parameter to the plotDive() functions. This is necessary if we want to have multiple concurrent profile objects. Think for example for printing or for mobile where multiple dive objects are active at the same time. Signed-off-by: Berthold Stoeger --- desktop-widgets/divelogexportdialog.cpp | 4 ++-- desktop-widgets/diveplanner.cpp | 4 ++-- desktop-widgets/mainwindow.cpp | 12 ++++++------ desktop-widgets/printer.cpp | 4 ++-- desktop-widgets/tab-widgets/maintab.cpp | 5 ----- 5 files changed, 12 insertions(+), 17 deletions(-) (limited to 'desktop-widgets') diff --git a/desktop-widgets/divelogexportdialog.cpp b/desktop-widgets/divelogexportdialog.cpp index e9a4beb4e..30e389dde 100644 --- a/desktop-widgets/divelogexportdialog.cpp +++ b/desktop-widgets/divelogexportdialog.cpp @@ -229,7 +229,7 @@ void exportProfile(const struct dive *dive, const QString filename) profile->setPrintMode(true); double scale = profile->getFontPrintScale(); profile->setFontPrintScale(4 * scale); - profile->plotDive(dive, true, false, true); + profile->plotDive(dive, 0, true, false, true); QImage image = QImage(profile->size() * 4, QImage::Format_RGB32); QPainter paint; paint.begin(&image); @@ -238,5 +238,5 @@ void exportProfile(const struct dive *dive, const QString filename) profile->setToolTipVisibile(true); profile->setFontPrintScale(scale); profile->setPrintMode(false); - profile->plotDive(dive, true); + profile->plotDive(dive, 0, true); // TODO: Shouldn't this plot the current dive? } diff --git a/desktop-widgets/diveplanner.cpp b/desktop-widgets/diveplanner.cpp index 94912cab6..e237097c5 100644 --- a/desktop-widgets/diveplanner.cpp +++ b/desktop-widgets/diveplanner.cpp @@ -541,7 +541,7 @@ void PlannerWidgets::planDive() { DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::PLAN); - MainWindow::instance()->graphics->setPlanState(); + MainWindow::instance()->graphics->setPlanState(&displayed_dive, 0); dc_number = 0; // create a simple starting dive, using the first gas from the just copied cylinders @@ -569,7 +569,7 @@ void PlannerWidgets::replanDive() DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::PLAN); DivePlannerPointsModel::instance()->loadFromDive(&displayed_dive); - MainWindow::instance()->graphics->setPlanState(); + MainWindow::instance()->graphics->setPlanState(&displayed_dive, 0); plannerWidget.setReplanButton(true); plannerWidget.setupStartTime(timestampToDateTime(displayed_dive.when)); diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp index 425aaa30f..b6cae1e96 100644 --- a/desktop-widgets/mainwindow.cpp +++ b/desktop-widgets/mainwindow.cpp @@ -434,7 +434,7 @@ void MainWindow::selectionChanged() configureToolbar(); enableDisableOtherDCsActions(); } - graphics->plotDive(current_dive, false); + graphics->plotDive(current_dive, dc_number, false); MapWidget::instance()->selectionChanged(); } @@ -685,7 +685,7 @@ void MainWindow::enableShortcuts() void MainWindow::showProfile() { enableShortcuts(); - graphics->setProfileState(); + graphics->setProfileState(current_dive, dc_number); setApplicationState(ApplicationState::Default); } @@ -738,7 +738,7 @@ void MainWindow::refreshProfile() { showProfile(); configureToolbar(); - graphics->plotDive(current_dive, true); + graphics->plotDive(current_dive, dc_number, true); } void MainWindow::planCanceled() @@ -919,7 +919,7 @@ void MainWindow::on_actionPreviousDC_triggered() unsigned nrdc = number_of_computers(current_dive); dc_number = (dc_number + nrdc - 1) % nrdc; configureToolbar(); - graphics->plotDive(current_dive, false); + graphics->plotDive(current_dive, dc_number, false); mainTab->updateDiveInfo(); } @@ -928,7 +928,7 @@ void MainWindow::on_actionNextDC_triggered() unsigned nrdc = number_of_computers(current_dive); dc_number = (dc_number + 1) % nrdc; configureToolbar(); - graphics->plotDive(current_dive, false); + graphics->plotDive(current_dive, dc_number, false); mainTab->updateDiveInfo(); } @@ -1516,7 +1516,7 @@ void MainWindow::editCurrentDive() disableShortcuts(); copy_dive(current_dive, &displayed_dive); // Work on a copy of the dive DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::ADD); - graphics->setAddState(); + graphics->setAddState(&displayed_dive, 0); setApplicationState(ApplicationState::EditDive); DivePlannerPointsModel::instance()->loadFromDive(&displayed_dive); mainTab->enableEdition(); diff --git a/desktop-widgets/printer.cpp b/desktop-widgets/printer.cpp index 49135d79c..022db1a07 100644 --- a/desktop-widgets/printer.cpp +++ b/desktop-widgets/printer.cpp @@ -38,7 +38,7 @@ void Printer::putProfileImage(const QRect &profilePlaceholder, const QRect &view int y = profilePlaceholder.y() - viewPort.y(); // use the placeHolder and the viewPort position to calculate the relative position of the dive profile. QRect pos(x, y, profilePlaceholder.width(), profilePlaceholder.height()); - profile->plotDive(dive, true, true); + profile->plotDive(dive, 0, true, true); if (!printOptions.color_selected) { QImage image(pos.width(), pos.height(), QImage::Format_ARGB32); @@ -193,7 +193,7 @@ void Printer::render(int pages) qPrefDisplay::set_animation_speed(animationOriginal); //replot the dive after returning the settings - profile->plotDive(current_dive, true, true); + profile->plotDive(current_dive, dc_number, true, true); } //value: ranges from 0 : 100 and shows the progress of the templating engine diff --git a/desktop-widgets/tab-widgets/maintab.cpp b/desktop-widgets/tab-widgets/maintab.cpp index 0170cdb40..78784de46 100644 --- a/desktop-widgets/tab-widgets/maintab.cpp +++ b/desktop-widgets/tab-widgets/maintab.cpp @@ -541,11 +541,6 @@ void MainTab::rejectChanges() // no harm done to call cancelPlan even if we were not PLAN mode... DivePlannerPointsModel::instance()->cancelPlan(); - // now make sure that the correct dive is displayed - if (current_dive) - copy_dive(current_dive, &displayed_dive); - else - clear_dive(&displayed_dive); updateDiveInfo(); // show the profile and dive info -- cgit v1.2.3-70-g09d2