profile: explicitly update gas-axis

On each profile replot, the gas axis was implicitly reset
by calling "dataModel->emitDataChanged()", which would send
a signal recieved by the axis. To make the code less confusing
and, more importantly, make order of execution deterministic,
explicitly reset the axis.

Rename the function that resets the axis from "settingsChanged"
to "update" to reflect its usage.

Moreover, remove the "setModel()" function and pass the model
to the constructore. Make it a const reference to make clear
that it can't change during the life time of the axis.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2020-12-29 22:49:40 +01:00 committed by Dirk Hohndel
parent f4103e4998
commit dd0939b6f5
3 changed files with 16 additions and 24 deletions

View file

@ -413,34 +413,27 @@ QString TemperatureAxis::textForValue(double value) const
return QString::number(mkelvin_to_C((int)value));
}
PartialGasPressureAxis::PartialGasPressureAxis(ProfileWidget2 *widget) :
PartialGasPressureAxis::PartialGasPressureAxis(const DivePlotDataModel &model, ProfileWidget2 *widget) :
DiveCartesianAxis(widget),
model(NULL)
model(model)
{
connect(&diveListNotifier, &DiveListNotifier::settingsChanged, this, &PartialGasPressureAxis::settingsChanged);
connect(&diveListNotifier, &DiveListNotifier::settingsChanged, this, &PartialGasPressureAxis::update);
}
void PartialGasPressureAxis::setModel(DivePlotDataModel *m)
{
model = m;
connect(model, SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(settingsChanged()));
settingsChanged();
}
void PartialGasPressureAxis::settingsChanged()
void PartialGasPressureAxis::update()
{
bool showPhe = prefs.pp_graphs.phe;
bool showPn2 = prefs.pp_graphs.pn2;
bool showPo2 = prefs.pp_graphs.po2;
setVisible(showPhe || showPn2 || showPo2);
if (!model->rowCount())
if (!model.rowCount())
return;
double max = showPhe ? model->pheMax() : -1;
if (showPn2 && model->pn2Max() > max)
max = model->pn2Max();
if (showPo2 && model->po2Max() > max)
max = model->po2Max();
double max = showPhe ? model.pheMax() : -1;
if (showPn2 && model.pn2Max() > max)
max = model.pn2Max();
if (showPo2 && model.po2Max() > max)
max = model.po2Max();
qreal pp = floor(max * 10.0) / 10.0 + 0.2;
if (IS_FP_SAME(maximum(), pp))

View file

@ -109,13 +109,12 @@ private:
class PartialGasPressureAxis : public DiveCartesianAxis {
Q_OBJECT
public:
PartialGasPressureAxis(ProfileWidget2 *widget);
void setModel(DivePlotDataModel *model);
PartialGasPressureAxis(const DivePlotDataModel &model, ProfileWidget2 *widget);
public
slots:
void settingsChanged();
void update();
private:
DivePlotDataModel *model;
const DivePlotDataModel &model;
};
#endif // DIVECARTESIANAXIS_H

View file

@ -120,7 +120,7 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) : QGraphicsView(parent),
#endif
isPlotZoomed(prefs.zoomed_plot),// no! bad use of prefs. 'PreferencesDialog::loadSettings' NOT CALLED yet.
profileYAxis(new DepthAxis(this)),
gasYAxis(new PartialGasPressureAxis(this)),
gasYAxis(new PartialGasPressureAxis(*dataModel, this)),
temperatureAxis(new TemperatureAxis(this)),
timeAxis(new TimeAxis(this)),
diveProfileItem(createItem<DiveProfileItem>(*profileYAxis, DivePlotDataModel::DEPTH, 0)),
@ -288,7 +288,6 @@ void ProfileWidget2::setupItemOnScene()
gasYAxis->setTickInterval(1);
gasYAxis->setTickSize(1);
gasYAxis->setMinimum(0);
gasYAxis->setModel(dataModel);
gasYAxis->setFontLabelScale(0.7);
gasYAxis->setLineSize(96);
@ -735,6 +734,7 @@ void ProfileWidget2::plotDive(const struct dive *d, bool force, bool doClearPict
#endif
tankItem->setData(&plotInfo, &displayed_dive);
gasYAxis->update();
dataModel->emitDataChanged();
// The event items are a bit special since we don't know how many events are going to
// exist on a dive, so I cant create cache items for that. that's why they are here
@ -837,7 +837,7 @@ void ProfileWidget2::settingsChanged()
else
needReplot = prefs.calcceiling;
#ifndef SUBSURFACE_MOBILE
gasYAxis->settingsChanged(); // Initialize ticks of partial pressure graph
gasYAxis->update(); // Initialize ticks of partial pressure graph
if ((prefs.percentagegraph||prefs.hrgraph) && PP_GRAPHS_ENABLED) {
profileYAxis->animateChangeLine(itemPos.depth.shrinked);
temperatureAxis->setPos(itemPos.temperatureAll.pos.on);