summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2014-07-03 14:34:24 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-07-03 14:43:32 -0700
commitd8c31135848d765a3d241d295e5d6afc311f7820 (patch)
treea45fcebd0119f43576cc41ae1936c127bd01a88c
parent117b212cddda614a1c668882f8165c3a6a4f3093 (diff)
downloadsubsurface-d8c31135848d765a3d241d295e5d6afc311f7820.tar.gz
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>
-rw-r--r--qt-ui/profile/diveplotdatamodel.cpp12
-rw-r--r--qt-ui/profile/diveplotdatamodel.h1
-rw-r--r--qt-ui/profile/diveprofileitem.cpp6
-rw-r--r--qt-ui/profile/profilewidget2.cpp49
4 files changed, 28 insertions, 40 deletions
diff --git a/qt-ui/profile/diveplotdatamodel.cpp b/qt-ui/profile/diveplotdatamodel.cpp
index 08bcf11bd..47a44768a 100644
--- a/qt-ui/profile/diveplotdatamodel.cpp
+++ b/qt-ui/profile/diveplotdatamodel.cpp
@@ -146,11 +146,6 @@ void DivePlotDataModel::setDive(dive *d, const plot_info &info)
endInsertRows();
}
-int DivePlotDataModel::id() const
-{
- return diveId;
-}
-
unsigned int DivePlotDataModel::dcShown() const
{
return dcNr;
@@ -178,9 +173,8 @@ void DivePlotDataModel::emitDataChanged()
void DivePlotDataModel::calculateDecompression()
{
- struct dive *d = get_dive_by_uniq_id(id());
- struct divecomputer *dc = select_dc(d);
- init_decompression(d);
- calculate_deco_information(d, dc, &pInfo, false);
+ struct divecomputer *dc = select_dc(&displayed_dive);
+ init_decompression(&displayed_dive);
+ calculate_deco_information(&displayed_dive, dc, &pInfo, false);
dataChanged(index(0, CEILING), index(pInfo.nr - 1, TISSUE_16));
}
diff --git a/qt-ui/profile/diveplotdatamodel.h b/qt-ui/profile/diveplotdatamodel.h
index 35805256d..bb0c64152 100644
--- a/qt-ui/profile/diveplotdatamodel.h
+++ b/qt-ui/profile/diveplotdatamodel.h
@@ -54,7 +54,6 @@ public:
void clear();
void setDive(struct dive *d, const plot_info &pInfo);
const plot_info &data() const;
- int id() const;
unsigned int dcShown() const;
double pheMax();
double pn2Max();
diff --git a/qt-ui/profile/diveprofileitem.cpp b/qt-ui/profile/diveprofileitem.cpp
index c63f9ecc4..fda31cb12 100644
--- a/qt-ui/profile/diveprofileitem.cpp
+++ b/qt-ui/profile/diveprofileitem.cpp
@@ -450,7 +450,6 @@ void DiveGasPressureItem::modelDataChanged(const QModelIndex &topLeft, const QMo
int last_pressure[MAX_CYLINDERS] = { 0, };
int last_time[MAX_CYLINDERS] = { 0, };
struct plot_data *entry;
- struct dive *dive = get_dive_by_uniq_id(dataModel->id());
cyl = -1;
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]) {
plotPressureValue(mbar, entry->sec, Qt::AlignRight | Qt::AlignTop);
plotGasValue(mbar, entry->sec, Qt::AlignRight | Qt::AlignBottom,
- dive->cylinder[cyl].gasmix);
+ displayed_dive.cylinder[cyl].gasmix);
seen_cyl[cyl] = true;
}
}
@@ -509,11 +508,10 @@ void DiveGasPressureItem::paint(QPainter *painter, const QStyleOptionGraphicsIte
QPen pen;
pen.setCosmetic(true);
pen.setWidth(2);
- struct dive *d = get_dive_by_uniq_id(dataModel->id());
struct plot_data *entry = dataModel->data().entry;
Q_FOREACH (const QPolygonF &poly, polygons) {
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->drawLine(poly[i - 1], poly[i]);
}
diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp
index 7a17fd7fb..c7a27fcbd 100644
--- a/qt-ui/profile/profilewidget2.cpp
+++ b/qt-ui/profile/profilewidget2.cpp
@@ -253,7 +253,6 @@ void ProfileWidget2::setupItemOnScene()
void ProfileWidget2::replot()
{
- int diveId = dataModel->id();
dataModel->clear();
plotDive(); // simply plot the displayed_dive again
}
@@ -360,28 +359,25 @@ void ProfileWidget2::plotDive(struct dive *d)
QTime measureDuration; // let's measure how long this takes us (maybe we'll turn of TTL calculation later
measureDuration.start();
- if (!d) {
- if (selected_dive == -1)
- 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;
+ if (currentState != ADD && currentState != PLAN) {
+ if (!d) {
+ if (selected_dive == -1)
+ return;
+ d = current_dive; // display the current dive
+ }
- forceReplot = false;
+ // 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 == displayed_dive.id && dc_number == dataModel->dcShown() && !forceReplot)
+ return;
- // this copies the dive and makes copies of all the relevant additional data
- copy_dive(d, &displayed_dive);
+ forceReplot = false;
- //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) {
+ // this copies the dive and makes copies of all the relevant additional data
+ copy_dive(d, &displayed_dive);
+ } else {
DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance();
plannerModel->createTemporaryPlan();
if (!plannerModel->getDiveplan().dp) {
@@ -497,7 +493,7 @@ void ProfileWidget2::plotDive(struct dive *d)
else
meanDepth->setVisible(false);
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));
dataModel->emitDataChanged();
@@ -524,7 +520,7 @@ void ProfileWidget2::plotDive(struct dive *d)
}
QString dcText = get_dc_nickname(currentdc->model, currentdc->deviceid);
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);
diveComputerText->setText(dcText);
if (MainWindow::instance()->filesFromCommandLine() && animSpeedBackup != -1) {
@@ -1046,15 +1042,16 @@ void ProfileWidget2::changeGas()
QString gas = action->text();
// backup the things on the dataModel, since we will clear that out.
unsigned int diveComputer = dataModel->dcShown();
- int diveId = dataModel->id();
struct gasmix gasmix;
int seconds = timeAxis->valueAt(scenePos);
- struct dive *d = get_dive_by_uniq_id(diveId);
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
- 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();
mark_divelist_changed(true);
replot();