profile: construct PP gas items with createPPGas() function

This function was called after creating the items. It can be
called directly to create the items. Less chance of mixups.

For this to work, the initialization of isGrayscale has to
be moved to the front, because createPPGas sets the color
according to this flag.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2020-12-20 18:50:37 +01:00 committed by Dirk Hohndel
parent b0f374c5c9
commit e3ea74e079
2 changed files with 19 additions and 25 deletions

View file

@ -109,6 +109,8 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) : QGraphicsView(parent),
dataModel(new DivePlotDataModel(this)), dataModel(new DivePlotDataModel(this)),
zoomLevel(0), zoomLevel(0),
zoomFactor(1.15), zoomFactor(1.15),
isGrayscale(false),
printMode(false),
background(new DivePixmapItem()), background(new DivePixmapItem()),
backgroundFile(":poster-icon"), backgroundFile(":poster-icon"),
#ifndef SUBSURFACE_MOBILE #ifndef SUBSURFACE_MOBILE
@ -126,14 +128,15 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) : QGraphicsView(parent),
gasPressureItem(createItem<DiveGasPressureItem>(*cylinderPressureAxis, DivePlotDataModel::TEMPERATURE)), gasPressureItem(createItem<DiveGasPressureItem>(*cylinderPressureAxis, DivePlotDataModel::TEMPERATURE)),
diveComputerText(new DiveTextItem()), diveComputerText(new DiveTextItem()),
reportedCeiling(createItem<DiveReportedCeiling>(*profileYAxis, DivePlotDataModel::CEILING)), reportedCeiling(createItem<DiveReportedCeiling>(*profileYAxis, DivePlotDataModel::CEILING)),
pn2GasItem(createItem<PartialPressureGasItem>(*gasYAxis, DivePlotDataModel::PN2)), pn2GasItem(createPPGas(DivePlotDataModel::PN2, PN2, PN2_ALERT, NULL, &prefs.pp_graphs.pn2_threshold)),
pheGasItem(createItem<PartialPressureGasItem>(*gasYAxis, DivePlotDataModel::PHE)), pheGasItem(createPPGas(DivePlotDataModel::PHE, PHE, PHE_ALERT, NULL, &prefs.pp_graphs.phe_threshold)),
po2GasItem(createItem<PartialPressureGasItem>(*gasYAxis, DivePlotDataModel::PO2)), po2GasItem(createPPGas(DivePlotDataModel::PO2, PO2, PO2_ALERT, &prefs.pp_graphs.po2_threshold_min, &prefs.pp_graphs.po2_threshold_max)),
o2SetpointGasItem(createItem<PartialPressureGasItem>(*gasYAxis, DivePlotDataModel::O2SETPOINT)), o2SetpointGasItem(createPPGas(DivePlotDataModel::O2SETPOINT, O2SETPOINT, PO2_ALERT, &prefs.pp_graphs.po2_threshold_min, &prefs.pp_graphs.po2_threshold_max)),
ccrsensor1GasItem(createItem<PartialPressureGasItem>(*gasYAxis, DivePlotDataModel::CCRSENSOR1)), ccrsensor1GasItem(createPPGas(DivePlotDataModel::CCRSENSOR1, CCRSENSOR1, PO2_ALERT, &prefs.pp_graphs.po2_threshold_min, &prefs.pp_graphs.po2_threshold_max)),
ccrsensor2GasItem(createItem<PartialPressureGasItem>(*gasYAxis, DivePlotDataModel::CCRSENSOR2)), ccrsensor2GasItem(createPPGas(DivePlotDataModel::CCRSENSOR2, CCRSENSOR2, PO2_ALERT, &prefs.pp_graphs.po2_threshold_min, &prefs.pp_graphs.po2_threshold_max)),
ccrsensor3GasItem(createItem<PartialPressureGasItem>(*gasYAxis, DivePlotDataModel::CCRSENSOR3)), ccrsensor3GasItem(createPPGas(DivePlotDataModel::CCRSENSOR3, CCRSENSOR3, PO2_ALERT, &prefs.pp_graphs.po2_threshold_min, &prefs.pp_graphs.po2_threshold_max)),
ocpo2GasItem(createItem<PartialPressureGasItem>(*gasYAxis, DivePlotDataModel::SCR_OC_PO2)), ocpo2GasItem(createPPGas(DivePlotDataModel::SCR_OC_PO2, SCR_OCPO2, PO2_ALERT, &prefs.pp_graphs.po2_threshold_min, &prefs.pp_graphs.po2_threshold_max)),
#ifndef SUBSURFACE_MOBILE #ifndef SUBSURFACE_MOBILE
diveCeiling(createItem<DiveCalculatedCeiling>(*profileYAxis, DivePlotDataModel::CEILING, this)), diveCeiling(createItem<DiveCalculatedCeiling>(*profileYAxis, DivePlotDataModel::CEILING, this)),
decoModelParameters(new DiveTextItem()), decoModelParameters(new DiveTextItem()),
@ -147,8 +150,6 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) : QGraphicsView(parent),
rulerItem(new RulerItem2()), rulerItem(new RulerItem2()),
#endif #endif
tankItem(new TankItem()), tankItem(new TankItem()),
isGrayscale(false),
printMode(false),
shouldCalculateMaxTime(true), shouldCalculateMaxTime(true),
shouldCalculateMaxDepth(true), shouldCalculateMaxDepth(true),
fontPrintScale(1.0) fontPrintScale(1.0)
@ -367,15 +368,6 @@ void ProfileWidget2::setupItemOnScene()
setupItem(diveProfileItem, 0); setupItem(diveProfileItem, 0);
setupItem(meanDepthItem, 1); setupItem(meanDepthItem, 1);
createPPGas(pn2GasItem, PN2, PN2_ALERT, NULL, &prefs.pp_graphs.pn2_threshold);
createPPGas(pheGasItem, PHE, PHE_ALERT, NULL, &prefs.pp_graphs.phe_threshold);
createPPGas(po2GasItem, PO2, PO2_ALERT, &prefs.pp_graphs.po2_threshold_min, &prefs.pp_graphs.po2_threshold_max);
createPPGas(o2SetpointGasItem, O2SETPOINT, PO2_ALERT, &prefs.pp_graphs.po2_threshold_min, &prefs.pp_graphs.po2_threshold_max);
createPPGas(ccrsensor1GasItem, CCRSENSOR1, PO2_ALERT, &prefs.pp_graphs.po2_threshold_min, &prefs.pp_graphs.po2_threshold_max);
createPPGas(ccrsensor2GasItem, CCRSENSOR2, PO2_ALERT, &prefs.pp_graphs.po2_threshold_min, &prefs.pp_graphs.po2_threshold_max);
createPPGas(ccrsensor3GasItem, CCRSENSOR3, PO2_ALERT, &prefs.pp_graphs.po2_threshold_min, &prefs.pp_graphs.po2_threshold_max);
createPPGas(ocpo2GasItem, SCR_OCPO2, PO2_ALERT, &prefs.pp_graphs.po2_threshold_min, &prefs.pp_graphs.po2_threshold_max);
#undef CREATE_PP_GAS #undef CREATE_PP_GAS
#ifndef SUBSURFACE_MOBILE #ifndef SUBSURFACE_MOBILE
@ -410,14 +402,16 @@ void ProfileWidget2::replot()
plotDive(current_dive, true, false); plotDive(current_dive, true, false);
} }
void ProfileWidget2::createPPGas(PartialPressureGasItem *item, color_index_t color, color_index_t colorAlert, PartialPressureGasItem *ProfileWidget2::createPPGas(int column, color_index_t color, color_index_t colorAlert,
const double *thresholdSettingsMin, const double *thresholdSettingsMax) const double *thresholdSettingsMin, const double *thresholdSettingsMax)
{ {
PartialPressureGasItem *item = createItem<PartialPressureGasItem>(*gasYAxis, column);
setupItem(item, 0); setupItem(item, 0);
item->setThresholdSettingsKey(thresholdSettingsMin, thresholdSettingsMax); item->setThresholdSettingsKey(thresholdSettingsMin, thresholdSettingsMax);
item->setColors(getColor(color, isGrayscale), getColor(colorAlert, isGrayscale)); item->setColors(getColor(color, isGrayscale), getColor(colorAlert, isGrayscale));
item->settingsChanged(); item->settingsChanged();
item->setZValue(99); item->setZValue(99);
return item;
} }
void ProfileWidget2::setupItemSizes() void ProfileWidget2::setupItemSizes()

View file

@ -159,7 +159,7 @@ private:
void disconnectTemporaryConnections(); void disconnectTemporaryConnections();
struct plot_data *getEntryFromPos(QPointF pos); struct plot_data *getEntryFromPos(QPointF pos);
void addActionShortcut(const Qt::Key shortcut, void (ProfileWidget2::*slot)()); void addActionShortcut(const Qt::Key shortcut, void (ProfileWidget2::*slot)());
void createPPGas(PartialPressureGasItem *item, color_index_t color, color_index_t colorAlert, PartialPressureGasItem *createPPGas(int column, color_index_t color, color_index_t colorAlert,
const double *thresholdSettingsMin, const double *thresholdSettingsMax); const double *thresholdSettingsMin, const double *thresholdSettingsMax);
void clearPictures(); void clearPictures();
void plotPicturesInternal(const struct dive *d, bool synchronous); void plotPicturesInternal(const struct dive *d, bool synchronous);
@ -178,6 +178,8 @@ private:
DivePlotDataModel *dataModel; DivePlotDataModel *dataModel;
int zoomLevel; int zoomLevel;
qreal zoomFactor; qreal zoomFactor;
bool isGrayscale;
bool printMode;
DivePixmapItem *background; DivePixmapItem *background;
QString backgroundFile; QString backgroundFile;
#ifndef SUBSURFACE_MOBILE #ifndef SUBSURFACE_MOBILE
@ -223,8 +225,6 @@ private:
RulerItem2 *rulerItem; RulerItem2 *rulerItem;
#endif #endif
TankItem *tankItem; TankItem *tankItem;
bool isGrayscale;
bool printMode;
QList<QGraphicsSimpleTextItem *> gases; QList<QGraphicsSimpleTextItem *> gases;