planner: pass in_planner argument to replot()

To remove reliance on global state, pass an "in_planner" argument
to AbstractProfilePolygonItem::replot(). Thus, calls to in_planner()
can be removed.

This is a bit sad, since the in_planner argument is now passed
to numerous replot() reimplementations of classes derived
from AbstractProfilePolygonItem. However, it is only needed
for one, viz. DiveGasPressureItem. Well, perhaps in the future
more features will depend on the planner mode...

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2021-02-13 17:42:03 +01:00 committed by Dirk Hohndel
parent 65720d2fce
commit c6d78bc134
3 changed files with 28 additions and 28 deletions

View file

@ -31,7 +31,7 @@ void AbstractProfilePolygonItem::setVisible(bool visible)
QGraphicsPolygonItem::setVisible(visible); QGraphicsPolygonItem::setVisible(visible);
} }
void AbstractProfilePolygonItem::replot(const dive *) void AbstractProfilePolygonItem::replot(const dive *, bool)
{ {
// Calculate the polygon. This is the polygon that will be painted on screen // Calculate the polygon. This is the polygon that will be painted on screen
// on the ::paint method. Here we calculate the correct position of the points // on the ::paint method. Here we calculate the correct position of the points
@ -85,9 +85,9 @@ void DiveProfileItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *o
painter->restore(); painter->restore();
} }
void DiveProfileItem::replot(const dive *d) void DiveProfileItem::replot(const dive *d, bool in_planner)
{ {
AbstractProfilePolygonItem::replot(d); AbstractProfilePolygonItem::replot(d, in_planner);
if (polygon().isEmpty()) if (polygon().isEmpty())
return; return;
@ -165,7 +165,7 @@ DiveHeartrateItem::DiveHeartrateItem(const DivePlotDataModel &model, const DiveC
connect(qPrefTechnicalDetails::instance(), &qPrefTechnicalDetails::hrgraphChanged, this, &DiveHeartrateItem::setVisible); connect(qPrefTechnicalDetails::instance(), &qPrefTechnicalDetails::hrgraphChanged, this, &DiveHeartrateItem::setVisible);
} }
void DiveHeartrateItem::replot(const dive *) void DiveHeartrateItem::replot(const dive *, bool)
{ {
int last = -300, last_printed_hr = 0, sec = 0; int last = -300, last_printed_hr = 0, sec = 0;
struct { struct {
@ -244,7 +244,7 @@ DivePercentageItem::DivePercentageItem(const DivePlotDataModel &model, const Div
connect(qPrefTechnicalDetails::instance(), &qPrefTechnicalDetails::percentagegraphChanged, this, &DivePercentageItem::setVisible); connect(qPrefTechnicalDetails::instance(), &qPrefTechnicalDetails::percentagegraphChanged, this, &DivePercentageItem::setVisible);
} }
void DivePercentageItem::replot(const dive *d) void DivePercentageItem::replot(const dive *d, bool)
{ {
// Ignore empty values. a heart rate of 0 would be a bad sign. // Ignore empty values. a heart rate of 0 would be a bad sign.
QPolygonF poly; QPolygonF poly;
@ -318,7 +318,7 @@ DiveAmbPressureItem::DiveAmbPressureItem(const DivePlotDataModel &model, const D
setPen(pen); setPen(pen);
} }
void DiveAmbPressureItem::replot(const dive *) void DiveAmbPressureItem::replot(const dive *, bool)
{ {
int sec = 0; int sec = 0;
@ -359,7 +359,7 @@ DiveGFLineItem::DiveGFLineItem(const DivePlotDataModel &model, const DiveCartesi
setPen(pen); setPen(pen);
} }
void DiveGFLineItem::replot(const dive *) void DiveGFLineItem::replot(const dive *, bool)
{ {
int sec = 0; int sec = 0;
@ -400,7 +400,7 @@ DiveTemperatureItem::DiveTemperatureItem(const DivePlotDataModel &model, const D
setPen(pen); setPen(pen);
} }
void DiveTemperatureItem::replot(const dive *) void DiveTemperatureItem::replot(const dive *, bool)
{ {
int last = -300, last_printed_temp = 0, sec = 0, last_valid_temp = 0; int last = -300, last_printed_temp = 0, sec = 0, last_valid_temp = 0;
@ -478,7 +478,7 @@ DiveMeanDepthItem::DiveMeanDepthItem(const DivePlotDataModel &model, const DiveC
lastRunningSum = 0.0; lastRunningSum = 0.0;
} }
void DiveMeanDepthItem::replot(const dive *) void DiveMeanDepthItem::replot(const dive *, bool)
{ {
double meandepthvalue = 0.0; double meandepthvalue = 0.0;
@ -525,7 +525,7 @@ void DiveMeanDepthItem::createTextItem()
texts.append(text); texts.append(text);
} }
void DiveGasPressureItem::replot(const dive *d) void DiveGasPressureItem::replot(const dive *d, bool in_planner)
{ {
const struct plot_info *pInfo = &dataModel.data(); const struct plot_info *pInfo = &dataModel.data();
std::vector<int> plotted_cyl(pInfo->nr_cylinders, false); std::vector<int> plotted_cyl(pInfo->nr_cylinders, false);
@ -548,7 +548,7 @@ void DiveGasPressureItem::replot(const dive *d)
boundingPoly.push_back(point); boundingPoly.push_back(point);
QColor color; QColor color;
if (!in_planner()) { if (in_planner) {
if (entry->sac) if (entry->sac)
color = getSacColor(entry->sac, d->sac); color = getSacColor(entry->sac, d->sac);
else else
@ -699,9 +699,9 @@ DiveCalculatedCeiling::DiveCalculatedCeiling(const DivePlotDataModel &model, con
setVisible(prefs.calcceiling); setVisible(prefs.calcceiling);
} }
void DiveCalculatedCeiling::replot(const dive *d) void DiveCalculatedCeiling::replot(const dive *d, bool in_planner)
{ {
AbstractProfilePolygonItem::replot(d); AbstractProfilePolygonItem::replot(d, in_planner);
// Add 2 points to close the polygon. // Add 2 points to close the polygon.
QPolygonF poly = polygon(); QPolygonF poly = polygon();
if (poly.isEmpty()) if (poly.isEmpty())
@ -747,7 +747,7 @@ DiveReportedCeiling::DiveReportedCeiling(const DivePlotDataModel &model, const D
setVisible(prefs.dcceiling); setVisible(prefs.dcceiling);
} }
void DiveReportedCeiling::replot(const dive *) void DiveReportedCeiling::replot(const dive *, bool)
{ {
QPolygonF p; QPolygonF p;
p.append(QPointF(hAxis.posAtValue(0), vAxis.posAtValue(0))); p.append(QPointF(hAxis.posAtValue(0), vAxis.posAtValue(0)));
@ -780,7 +780,7 @@ void DiveReportedCeiling::paint(QPainter *painter, const QStyleOptionGraphicsIte
QGraphicsPolygonItem::paint(painter, option, widget); QGraphicsPolygonItem::paint(painter, option, widget);
} }
void PartialPressureGasItem::replot(const dive *) void PartialPressureGasItem::replot(const dive *, bool)
{ {
plot_data *entry = dataModel.data().entry; plot_data *entry = dataModel.data().entry;
QPolygonF poly; QPolygonF poly;

View file

@ -39,7 +39,7 @@ public:
AbstractProfilePolygonItem(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn); AbstractProfilePolygonItem(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn);
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) = 0; virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) = 0;
void clear(); void clear();
virtual void replot(const dive *d); virtual void replot(const dive *d, bool in_planner);
public public
slots: slots:
void setVisible(bool visible); void setVisible(bool visible);
@ -59,7 +59,7 @@ class DiveProfileItem : public AbstractProfilePolygonItem {
public: public:
DiveProfileItem(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn); DiveProfileItem(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn);
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override;
void replot(const dive *d) override; void replot(const dive *d, bool in_planner) override;
void plot_depth_sample(struct plot_data *entry, QFlags<Qt::AlignmentFlag> flags, const QColor &color); void plot_depth_sample(struct plot_data *entry, QFlags<Qt::AlignmentFlag> flags, const QColor &color);
int maxCeiling(int row); int maxCeiling(int row);
@ -73,7 +73,7 @@ class DiveMeanDepthItem : public AbstractProfilePolygonItem {
Q_OBJECT Q_OBJECT
public: public:
DiveMeanDepthItem(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn); DiveMeanDepthItem(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn);
void replot(const dive *d) override; void replot(const dive *d, bool in_planner) override;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override;
private: private:
@ -86,7 +86,7 @@ class DiveTemperatureItem : public AbstractProfilePolygonItem {
Q_OBJECT Q_OBJECT
public: public:
DiveTemperatureItem(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn); DiveTemperatureItem(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn);
void replot(const dive *d) override; void replot(const dive *d, bool in_planner) override;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override;
private: private:
@ -97,7 +97,7 @@ class DiveHeartrateItem : public AbstractProfilePolygonItem {
Q_OBJECT Q_OBJECT
public: public:
DiveHeartrateItem(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn); DiveHeartrateItem(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn);
void replot(const dive *d) override; void replot(const dive *d, bool in_planner) override;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
private: private:
@ -109,7 +109,7 @@ class DivePercentageItem : public AbstractProfilePolygonItem {
Q_OBJECT Q_OBJECT
public: public:
DivePercentageItem(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn, int i); DivePercentageItem(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn, int i);
void replot(const dive *d) override; void replot(const dive *d, bool in_planner) override;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
private: private:
@ -124,7 +124,7 @@ class DiveAmbPressureItem : public AbstractProfilePolygonItem {
Q_OBJECT Q_OBJECT
public: public:
DiveAmbPressureItem(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn); DiveAmbPressureItem(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn);
void replot(const dive *d) override; void replot(const dive *d, bool in_planner) override;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
private: private:
@ -135,7 +135,7 @@ class DiveGFLineItem : public AbstractProfilePolygonItem {
Q_OBJECT Q_OBJECT
public: public:
DiveGFLineItem(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn); DiveGFLineItem(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn);
void replot(const dive *d) override; void replot(const dive *d, bool in_planner) override;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
private: private:
@ -147,7 +147,7 @@ class DiveGasPressureItem : public AbstractProfilePolygonItem {
public: public:
using AbstractProfilePolygonItem::AbstractProfilePolygonItem; using AbstractProfilePolygonItem::AbstractProfilePolygonItem;
void replot(const dive *d) override; void replot(const dive *d, bool in_planner) override;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override;
private: private:
@ -166,7 +166,7 @@ class DiveCalculatedCeiling : public AbstractProfilePolygonItem {
public: public:
DiveCalculatedCeiling(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, DiveCalculatedCeiling(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn,
const DiveCartesianAxis &vAxis, int vColumn, ProfileWidget2 *profileWidget); const DiveCartesianAxis &vAxis, int vColumn, ProfileWidget2 *profileWidget);
void replot(const dive *d) override; void replot(const dive *d, bool in_planner) override;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override;
private: private:
@ -178,7 +178,7 @@ class DiveReportedCeiling : public AbstractProfilePolygonItem {
public: public:
DiveReportedCeiling(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn); DiveReportedCeiling(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn);
void replot(const dive *d) override; void replot(const dive *d, bool in_planner) override;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override;
}; };
@ -195,7 +195,7 @@ class PartialPressureGasItem : public AbstractProfilePolygonItem {
public: public:
PartialPressureGasItem(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn); PartialPressureGasItem(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn);
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override;
void replot(const dive *d) override; void replot(const dive *d, bool in_planner) override;
void setThresholdSettingsKey(const double *prefPointerMin, const double *prefPointerMax); void setThresholdSettingsKey(const double *prefPointerMin, const double *prefPointerMax);
void setVisibilitySettingsKey(const QString &setVisibilitySettingsKey); void setVisibilitySettingsKey(const QString &setVisibilitySettingsKey);
void setColors(const QColor &normalColor, const QColor &alertColor); void setColors(const QColor &normalColor, const QColor &alertColor);

View file

@ -728,7 +728,7 @@ void ProfileWidget2::plotDive(const struct dive *d, bool force, bool doClearPict
// Replot dive items // Replot dive items
for (AbstractProfilePolygonItem *item: profileItems) for (AbstractProfilePolygonItem *item: profileItems)
item->replot(&displayed_dive); item->replot(&displayed_dive, currentState == PLAN);
// The event items are a bit special since we don't know how many events are going to // 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 // exist on a dive, so I cant create cache items for that. that's why they are here