diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2020-12-20 18:12:55 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2021-01-10 15:57:39 -0800 |
commit | 3f100fda0ac4848f5ddf1793b7b1f3a03c97ccd9 (patch) | |
tree | 22b0880a555dd73c45840517812cec550791c2b0 | |
parent | bd01e91ea39c837677b543f1493e837d356cfaee (diff) | |
download | subsurface-3f100fda0ac4848f5ddf1793b7b1f3a03c97ccd9.tar.gz |
profile: initialize axis of DiveProfileItems on construction
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r-- | profile-widget/diveprofileitem.cpp | 128 | ||||
-rw-r--r-- | profile-widget/diveprofileitem.h | 35 | ||||
-rw-r--r-- | profile-widget/profilewidget2.cpp | 89 | ||||
-rw-r--r-- | profile-widget/profilewidget2.h | 4 |
4 files changed, 119 insertions, 137 deletions
diff --git a/profile-widget/diveprofileitem.cpp b/profile-widget/diveprofileitem.cpp index f2fade554..b1524446e 100644 --- a/profile-widget/diveprofileitem.cpp +++ b/profile-widget/diveprofileitem.cpp @@ -13,35 +13,31 @@ #include "libdivecomputer/parser.h" #include "profile-widget/profilewidget2.h" -AbstractProfilePolygonItem::AbstractProfilePolygonItem(const DivePlotDataModel &model) : - hAxis(NULL), vAxis(NULL), dataModel(model), hDataColumn(-1), vDataColumn(-1) +AbstractProfilePolygonItem::AbstractProfilePolygonItem(const DivePlotDataModel &model, const DiveCartesianAxis &horizontal, int hColumn, + const DiveCartesianAxis &vertical, int vColumn) : + hAxis(horizontal), vAxis(vertical), dataModel(model), hDataColumn(hColumn), vDataColumn(vColumn) { setCacheMode(DeviceCoordinateCache); connect(&diveListNotifier, &DiveListNotifier::settingsChanged, this, &AbstractProfilePolygonItem::settingsChanged); connect(&dataModel, &DivePlotDataModel::dataChanged, this, &AbstractProfilePolygonItem::modelDataChanged); connect(&dataModel, &DivePlotDataModel::rowsAboutToBeRemoved, this, &AbstractProfilePolygonItem::modelDataRemoved); + connect(&hAxis, &DiveCartesianAxis::sizeChanged, this, &AbstractProfilePolygonItem::replot); + connect(&vAxis, &DiveCartesianAxis::sizeChanged, this, &AbstractProfilePolygonItem::replot); + connect(&vAxis, &DiveCartesianAxis::maxChanged, this, &AbstractProfilePolygonItem::replot); } -void AbstractProfilePolygonItem::settingsChanged() -{ -} - -void AbstractProfilePolygonItem::setVisible(bool visible) +void AbstractProfilePolygonItem::replot() { - QGraphicsPolygonItem::setVisible(visible); + modelDataChanged(); } -void AbstractProfilePolygonItem::setHorizontalAxis(DiveCartesianAxis *horizontal) +void AbstractProfilePolygonItem::settingsChanged() { - hAxis = horizontal; - connect(hAxis, SIGNAL(sizeChanged()), this, SLOT(modelDataChanged())); - modelDataChanged(); } -void AbstractProfilePolygonItem::setHorizontalDataColumn(int column) +void AbstractProfilePolygonItem::setVisible(bool visible) { - hDataColumn = column; - modelDataChanged(); + QGraphicsPolygonItem::setVisible(visible); } void AbstractProfilePolygonItem::modelDataRemoved(const QModelIndex&, int, int) @@ -51,24 +47,8 @@ void AbstractProfilePolygonItem::modelDataRemoved(const QModelIndex&, int, int) texts.clear(); } -void AbstractProfilePolygonItem::setVerticalAxis(DiveCartesianAxis *vertical) -{ - vAxis = vertical; - connect(vAxis, SIGNAL(sizeChanged()), this, SLOT(modelDataChanged())); - connect(vAxis, SIGNAL(maxChanged()), this, SLOT(modelDataChanged())); - modelDataChanged(); -} - -void AbstractProfilePolygonItem::setVerticalDataColumn(int column) -{ - vDataColumn = column; - modelDataChanged(); -} - bool AbstractProfilePolygonItem::shouldCalculateStuff(const QModelIndex &topLeft, const QModelIndex &bottomRight) { - if (!hAxis || !vAxis) - return false; if (dataModel.rowCount() == 0) return false; if (hDataColumn == -1 || vDataColumn == -1) @@ -93,7 +73,7 @@ void AbstractProfilePolygonItem::modelDataChanged(const QModelIndex&, const QMod for (int i = 0, modelDataCount = dataModel.rowCount(); i < modelDataCount; i++) { qreal horizontalValue = dataModel.index(i, hDataColumn).data().toReal(); qreal verticalValue = dataModel.index(i, vDataColumn).data().toReal(); - QPointF point(hAxis->posAtValue(horizontalValue), vAxis->posAtValue(verticalValue)); + QPointF point(hAxis.posAtValue(horizontalValue), vAxis.posAtValue(verticalValue)); poly.append(point); } setPolygon(poly); @@ -102,7 +82,8 @@ void AbstractProfilePolygonItem::modelDataChanged(const QModelIndex&, const QMod texts.clear(); } -DiveProfileItem::DiveProfileItem(const DivePlotDataModel &model) : AbstractProfilePolygonItem(model), +DiveProfileItem::DiveProfileItem(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn) : + AbstractProfilePolygonItem(model, hAxis, hColumn, vAxis, vColumn), show_reported_ceiling(0), reported_ceiling_in_red(0) { connect(qPrefTechnicalDetails::instance(), &qPrefTechnicalDetails::dcceilingChanged, this, &DiveProfileItem::settingsToggled); @@ -194,9 +175,9 @@ void DiveProfileItem::modelDataChanged(const QModelIndex &topLeft, const QModelI for (int i = dataModel.rowCount() - 1; i >= 0; i--, entry--) { if (!entry->in_deco) { /* not in deco implies this is a safety stop, no ceiling */ - p.append(QPointF(hAxis->posAtValue(entry->sec), vAxis->posAtValue(0))); + p.append(QPointF(hAxis.posAtValue(entry->sec), vAxis.posAtValue(0))); } else { - p.append(QPointF(hAxis->posAtValue(entry->sec), vAxis->posAtValue(qMin(entry->stopdepth, entry->depth)))); + p.append(QPointF(hAxis.posAtValue(entry->sec), vAxis.posAtValue(qMin(entry->stopdepth, entry->depth)))); } } setPolygon(p); @@ -246,14 +227,15 @@ void DiveProfileItem::settingsChanged() void DiveProfileItem::plot_depth_sample(struct plot_data *entry, QFlags<Qt::AlignmentFlag> flags, const QColor &color) { DiveTextItem *item = new DiveTextItem(this); - item->setPos(hAxis->posAtValue(entry->sec), vAxis->posAtValue(entry->depth)); + item->setPos(hAxis.posAtValue(entry->sec), vAxis.posAtValue(entry->depth)); item->setText(get_depth_string(entry->depth, true)); item->setAlignment(flags); item->setBrush(color); texts.append(item); } -DiveHeartrateItem::DiveHeartrateItem(const DivePlotDataModel &model) : AbstractProfilePolygonItem(model) +DiveHeartrateItem::DiveHeartrateItem(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn) : + AbstractProfilePolygonItem(model, hAxis, hColumn, vAxis, vColumn) { QPen pen; pen.setBrush(QBrush(getColor(::HR_PLOT))); @@ -284,7 +266,7 @@ void DiveHeartrateItem::modelDataChanged(const QModelIndex &topLeft, const QMode if (!hr) continue; sec = dataModel.index(i, hDataColumn).data().toInt(); - QPointF point(hAxis->posAtValue(sec), vAxis->posAtValue(hr)); + QPointF point(hAxis.posAtValue(sec), vAxis.posAtValue(hr)); poly.append(point); if (hr == hist[2].hr) // same as last one, no point in looking at printing @@ -323,7 +305,7 @@ void DiveHeartrateItem::createTextItem(int sec, int hr) DiveTextItem *text = new DiveTextItem(this); text->setAlignment(Qt::AlignRight | Qt::AlignBottom); text->setBrush(getColor(HR_TEXT)); - text->setPos(QPointF(hAxis->posAtValue(sec), vAxis->posAtValue(hr))); + text->setPos(QPointF(hAxis.posAtValue(sec), vAxis.posAtValue(hr))); text->setScale(0.7); // need to call this BEFORE setText() text->setText(QString("%1").arg(hr)); texts.append(text); @@ -339,10 +321,11 @@ void DiveHeartrateItem::paint(QPainter *painter, const QStyleOptionGraphicsItem* painter->restore(); } -DivePercentageItem::DivePercentageItem(const DivePlotDataModel &model, int i) : AbstractProfilePolygonItem(model) +DivePercentageItem::DivePercentageItem(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn, int i) : + AbstractProfilePolygonItem(model, hAxis, hColumn, vAxis, vColumn), + tissueIndex(i) { connect(qPrefTechnicalDetails::instance(), &qPrefTechnicalDetails::percentagegraphChanged, this, &DivePercentageItem::setVisible); - tissueIndex = i; settingsChanged(); } @@ -358,7 +341,7 @@ void DivePercentageItem::modelDataChanged(const QModelIndex &topLeft, const QMod QPolygonF poly; for (int i = 0, modelDataCount = dataModel.rowCount(); i < modelDataCount; i++) { sec = dataModel.index(i, hDataColumn).data().toInt(); - QPointF point(hAxis->posAtValue(sec), vAxis->posAtValue(64 - 4 * tissueIndex)); + QPointF point(hAxis.posAtValue(sec), vAxis.posAtValue(64 - 4 * tissueIndex)); poly.append(point); } setPolygon(poly); @@ -416,7 +399,8 @@ void DivePercentageItem::paint(QPainter *painter, const QStyleOptionGraphicsItem painter->restore(); } -DiveAmbPressureItem::DiveAmbPressureItem(const DivePlotDataModel &model) : AbstractProfilePolygonItem(model) +DiveAmbPressureItem::DiveAmbPressureItem(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn) : + AbstractProfilePolygonItem(model, hAxis, hColumn, vAxis, vColumn) { QPen pen; pen.setBrush(QBrush(getColor(::AMB_PRESSURE_LINE))); @@ -441,7 +425,7 @@ void DiveAmbPressureItem::modelDataChanged(const QModelIndex &topLeft, const QMo if (!hr) continue; sec = dataModel.index(i, hDataColumn).data().toInt(); - QPointF point(hAxis->posAtValue(sec), vAxis->posAtValue(hr)); + QPointF point(hAxis.posAtValue(sec), vAxis.posAtValue(hr)); poly.append(point); } setPolygon(poly); @@ -461,7 +445,8 @@ void DiveAmbPressureItem::paint(QPainter *painter, const QStyleOptionGraphicsIte connect(qPrefTechnicalDetails::instance(), &qPrefTechnicalDetails::percentagegraphChanged, this, &DiveAmbPressureItem::setVisible); } -DiveGFLineItem::DiveGFLineItem(const DivePlotDataModel &model) : AbstractProfilePolygonItem(model) +DiveGFLineItem::DiveGFLineItem(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn) : + AbstractProfilePolygonItem(model, hAxis, hColumn, vAxis, vColumn) { QPen pen; pen.setBrush(QBrush(getColor(::GF_LINE))); @@ -486,7 +471,7 @@ void DiveGFLineItem::modelDataChanged(const QModelIndex &topLeft, const QModelIn if (!hr) continue; sec = dataModel.index(i, hDataColumn).data().toInt(); - QPointF point(hAxis->posAtValue(sec), vAxis->posAtValue(hr)); + QPointF point(hAxis.posAtValue(sec), vAxis.posAtValue(hr)); poly.append(point); } setPolygon(poly); @@ -506,7 +491,8 @@ void DiveGFLineItem::paint(QPainter *painter, const QStyleOptionGraphicsItem*, Q connect(qPrefTechnicalDetails::instance(), &qPrefTechnicalDetails::percentagegraphChanged, this, &DiveAmbPressureItem::setVisible); } -DiveTemperatureItem::DiveTemperatureItem(const DivePlotDataModel &model) : AbstractProfilePolygonItem(model) +DiveTemperatureItem::DiveTemperatureItem(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn) : + AbstractProfilePolygonItem(model, hAxis, hColumn, vAxis, vColumn) { QPen pen; pen.setBrush(QBrush(getColor(::TEMP_PLOT))); @@ -532,7 +518,7 @@ void DiveTemperatureItem::modelDataChanged(const QModelIndex &topLeft, const QMo continue; last_valid_temp = mkelvin; sec = dataModel.index(i, hDataColumn).data().toInt(); - QPointF point(hAxis->posAtValue(sec), vAxis->posAtValue(mkelvin)); + QPointF point(hAxis.posAtValue(sec), vAxis.posAtValue(mkelvin)); poly.append(point); /* don't print a temperature @@ -569,7 +555,7 @@ void DiveTemperatureItem::createTextItem(int sec, int mkelvin) DiveTextItem *text = new DiveTextItem(this); text->setAlignment(Qt::AlignRight | Qt::AlignBottom); text->setBrush(getColor(TEMP_TEXT)); - text->setPos(QPointF(hAxis->posAtValue(sec), vAxis->posAtValue(mkelvin))); + text->setPos(QPointF(hAxis.posAtValue(sec), vAxis.posAtValue(mkelvin))); text->setScale(0.8); // need to call this BEFORE setText() text->setText(get_temperature_string(temp, true)); texts.append(text); @@ -585,7 +571,8 @@ void DiveTemperatureItem::paint(QPainter *painter, const QStyleOptionGraphicsIte painter->restore(); } -DiveMeanDepthItem::DiveMeanDepthItem(const DivePlotDataModel &model) : AbstractProfilePolygonItem(model) +DiveMeanDepthItem::DiveMeanDepthItem(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn) : + AbstractProfilePolygonItem(model, hAxis, hColumn, vAxis, vColumn) { QPen pen; pen.setBrush(QBrush(getColor(::HR_AXIS))); @@ -611,7 +598,7 @@ void DiveMeanDepthItem::modelDataChanged(const QModelIndex &topLeft, const QMode continue; meandepthvalue = entry->running_sum / entry->sec; - QPointF point(hAxis->posAtValue(entry->sec), vAxis->posAtValue(meandepthvalue)); + QPointF point(hAxis.posAtValue(entry->sec), vAxis.posAtValue(meandepthvalue)); poly.append(point); } lastRunningSum = meandepthvalue; @@ -640,7 +627,7 @@ void DiveMeanDepthItem::createTextItem() DiveTextItem *text = new DiveTextItem(this); text->setAlignment(Qt::AlignRight | Qt::AlignTop); text->setBrush(getColor(TEMP_TEXT)); - text->setPos(QPointF(hAxis->posAtValue(sec) + 1, vAxis->posAtValue(lastRunningSum))); + text->setPos(QPointF(hAxis.posAtValue(sec) + 1, vAxis.posAtValue(lastRunningSum))); text->setScale(0.8); // need to call this BEFORE setText() text->setText(get_depth_string(lrint(lastRunningSum), true)); texts.append(text); @@ -669,7 +656,7 @@ void DiveGasPressureItem::modelDataChanged(const QModelIndex &topLeft, const QMo if (!mbar) continue; - QPointF point(hAxis->posAtValue(time), vAxis->posAtValue(mbar)); + QPointF point(hAxis.posAtValue(time), vAxis.posAtValue(mbar)); boundingPoly.push_back(point); if (plotted_cyl[cyl]) { @@ -716,7 +703,7 @@ void DiveGasPressureItem::modelDataChanged(const QModelIndex &topLeft, const QMo QFlags<Qt::AlignmentFlag> alignVar = Qt::AlignTop; std::vector<QFlags<Qt::AlignmentFlag>> align(pInfo->nr_cylinders); - double axisRange = (vAxis->maximum() - vAxis->minimum())/1000; // Convert axis pressure range to bar + double axisRange = (vAxis.maximum() - vAxis.minimum())/1000; // Convert axis pressure range to bar double axisLog = log10(log10(axisRange)); for (int i = 0, count = dataModel.rowCount(); i < count; i++) { @@ -767,7 +754,7 @@ void DiveGasPressureItem::plotPressureValue(int mbar, int sec, QFlags<Qt::Alignm const char *unit; int pressure = get_pressure_units(mbar, &unit); DiveTextItem *text = new DiveTextItem(this); - text->setPos(hAxis->posAtValue(sec), vAxis->posAtValue(mbar) + pressure_offset ); + text->setPos(hAxis.posAtValue(sec), vAxis.posAtValue(mbar) + pressure_offset ); text->setText(QString("%1%2").arg(pressure).arg(unit)); text->setAlignment(align); text->setBrush(getColor(PRESSURE_TEXT)); @@ -778,7 +765,7 @@ void DiveGasPressureItem::plotGasValue(int mbar, int sec, struct gasmix gasmix, { QString gas = get_gas_string(gasmix); DiveTextItem *text = new DiveTextItem(this); - text->setPos(hAxis->posAtValue(sec), vAxis->posAtValue(mbar) + gasname_offset ); + text->setPos(hAxis.posAtValue(sec), vAxis.posAtValue(mbar) + gasname_offset ); text->setText(gas); text->setAlignment(align); text->setBrush(getColor(PRESSURE_TEXT)); @@ -803,7 +790,7 @@ void DiveGasPressureItem::paint(QPainter *painter, const QStyleOptionGraphicsIte else pen.setBrush(MED_GRAY_HIGH_TRANS); } else { - if (vAxis->valueAt(poly[i]) < 0) + if (vAxis.valueAt(poly[i]) < 0) pen.setBrush(MAGENTA); else pen.setBrush(getPressureColor(entry->density)); @@ -815,8 +802,8 @@ void DiveGasPressureItem::paint(QPainter *painter, const QStyleOptionGraphicsIte painter->restore(); } -DiveCalculatedCeiling::DiveCalculatedCeiling(const DivePlotDataModel &model, ProfileWidget2 *widget) : - AbstractProfilePolygonItem(model), +DiveCalculatedCeiling::DiveCalculatedCeiling(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn, ProfileWidget2 *widget) : + AbstractProfilePolygonItem(model, hAxis, hColumn, vAxis, vColumn), profileWidget(widget) { connect(qPrefTechnicalDetails::instance(), &qPrefTechnicalDetails::calcceilingChanged, this, &DiveCalculatedCeiling::setVisible); @@ -836,8 +823,8 @@ void DiveCalculatedCeiling::modelDataChanged(const QModelIndex &topLeft, const Q QPointF p1 = poly.first(); QPointF p2 = poly.last(); - poly.prepend(QPointF(p1.x(), vAxis->posAtValue(0))); - poly.append(QPointF(p2.x(), vAxis->posAtValue(0))); + poly.prepend(QPointF(p1.x(), vAxis.posAtValue(0))); + poly.append(QPointF(p2.x(), vAxis.posAtValue(0))); setPolygon(poly); QLinearGradient pat(0, polygon().boundingRect().top(), 0, polygon().boundingRect().bottom()); @@ -854,8 +841,8 @@ void DiveCalculatedCeiling::paint(QPainter *painter, const QStyleOptionGraphicsI QGraphicsPolygonItem::paint(painter, option, widget); } -DiveCalculatedTissue::DiveCalculatedTissue(const DivePlotDataModel &model, ProfileWidget2 *widget) : - DiveCalculatedCeiling(model, widget) +DiveCalculatedTissue::DiveCalculatedTissue(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn, ProfileWidget2 *widget) : + DiveCalculatedCeiling(model, hAxis, hColumn, vAxis, vColumn, widget) { settingsChanged(); connect(qPrefTechnicalDetails::instance(), &qPrefTechnicalDetails::calcalltissuesChanged, this, &DiveCalculatedTissue::setVisible); @@ -872,7 +859,8 @@ void DiveCalculatedTissue::settingsChanged() DiveCalculatedCeiling::setVisible(prefs.calcalltissues && prefs.calcceiling); } -DiveReportedCeiling::DiveReportedCeiling(const DivePlotDataModel &model) : AbstractProfilePolygonItem(model) +DiveReportedCeiling::DiveReportedCeiling(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn) : + AbstractProfilePolygonItem(model, hAxis, hColumn, vAxis, vColumn) { connect(qPrefTechnicalDetails::instance(), &qPrefTechnicalDetails::dcceilingChanged, this, &DiveReportedCeiling::setVisible); setVisible(prefs.dcceiling); @@ -885,13 +873,13 @@ void DiveReportedCeiling::modelDataChanged(const QModelIndex &topLeft, const QMo return; QPolygonF p; - p.append(QPointF(hAxis->posAtValue(0), vAxis->posAtValue(0))); + p.append(QPointF(hAxis.posAtValue(0), vAxis.posAtValue(0))); plot_data *entry = dataModel.data().entry; for (int i = 0, count = dataModel.rowCount(); i < count; i++, entry++) { if (entry->in_deco && entry->stopdepth) { - p.append(QPointF(hAxis->posAtValue(entry->sec), vAxis->posAtValue(qMin(entry->stopdepth, entry->depth)))); + p.append(QPointF(hAxis.posAtValue(entry->sec), vAxis.posAtValue(qMin(entry->stopdepth, entry->depth)))); } else { - p.append(QPointF(hAxis->posAtValue(entry->sec), vAxis->posAtValue(0))); + p.append(QPointF(hAxis.posAtValue(entry->sec), vAxis.posAtValue(0))); } } setPolygon(p); @@ -935,7 +923,7 @@ void PartialPressureGasItem::modelDataChanged(const QModelIndex &topLeft, const for (int i = 0; i < dataModel.rowCount(); i++, entry++) { double value = dataModel.index(i, vDataColumn).data().toDouble(); int time = dataModel.index(i, hDataColumn).data().toInt(); - QPointF point(hAxis->posAtValue(time), vAxis->posAtValue(value)); + QPointF point(hAxis.posAtValue(time), vAxis.posAtValue(value)); poly.push_back(point); if (thresholdPtrMax && value >= threshold_max) { if (inAlertFragment) { @@ -985,8 +973,8 @@ void PartialPressureGasItem::setThresholdSettingsKey(const double *prefPointerMi thresholdPtrMax = prefPointerMax; } -PartialPressureGasItem::PartialPressureGasItem(const DivePlotDataModel &model) : - AbstractProfilePolygonItem(model), +PartialPressureGasItem::PartialPressureGasItem(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn) : + AbstractProfilePolygonItem(model, hAxis, hColumn, vAxis, vColumn), thresholdPtrMin(NULL), thresholdPtrMax(NULL) { diff --git a/profile-widget/diveprofileitem.h b/profile-widget/diveprofileitem.h index d7a9ccf92..e66f337af 100644 --- a/profile-widget/diveprofileitem.h +++ b/profile-widget/diveprofileitem.h @@ -35,17 +35,14 @@ class AbstractProfilePolygonItem : public QObject, public QGraphicsPolygonItem { Q_PROPERTY(qreal x WRITE setX READ x) Q_PROPERTY(qreal y WRITE setY READ y) public: - AbstractProfilePolygonItem(const DivePlotDataModel &model); - void setVerticalAxis(DiveCartesianAxis *vertical); - void setHorizontalAxis(DiveCartesianAxis *horizontal); - void setHorizontalDataColumn(int column); - void setVerticalDataColumn(int column); + 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; public slots: virtual void settingsChanged(); virtual void modelDataChanged(const QModelIndex &topLeft = QModelIndex(), const QModelIndex &bottomRight = QModelIndex()); virtual void modelDataRemoved(const QModelIndex &parent, int from, int to); + void replot(); void setVisible(bool visible); protected: @@ -58,8 +55,8 @@ protected: */ bool shouldCalculateStuff(const QModelIndex &topLeft, const QModelIndex &bottomRight); - DiveCartesianAxis *hAxis; - DiveCartesianAxis *vAxis; + const DiveCartesianAxis &hAxis; + const DiveCartesianAxis &vAxis; const DivePlotDataModel &dataModel; int hDataColumn; int vDataColumn; @@ -70,7 +67,7 @@ class DiveProfileItem : public AbstractProfilePolygonItem { Q_OBJECT public: - DiveProfileItem(const DivePlotDataModel &model); + 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 modelDataChanged(const QModelIndex &topLeft = QModelIndex(), const QModelIndex &bottomRight = QModelIndex()) override; void settingsToggled(bool toggled); @@ -87,7 +84,7 @@ private: class DiveMeanDepthItem : public AbstractProfilePolygonItem { Q_OBJECT public: - DiveMeanDepthItem(const DivePlotDataModel &model); + DiveMeanDepthItem(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn); void modelDataChanged(const QModelIndex &topLeft = QModelIndex(), const QModelIndex &bottomRight = QModelIndex()) override; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override; @@ -100,7 +97,7 @@ private: class DiveTemperatureItem : public AbstractProfilePolygonItem { Q_OBJECT public: - DiveTemperatureItem(const DivePlotDataModel &model); + DiveTemperatureItem(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn); void modelDataChanged(const QModelIndex &topLeft = QModelIndex(), const QModelIndex &bottomRight = QModelIndex()) override; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override; @@ -111,7 +108,7 @@ private: class DiveHeartrateItem : public AbstractProfilePolygonItem { Q_OBJECT public: - DiveHeartrateItem(const DivePlotDataModel &model); + DiveHeartrateItem(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn); void modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) override; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override; @@ -123,7 +120,7 @@ private: class DivePercentageItem : public AbstractProfilePolygonItem { Q_OBJECT public: - DivePercentageItem(const DivePlotDataModel &model, int i); + DivePercentageItem(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn, int i); void modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) override; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override; @@ -137,7 +134,7 @@ private: class DiveAmbPressureItem : public AbstractProfilePolygonItem { Q_OBJECT public: - DiveAmbPressureItem(const DivePlotDataModel &model); + DiveAmbPressureItem(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn); void modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) override; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override; @@ -148,7 +145,7 @@ private: class DiveGFLineItem : public AbstractProfilePolygonItem { Q_OBJECT public: - DiveGFLineItem(const DivePlotDataModel &model); + DiveGFLineItem(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn); void modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) override; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override; @@ -174,7 +171,8 @@ class DiveCalculatedCeiling : public AbstractProfilePolygonItem { Q_OBJECT public: - DiveCalculatedCeiling(const DivePlotDataModel &model, ProfileWidget2 *profileWidget); + DiveCalculatedCeiling(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, + const DiveCartesianAxis &vAxis, int vColumn, ProfileWidget2 *profileWidget); void modelDataChanged(const QModelIndex &topLeft = QModelIndex(), const QModelIndex &bottomRight = QModelIndex()) override; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override; @@ -186,7 +184,7 @@ class DiveReportedCeiling : public AbstractProfilePolygonItem { Q_OBJECT public: - DiveReportedCeiling(const DivePlotDataModel &model); + DiveReportedCeiling(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn); void modelDataChanged(const QModelIndex &topLeft = QModelIndex(), const QModelIndex &bottomRight = QModelIndex()) override; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override; }; @@ -194,7 +192,8 @@ public: class DiveCalculatedTissue : public DiveCalculatedCeiling { Q_OBJECT public: - DiveCalculatedTissue(const DivePlotDataModel &model, ProfileWidget2 *profileWidget); + DiveCalculatedTissue(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, + const DiveCartesianAxis &vAxis, int vColumn, ProfileWidget2 *profileWidget); void setVisible(bool visible); void settingsChanged() override; }; @@ -202,7 +201,7 @@ public: class PartialPressureGasItem : public AbstractProfilePolygonItem { Q_OBJECT public: - PartialPressureGasItem(const DivePlotDataModel &model); + 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 modelDataChanged(const QModelIndex &topLeft = QModelIndex(), const QModelIndex &bottomRight = QModelIndex()) override; void setThresholdSettingsKey(const double *prefPointerMin, const double *prefPointerMax); diff --git a/profile-widget/profilewidget2.cpp b/profile-widget/profilewidget2.cpp index 5e4924169..464cb515a 100644 --- a/profile-widget/profilewidget2.cpp +++ b/profile-widget/profilewidget2.cpp @@ -111,29 +111,29 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) : QGraphicsView(parent), gasYAxis(new PartialGasPressureAxis(this)), temperatureAxis(new TemperatureAxis(this)), timeAxis(new TimeAxis(this)), - diveProfileItem(new DiveProfileItem(*dataModel)), - temperatureItem(new DiveTemperatureItem(*dataModel)), - meanDepthItem(new DiveMeanDepthItem(*dataModel)), + diveProfileItem(new DiveProfileItem(*dataModel, *timeAxis, DivePlotDataModel::TIME, *profileYAxis, DivePlotDataModel::DEPTH)), + temperatureItem(new DiveTemperatureItem(*dataModel, *timeAxis, DivePlotDataModel::TIME, *temperatureAxis, DivePlotDataModel::TEMPERATURE)), + meanDepthItem(new DiveMeanDepthItem(*dataModel, *timeAxis, DivePlotDataModel::TIME, *profileYAxis, DivePlotDataModel::INSTANT_MEANDEPTH)), cylinderPressureAxis(new DiveCartesianAxis(this)), - gasPressureItem(new DiveGasPressureItem(*dataModel)), + gasPressureItem(new DiveGasPressureItem(*dataModel, *timeAxis, DivePlotDataModel::TIME, *cylinderPressureAxis, DivePlotDataModel::TEMPERATURE)), diveComputerText(new DiveTextItem()), - reportedCeiling(new DiveReportedCeiling(*dataModel)), - pn2GasItem(new PartialPressureGasItem(*dataModel)), - pheGasItem(new PartialPressureGasItem(*dataModel)), - po2GasItem(new PartialPressureGasItem(*dataModel)), - o2SetpointGasItem(new PartialPressureGasItem(*dataModel)), - ccrsensor1GasItem(new PartialPressureGasItem(*dataModel)), - ccrsensor2GasItem(new PartialPressureGasItem(*dataModel)), - ccrsensor3GasItem(new PartialPressureGasItem(*dataModel)), - ocpo2GasItem(new PartialPressureGasItem(*dataModel)), + reportedCeiling(new DiveReportedCeiling(*dataModel, *timeAxis, DivePlotDataModel::TIME, *profileYAxis, DivePlotDataModel::CEILING)), + pn2GasItem(new PartialPressureGasItem(*dataModel, *timeAxis, DivePlotDataModel::TIME, *gasYAxis, DivePlotDataModel::PN2)), + pheGasItem(new PartialPressureGasItem(*dataModel, *timeAxis, DivePlotDataModel::TIME, *gasYAxis, DivePlotDataModel::PHE)), + po2GasItem(new PartialPressureGasItem(*dataModel, *timeAxis, DivePlotDataModel::TIME, *gasYAxis, DivePlotDataModel::PO2)), + o2SetpointGasItem(new PartialPressureGasItem(*dataModel, *timeAxis, DivePlotDataModel::TIME, *gasYAxis, DivePlotDataModel::O2SETPOINT)), + ccrsensor1GasItem(new PartialPressureGasItem(*dataModel, *timeAxis, DivePlotDataModel::TIME, *gasYAxis, DivePlotDataModel::CCRSENSOR1)), + ccrsensor2GasItem(new PartialPressureGasItem(*dataModel, *timeAxis, DivePlotDataModel::TIME, *gasYAxis, DivePlotDataModel::CCRSENSOR2)), + ccrsensor3GasItem(new PartialPressureGasItem(*dataModel, *timeAxis, DivePlotDataModel::TIME, *gasYAxis, DivePlotDataModel::CCRSENSOR3)), + ocpo2GasItem(new PartialPressureGasItem(*dataModel, *timeAxis, DivePlotDataModel::TIME, *gasYAxis, DivePlotDataModel::SCR_OC_PO2)), #ifndef SUBSURFACE_MOBILE - diveCeiling(new DiveCalculatedCeiling(*dataModel, this)), + diveCeiling(new DiveCalculatedCeiling(*dataModel, *timeAxis, DivePlotDataModel::TIME, *profileYAxis, DivePlotDataModel::CEILING, this)), decoModelParameters(new DiveTextItem()), heartBeatAxis(new DiveCartesianAxis(this)), - heartBeatItem(new DiveHeartrateItem(*dataModel)), + heartBeatItem(new DiveHeartrateItem(*dataModel, *timeAxis, DivePlotDataModel::TIME, *heartBeatAxis, DivePlotDataModel::HEARTBEAT)), percentageAxis(new DiveCartesianAxis(this)), - ambPressureItem(new DiveAmbPressureItem(*dataModel)), - gflineItem(new DiveGFLineItem(*dataModel)), + ambPressureItem(new DiveAmbPressureItem(*dataModel, *timeAxis, DivePlotDataModel::TIME, *percentageAxis, DivePlotDataModel::AMBPRESSURE)), + gflineItem(new DiveGFLineItem(*dataModel, *timeAxis, DivePlotDataModel::TIME, *percentageAxis, DivePlotDataModel::GFLINE)), mouseFollowerVertical(new DiveLineItem()), mouseFollowerHorizontal(new DiveLineItem()), rulerItem(new RulerItem2()), @@ -340,33 +340,33 @@ void ProfileWidget2::setupItemOnScene() decoModelParameters->setX(50); decoModelParameters->setBrush(getColor(PRESSURE_TEXT)); decoModelParameters->setAlignment(Qt::AlignHCenter | Qt::AlignBottom); - setupItem(diveCeiling, profileYAxis, DivePlotDataModel::CEILING, DivePlotDataModel::TIME, 1); + setupItem(diveCeiling, 1); for (int i = 0; i < 16; i++) { - DiveCalculatedTissue *tissueItem = new DiveCalculatedTissue(*dataModel, this); - setupItem(tissueItem, profileYAxis, DivePlotDataModel::TISSUE_1 + i, DivePlotDataModel::TIME, 1 + i); + DiveCalculatedTissue *tissueItem = new DiveCalculatedTissue(*dataModel, *timeAxis, DivePlotDataModel::TIME, *profileYAxis, DivePlotDataModel::TISSUE_1 + i, this); + setupItem(tissueItem, 1 + i); allTissues.append(tissueItem); - DivePercentageItem *percentageItem = new DivePercentageItem(*dataModel, i); - setupItem(percentageItem, percentageAxis, DivePlotDataModel::PERCENTAGE_1 + i, DivePlotDataModel::TIME, 1 + i); + DivePercentageItem *percentageItem = new DivePercentageItem(*dataModel, *timeAxis, DivePlotDataModel::TIME, *percentageAxis, DivePlotDataModel::PERCENTAGE_1 + i, i); + setupItem(percentageItem, 1 + i); allPercentages.append(percentageItem); } - setupItem(heartBeatItem, heartBeatAxis, DivePlotDataModel::HEARTBEAT, DivePlotDataModel::TIME, 1); - setupItem(ambPressureItem, percentageAxis, DivePlotDataModel::AMBPRESSURE, DivePlotDataModel::TIME, 1); - setupItem(gflineItem, percentageAxis, DivePlotDataModel::GFLINE, DivePlotDataModel::TIME, 1); + setupItem(heartBeatItem, 1); + setupItem(ambPressureItem, 1); + setupItem(gflineItem, 1); #endif - setupItem(reportedCeiling, profileYAxis, DivePlotDataModel::CEILING, DivePlotDataModel::TIME, 1); - setupItem(gasPressureItem, cylinderPressureAxis, DivePlotDataModel::TEMPERATURE, DivePlotDataModel::TIME, 1); - setupItem(temperatureItem, temperatureAxis, DivePlotDataModel::TEMPERATURE, DivePlotDataModel::TIME, 1); - setupItem(diveProfileItem, profileYAxis, DivePlotDataModel::DEPTH, DivePlotDataModel::TIME, 0); - setupItem(meanDepthItem, profileYAxis, DivePlotDataModel::INSTANT_MEANDEPTH, DivePlotDataModel::TIME, 1); - - createPPGas(pn2GasItem, DivePlotDataModel::PN2, PN2, PN2_ALERT, NULL, &prefs.pp_graphs.pn2_threshold); - createPPGas(pheGasItem, DivePlotDataModel::PHE, PHE, PHE_ALERT, NULL, &prefs.pp_graphs.phe_threshold); - createPPGas(po2GasItem, DivePlotDataModel::PO2, PO2, PO2_ALERT, &prefs.pp_graphs.po2_threshold_min, &prefs.pp_graphs.po2_threshold_max); - createPPGas(o2SetpointGasItem, DivePlotDataModel::O2SETPOINT, O2SETPOINT, PO2_ALERT, &prefs.pp_graphs.po2_threshold_min, &prefs.pp_graphs.po2_threshold_max); - createPPGas(ccrsensor1GasItem, DivePlotDataModel::CCRSENSOR1, CCRSENSOR1, PO2_ALERT, &prefs.pp_graphs.po2_threshold_min, &prefs.pp_graphs.po2_threshold_max); - createPPGas(ccrsensor2GasItem, DivePlotDataModel::CCRSENSOR2, CCRSENSOR2, PO2_ALERT, &prefs.pp_graphs.po2_threshold_min, &prefs.pp_graphs.po2_threshold_max); - createPPGas(ccrsensor3GasItem, DivePlotDataModel::CCRSENSOR3, CCRSENSOR3, PO2_ALERT, &prefs.pp_graphs.po2_threshold_min, &prefs.pp_graphs.po2_threshold_max); - createPPGas(ocpo2GasItem, DivePlotDataModel::SCR_OC_PO2, SCR_OCPO2, PO2_ALERT, &prefs.pp_graphs.po2_threshold_min, &prefs.pp_graphs.po2_threshold_max); + setupItem(reportedCeiling, 1); + setupItem(gasPressureItem, 1); + setupItem(temperatureItem, 1); + setupItem(diveProfileItem, 0); + 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 #ifndef SUBSURFACE_MOBILE @@ -402,10 +402,10 @@ void ProfileWidget2::replot() plotDive(current_dive, true, false); } -void ProfileWidget2::createPPGas(PartialPressureGasItem *item, int verticalColumn, color_index_t color, color_index_t colorAlert, +void ProfileWidget2::createPPGas(PartialPressureGasItem *item, color_index_t color, color_index_t colorAlert, const double *thresholdSettingsMin, const double *thresholdSettingsMax) { - setupItem(item, gasYAxis, verticalColumn, DivePlotDataModel::TIME, 0); + setupItem(item, 0); item->setThresholdSettingsKey(thresholdSettingsMin, thresholdSettingsMax); item->setColors(getColor(color, isGrayscale), getColor(colorAlert, isGrayscale)); item->settingsChanged(); @@ -537,13 +537,8 @@ void ProfileWidget2::setupItemSizes() #endif } -void ProfileWidget2::setupItem(AbstractProfilePolygonItem *item, DiveCartesianAxis *vAxis, - int vData, int hData, int zValue) +void ProfileWidget2::setupItem(AbstractProfilePolygonItem *item, int zValue) { - item->setHorizontalAxis(timeAxis); - item->setVerticalAxis(vAxis); - item->setVerticalDataColumn(vData); - item->setHorizontalDataColumn(hData); item->setZValue(zValue); } diff --git a/profile-widget/profilewidget2.h b/profile-widget/profilewidget2.h index f077eb9e4..ff70c4c0e 100644 --- a/profile-widget/profilewidget2.h +++ b/profile-widget/profilewidget2.h @@ -78,7 +78,7 @@ public: void resetZoom(); void scale(qreal sx, qreal sy); void plotDive(const struct dive *d, bool force = false, bool clearPictures = false, bool instant = false); - void setupItem(AbstractProfilePolygonItem *item, DiveCartesianAxis *vAxis, int vData, int hData, int zValue); + void setupItem(AbstractProfilePolygonItem *item, int zValue); void setPrintMode(bool mode, bool grayscale = false); bool getPrintMode(); bool isPointOutOfBoundaries(const QPointF &point) const; @@ -158,7 +158,7 @@ private: void disconnectTemporaryConnections(); struct plot_data *getEntryFromPos(QPointF pos); void addActionShortcut(const Qt::Key shortcut, void (ProfileWidget2::*slot)()); - void createPPGas(PartialPressureGasItem *item, int verticalColumn, color_index_t color, color_index_t colorAlert, + void createPPGas(PartialPressureGasItem *item, color_index_t color, color_index_t colorAlert, const double *thresholdSettingsMin, const double *thresholdSettingsMax); void clearPictures(); void plotPicturesInternal(const struct dive *d, bool synchronous); |