profile: don't interpret NULL as current_dive in plotDive()

ProfileWidget2::plotDive() had this weird interface, where passing
in NULL as dive would mean "show current_dive". However, most callers
would already pass in current_dive. Therefore, unify and always pass
in current_dive if the caller wants to draw the current dive.

This allows us to interpret NULL as "show empty profile". Thus,
passing in current_dive when there is no current_dive simply shows
an empty profile. This makes the calling code in
MainWindow::selectionChanged() simpler.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2020-04-13 13:45:52 +02:00 committed by Dirk Hohndel
parent c1963fd5dd
commit 17556cc66c
4 changed files with 8 additions and 13 deletions

View file

@ -453,13 +453,12 @@ void MainWindow::selectionChanged()
if (!current_dive) { if (!current_dive) {
mainTab->clearTabs(); mainTab->clearTabs();
mainTab->updateDiveInfo(); mainTab->updateDiveInfo();
graphics->setEmptyState();
} else { } else {
graphics->plotDive(nullptr, false, true);
mainTab->updateDiveInfo(); mainTab->updateDiveInfo();
configureToolbar(); configureToolbar();
enableDisableOtherDCsActions(); enableDisableOtherDCsActions();
} }
graphics->plotDive(current_dive, false, true);
MapWidget::instance()->selectionChanged(); MapWidget::instance()->selectionChanged();
} }
@ -1112,7 +1111,7 @@ void MainWindow::on_actionPreviousDC_triggered()
unsigned nrdc = number_of_computers(current_dive); unsigned nrdc = number_of_computers(current_dive);
dc_number = (dc_number + nrdc - 1) % nrdc; dc_number = (dc_number + nrdc - 1) % nrdc;
configureToolbar(); configureToolbar();
graphics->plotDive(nullptr, false, true); graphics->plotDive(current_dive, false, true);
mainTab->updateDiveInfo(); mainTab->updateDiveInfo();
} }
@ -1121,7 +1120,7 @@ void MainWindow::on_actionNextDC_triggered()
unsigned nrdc = number_of_computers(current_dive); unsigned nrdc = number_of_computers(current_dive);
dc_number = (dc_number + 1) % nrdc; dc_number = (dc_number + 1) % nrdc;
configureToolbar(); configureToolbar();
graphics->plotDive(nullptr, false, true); graphics->plotDive(current_dive, false, true);
mainTab->updateDiveInfo(); mainTab->updateDiveInfo();
} }

View file

@ -185,7 +185,7 @@ void Printer::render(int Pages = 0)
qPrefDisplay::set_animation_speed(animationOriginal); qPrefDisplay::set_animation_speed(animationOriginal);
//replot the dive after returning the settings //replot the dive after returning the settings
profile->plotDive(0, true, true); profile->plotDive(current_dive, true, true);
} }
//value: ranges from 0 : 100 and shows the progress of the templating engine //value: ranges from 0 : 100 and shows the progress of the templating engine

View file

@ -381,8 +381,7 @@ void ProfileWidget2::setupItemOnScene()
void ProfileWidget2::replot() void ProfileWidget2::replot()
{ {
dataModel->clear(); plotDive(current_dive, true, false);
plotDive(nullptr, true, false);
} }
void ProfileWidget2::createPPGas(PartialPressureGasItem *item, int verticalColumn, color_index_t color, color_index_t colorAlert, void ProfileWidget2::createPPGas(PartialPressureGasItem *item, int verticalColumn, color_index_t color, color_index_t colorAlert,
@ -566,12 +565,9 @@ void ProfileWidget2::plotDive(const struct dive *d, bool force, bool doClearPict
#endif #endif
if (currentState != ADD && currentState != PLAN) { if (currentState != ADD && currentState != PLAN) {
if (!d) { if (!d) {
if (!current_dive) {
setEmptyState(); setEmptyState();
return; return;
} }
d = current_dive; // display the current dive
}
// No need to do this again if we are already showing the same dive // No need to do this again if we are already showing the same dive
// computer of the same dive, so we check the unique id of the dive // computer of the same dive, so we check the unique id of the dive

View file

@ -76,7 +76,7 @@ public:
~ProfileWidget2(); ~ProfileWidget2();
void resetZoom(); void resetZoom();
void scale(qreal sx, qreal sy); void scale(qreal sx, qreal sy);
void plotDive(const struct dive *d = 0, bool force = false, bool clearPictures = false, bool instant = false); void plotDive(const struct dive *d, bool force = false, bool clearPictures = false, bool instant = false);
void setupItem(AbstractProfilePolygonItem *item, DiveCartesianAxis *vAxis, int vData, int hData, int zValue); void setupItem(AbstractProfilePolygonItem *item, DiveCartesianAxis *vAxis, int vData, int hData, int zValue);
void setPrintMode(bool mode, bool grayscale = false); void setPrintMode(bool mode, bool grayscale = false);
bool getPrintMode(); bool getPrintMode();