UI restructure: plotDive: plot current dive by default & use displayed_dive

No longer use the dive structure that is passed in but instead always use
the displayed_dive to display things.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2014-07-02 20:00:57 -07:00
parent cd65c8512d
commit 2a55e55868
4 changed files with 27 additions and 24 deletions

View file

@ -175,7 +175,7 @@ void MainWindow::current_dive_changed(int divenr)
select_dive(divenr); select_dive(divenr);
ui.globe->centerOnCurrentDive(); ui.globe->centerOnCurrentDive();
} }
ui.newProfile->plotDive(current_dive); ui.newProfile->plotDive();
ui.InfoWidget->updateDiveInfo(divenr); ui.InfoWidget->updateDiveInfo(divenr);
} }
@ -650,7 +650,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;
ui.newProfile->plotDive(current_dive); ui.newProfile->plotDive();
ui.InfoWidget->updateDiveInfo(selected_dive); ui.InfoWidget->updateDiveInfo(selected_dive);
} }
@ -658,7 +658,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;
ui.newProfile->plotDive(current_dive); ui.newProfile->plotDive();
ui.InfoWidget->updateDiveInfo(selected_dive); ui.InfoWidget->updateDiveInfo(selected_dive);
} }

View file

@ -202,7 +202,7 @@ void PrintLayout::printProfileDives(int divesPerRow, int divesPerColumn)
profile->setFrameStyle(profileFrameStyle); profile->setFrameStyle(profileFrameStyle);
profile->setPrintMode(false); profile->setPrintMode(false);
profile->resize(originalSize); profile->resize(originalSize);
profile->plotDive(current_dive); profile->plotDive();
} }
/* we create a table that has a fixed height, but can stretch to fit certain width */ /* we create a table that has a fixed height, but can stretch to fit certain width */

View file

@ -255,7 +255,7 @@ void ProfileWidget2::replot()
{ {
int diveId = dataModel->id(); int diveId = dataModel->id();
dataModel->clear(); dataModel->clear();
plotDive(get_dive_by_uniq_id(diveId)); // why are we doing the get diveId here??? plotDive(); // simply plot the displayed_dive again
} }
void ProfileWidget2::setupItemSizes() void ProfileWidget2::setupItemSizes()
@ -360,11 +360,24 @@ void ProfileWidget2::plotDive(struct dive *d)
QTime measureDuration; // let's measure how long this takes us (maybe we'll turn of TTL calculation later QTime measureDuration; // let's measure how long this takes us (maybe we'll turn of TTL calculation later
measureDuration.start(); measureDuration.start();
// I Know that it's a list, but currently we are if (!d) {
// using just the first. if (selected_dive == -1)
if (!d) return;
d = current_dive; // display the current 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
// and the selected dive computer number against the ones we are
// showing (can't compare the dive pointers as those might change).
if (d->id == dataModel->id() && dc_number == dataModel->dcShown() && !forceReplot)
return; return;
forceReplot = false;
// this copies the dive and makes copies of all the relevant additional data
copy_dive(d, &displayed_dive);
//TODO: This is a temporary hack to help me understand the Planner. //TODO: This is a temporary hack to help me understand the Planner.
// It seems that each time the 'createTemporaryPlan' runs, a new // It seems that each time the 'createTemporaryPlan' runs, a new
// dive is created, and thus, we can plot that. hm... // dive is created, and thus, we can plot that. hm...
@ -378,6 +391,7 @@ void ProfileWidget2::plotDive(struct dive *d)
} }
//END //END
// special handling for the first time we display things
int animSpeedBackup = -1; int animSpeedBackup = -1;
if (firstCall && MainWindow::instance()->filesFromCommandLine()) { if (firstCall && MainWindow::instance()->filesFromCommandLine()) {
animSpeedBackup = prefs.animation; animSpeedBackup = prefs.animation;
@ -396,24 +410,13 @@ void ProfileWidget2::plotDive(struct dive *d)
toolTipItem->setVisible(!printMode); toolTipItem->setVisible(!printMode);
rulerItem->setVisible(prefs.rulergraph && !printMode); rulerItem->setVisible(prefs.rulergraph && !printMode);
// 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
// and the selected dive computer number against the ones we are
// showing (can't compare the dive pointers as those might change).
// I'm unclear what the semantics are supposed to be if we actually
// use more than one 'dives' as argument - so ignoring that right now :-)
if (d->id == dataModel->id() && dc_number == dataModel->dcShown() &&
!forceReplot)
return;
forceReplot = false;
if (currentState == EMPTY) if (currentState == EMPTY)
setProfileState(); setProfileState();
// next get the dive computer structure - if there are no samples // next get the dive computer structure - if there are no samples
// let's create a fake profile that's somewhat reasonable for the // let's create a fake profile that's somewhat reasonable for the
// data that we have // data that we have
struct divecomputer *currentdc = select_dc(d); struct divecomputer *currentdc = select_dc(&displayed_dive);
Q_ASSERT(currentdc); Q_ASSERT(currentdc);
if (!currentdc || !currentdc->samples) { if (!currentdc || !currentdc->samples) {
currentdc = fake_dc(currentdc); currentdc = fake_dc(currentdc);
@ -426,8 +429,8 @@ void ProfileWidget2::plotDive(struct dive *d)
* so I'll *not* calculate everything if something is not being * so I'll *not* calculate everything if something is not being
* shown. * shown.
*/ */
struct plot_info pInfo = calculate_max_limits_new(d, currentdc); struct plot_info pInfo = calculate_max_limits_new(&displayed_dive, currentdc);
create_plot_info_new(d, currentdc, &pInfo); create_plot_info_new(&displayed_dive, currentdc, &pInfo);
if(shouldCalculateMaxTime) if(shouldCalculateMaxTime)
maxtime = get_maxtime(&pInfo); maxtime = get_maxtime(&pInfo);
@ -444,7 +447,7 @@ void ProfileWidget2::plotDive(struct dive *d)
maxdepth = newMaxDepth; maxdepth = newMaxDepth;
} }
dataModel->setDive(d, pInfo); dataModel->setDive(&displayed_dive, pInfo);
toolTipItem->setPlotInfo(pInfo); toolTipItem->setPlotInfo(pInfo);
// It seems that I'll have a lot of boilerplate setting the model / axis for // It seems that I'll have a lot of boilerplate setting the model / axis for

View file

@ -67,7 +67,7 @@ public:
}; };
ProfileWidget2(QWidget *parent = 0); ProfileWidget2(QWidget *parent = 0);
void plotDive(struct dive *d); void plotDive(struct dive *d = 0);
virtual bool eventFilter(QObject *, QEvent *); virtual bool eventFilter(QObject *, QEvent *);
void setupItem(AbstractProfilePolygonItem *item, DiveCartesianAxis *hAxis, DiveCartesianAxis *vAxis, DivePlotDataModel *model, int vData, int hData, int zValue); void setupItem(AbstractProfilePolygonItem *item, DiveCartesianAxis *hAxis, DiveCartesianAxis *vAxis, DivePlotDataModel *model, int vData, int hData, int zValue);
void setPrintMode(bool mode, bool grayscale = false); void setPrintMode(bool mode, bool grayscale = false);