UI restructure: don't use random dives from the divelist for data

Everything should come from the displayed_dive.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2014-07-03 14:34:24 -07:00
parent 117b212cdd
commit d8c3113584
4 changed files with 28 additions and 40 deletions

View file

@ -146,11 +146,6 @@ void DivePlotDataModel::setDive(dive *d, const plot_info &info)
endInsertRows(); endInsertRows();
} }
int DivePlotDataModel::id() const
{
return diveId;
}
unsigned int DivePlotDataModel::dcShown() const unsigned int DivePlotDataModel::dcShown() const
{ {
return dcNr; return dcNr;
@ -178,9 +173,8 @@ void DivePlotDataModel::emitDataChanged()
void DivePlotDataModel::calculateDecompression() void DivePlotDataModel::calculateDecompression()
{ {
struct dive *d = get_dive_by_uniq_id(id()); struct divecomputer *dc = select_dc(&displayed_dive);
struct divecomputer *dc = select_dc(d); init_decompression(&displayed_dive);
init_decompression(d); calculate_deco_information(&displayed_dive, dc, &pInfo, false);
calculate_deco_information(d, dc, &pInfo, false);
dataChanged(index(0, CEILING), index(pInfo.nr - 1, TISSUE_16)); dataChanged(index(0, CEILING), index(pInfo.nr - 1, TISSUE_16));
} }

View file

@ -54,7 +54,6 @@ public:
void clear(); void clear();
void setDive(struct dive *d, const plot_info &pInfo); void setDive(struct dive *d, const plot_info &pInfo);
const plot_info &data() const; const plot_info &data() const;
int id() const;
unsigned int dcShown() const; unsigned int dcShown() const;
double pheMax(); double pheMax();
double pn2Max(); double pn2Max();

View file

@ -450,7 +450,6 @@ void DiveGasPressureItem::modelDataChanged(const QModelIndex &topLeft, const QMo
int last_pressure[MAX_CYLINDERS] = { 0, }; int last_pressure[MAX_CYLINDERS] = { 0, };
int last_time[MAX_CYLINDERS] = { 0, }; int last_time[MAX_CYLINDERS] = { 0, };
struct plot_data *entry; struct plot_data *entry;
struct dive *dive = get_dive_by_uniq_id(dataModel->id());
cyl = -1; cyl = -1;
for (int i = 0, count = dataModel->rowCount(); i < count; i++) { for (int i = 0, count = dataModel->rowCount(); i < count; i++) {
@ -464,7 +463,7 @@ void DiveGasPressureItem::modelDataChanged(const QModelIndex &topLeft, const QMo
if (!seen_cyl[cyl]) { if (!seen_cyl[cyl]) {
plotPressureValue(mbar, entry->sec, Qt::AlignRight | Qt::AlignTop); plotPressureValue(mbar, entry->sec, Qt::AlignRight | Qt::AlignTop);
plotGasValue(mbar, entry->sec, Qt::AlignRight | Qt::AlignBottom, plotGasValue(mbar, entry->sec, Qt::AlignRight | Qt::AlignBottom,
dive->cylinder[cyl].gasmix); displayed_dive.cylinder[cyl].gasmix);
seen_cyl[cyl] = true; seen_cyl[cyl] = true;
} }
} }
@ -509,11 +508,10 @@ void DiveGasPressureItem::paint(QPainter *painter, const QStyleOptionGraphicsIte
QPen pen; QPen pen;
pen.setCosmetic(true); pen.setCosmetic(true);
pen.setWidth(2); pen.setWidth(2);
struct dive *d = get_dive_by_uniq_id(dataModel->id());
struct plot_data *entry = dataModel->data().entry; struct plot_data *entry = dataModel->data().entry;
Q_FOREACH (const QPolygonF &poly, polygons) { Q_FOREACH (const QPolygonF &poly, polygons) {
for (int i = 1, count = poly.count(); i < count; i++, entry++) { for (int i = 1, count = poly.count(); i < count; i++, entry++) {
pen.setBrush(getSacColor(entry->sac, d->sac)); pen.setBrush(getSacColor(entry->sac, displayed_dive.sac));
painter->setPen(pen); painter->setPen(pen);
painter->drawLine(poly[i - 1], poly[i]); painter->drawLine(poly[i - 1], poly[i]);
} }

View file

@ -253,7 +253,6 @@ void ProfileWidget2::setupItemOnScene()
void ProfileWidget2::replot() void ProfileWidget2::replot()
{ {
int diveId = dataModel->id();
dataModel->clear(); dataModel->clear();
plotDive(); // simply plot the displayed_dive again plotDive(); // simply plot the displayed_dive again
} }
@ -360,6 +359,7 @@ 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();
if (currentState != ADD && currentState != PLAN) {
if (!d) { if (!d) {
if (selected_dive == -1) if (selected_dive == -1)
return; return;
@ -370,18 +370,14 @@ void ProfileWidget2::plotDive(struct dive *d)
// 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
// and the selected dive computer number against the ones we are // and the selected dive computer number against the ones we are
// showing (can't compare the dive pointers as those might change). // showing (can't compare the dive pointers as those might change).
if (d->id == dataModel->id() && dc_number == dataModel->dcShown() && !forceReplot) if (d->id == displayed_dive.id && dc_number == dataModel->dcShown() && !forceReplot)
return; return;
forceReplot = false; forceReplot = false;
// this copies the dive and makes copies of all the relevant additional data // this copies the dive and makes copies of all the relevant additional data
copy_dive(d, &displayed_dive); copy_dive(d, &displayed_dive);
} else {
//TODO: This is a temporary hack to help me understand the Planner.
// It seems that each time the 'createTemporaryPlan' runs, a new
// dive is created, and thus, we can plot that. hm...
if (currentState == ADD || currentState == PLAN) {
DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance(); DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance();
plannerModel->createTemporaryPlan(); plannerModel->createTemporaryPlan();
if (!plannerModel->getDiveplan().dp) { if (!plannerModel->getDiveplan().dp) {
@ -497,7 +493,7 @@ void ProfileWidget2::plotDive(struct dive *d)
else else
meanDepth->setVisible(false); meanDepth->setVisible(false);
meanDepth->setMeanDepth(pInfo.meandepth); meanDepth->setMeanDepth(pInfo.meandepth);
meanDepth->setLine(0, 0, timeAxis->posAtValue(d->duration.seconds), 0); meanDepth->setLine(0, 0, timeAxis->posAtValue(displayed_dive.duration.seconds), 0);
meanDepth->animateMoveTo(3, profileYAxis->posAtValue(pInfo.meandepth)); meanDepth->animateMoveTo(3, profileYAxis->posAtValue(pInfo.meandepth));
dataModel->emitDataChanged(); dataModel->emitDataChanged();
@ -524,7 +520,7 @@ void ProfileWidget2::plotDive(struct dive *d)
} }
QString dcText = get_dc_nickname(currentdc->model, currentdc->deviceid); QString dcText = get_dc_nickname(currentdc->model, currentdc->deviceid);
int nr; int nr;
if ((nr = number_of_computers(current_dive)) > 1) if ((nr = number_of_computers(&displayed_dive)) > 1)
dcText += tr(" (#%1 of %2)").arg(dc_number + 1).arg(nr); dcText += tr(" (#%1 of %2)").arg(dc_number + 1).arg(nr);
diveComputerText->setText(dcText); diveComputerText->setText(dcText);
if (MainWindow::instance()->filesFromCommandLine() && animSpeedBackup != -1) { if (MainWindow::instance()->filesFromCommandLine() && animSpeedBackup != -1) {
@ -1046,15 +1042,16 @@ void ProfileWidget2::changeGas()
QString gas = action->text(); QString gas = action->text();
// backup the things on the dataModel, since we will clear that out. // backup the things on the dataModel, since we will clear that out.
unsigned int diveComputer = dataModel->dcShown(); unsigned int diveComputer = dataModel->dcShown();
int diveId = dataModel->id();
struct gasmix gasmix; struct gasmix gasmix;
int seconds = timeAxis->valueAt(scenePos); int seconds = timeAxis->valueAt(scenePos);
struct dive *d = get_dive_by_uniq_id(diveId);
validate_gas(gas.toUtf8().constData(), &gasmix); validate_gas(gas.toUtf8().constData(), &gasmix);
add_gas_switch_event(d, get_dive_dc(d, diveComputer), seconds, get_gasidx(d, &gasmix)); add_gas_switch_event(&displayed_dive, get_dive_dc(&displayed_dive, diveComputer), seconds, get_gasidx(&displayed_dive, &gasmix));
// this means we potentially have a new tank that is being used and needs to be shown // this means we potentially have a new tank that is being used and needs to be shown
fixup_dive(d); fixup_dive(&displayed_dive);
// FIXME - this no longer gets written to the dive list - so we need to enableEdition() here
MainWindow::instance()->information()->updateDiveInfo(); MainWindow::instance()->information()->updateDiveInfo();
mark_divelist_changed(true); mark_divelist_changed(true);
replot(); replot();