From dd0939b6f5c9c7399183f2a36b2be77521886ef0 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Tue, 29 Dec 2020 22:49:40 +0100 Subject: 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 --- profile-widget/divecartesianaxis.cpp | 27 ++++++++++----------------- profile-widget/divecartesianaxis.h | 7 +++---- profile-widget/profilewidget2.cpp | 6 +++--- 3 files changed, 16 insertions(+), 24 deletions(-) (limited to 'profile-widget') diff --git a/profile-widget/divecartesianaxis.cpp b/profile-widget/divecartesianaxis.cpp index 8ee74e7f1..33b09b615 100644 --- a/profile-widget/divecartesianaxis.cpp +++ b/profile-widget/divecartesianaxis.cpp @@ -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)) diff --git a/profile-widget/divecartesianaxis.h b/profile-widget/divecartesianaxis.h index 1ea623649..a4a38dd1e 100644 --- a/profile-widget/divecartesianaxis.h +++ b/profile-widget/divecartesianaxis.h @@ -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 diff --git a/profile-widget/profilewidget2.cpp b/profile-widget/profilewidget2.cpp index 20897b674..737fdf306 100644 --- a/profile-widget/profilewidget2.cpp +++ b/profile-widget/profilewidget2.cpp @@ -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(*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); -- cgit v1.2.3-70-g09d2