diff options
-rw-r--r-- | profile-widget/diveprofileitem.cpp | 28 | ||||
-rw-r--r-- | profile-widget/diveprofileitem.h | 1 |
2 files changed, 14 insertions, 15 deletions
diff --git a/profile-widget/diveprofileitem.cpp b/profile-widget/diveprofileitem.cpp index f20d0bee3..c48f345b6 100644 --- a/profile-widget/diveprofileitem.cpp +++ b/profile-widget/diveprofileitem.cpp @@ -285,14 +285,20 @@ DivePercentageItem::DivePercentageItem(const DivePlotDataModel &model, const Div void DivePercentageItem::replot() { - int sec = 0; - // Ignore empty values. a heart rate of 0 would be a bad sign. QPolygonF poly; + colors.clear(); for (int i = 0, modelDataCount = dataModel.rowCount(); i < modelDataCount; i++) { - sec = dataModel.index(i, hDataColumn).data().toInt(); + int sec = dataModel.index(i, hDataColumn).data().toInt(); QPointF point(hAxis.posAtValue(sec), vAxis.posAtValue(64 - 4 * tissueIndex)); poly.append(point); + + double value = dataModel.index(i, vDataColumn).data().toDouble(); + struct gasmix gasmix = gasmix_air; + const struct event *ev = NULL; + gasmix = get_gasmix(&displayed_dive, displayed_dc, sec, &ev, gasmix); + int inert = get_n2(gasmix) + get_he(gasmix); + colors.push_back(ColorScale(value, inert)); } setPolygon(poly); @@ -333,18 +339,10 @@ void DivePercentageItem::paint(QPainter *painter, const QStyleOptionGraphicsItem mypen.setCapStyle(Qt::FlatCap); mypen.setCosmetic(false); QPolygonF poly = polygon(); - for (int i = 1, modelDataCount = dataModel.rowCount(); i < modelDataCount; i++) { - if (i < poly.count()) { - double value = dataModel.index(i, vDataColumn).data().toDouble(); - struct gasmix gasmix = gasmix_air; - const struct event *ev = NULL; - int sec = dataModel.index(i, DivePlotDataModel::TIME).data().toInt(); - gasmix = get_gasmix(&displayed_dive, displayed_dc, sec, &ev, gasmix); - int inert = get_n2(gasmix) + get_he(gasmix); - mypen.setBrush(QBrush(ColorScale(value, inert))); - painter->setPen(mypen); - painter->drawLine(poly[i - 1], poly[i]); - } + for (int i = 1; i < poly.count(); i++) { + mypen.setBrush(QBrush(colors[i])); + painter->setPen(mypen); + painter->drawLine(poly[i - 1], poly[i]); } painter->restore(); } diff --git a/profile-widget/diveprofileitem.h b/profile-widget/diveprofileitem.h index fc123c133..18902374a 100644 --- a/profile-widget/diveprofileitem.h +++ b/profile-widget/diveprofileitem.h @@ -122,6 +122,7 @@ public: void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override; private: + std::vector<QColor> colors; // Must have same number of elements as the polygon QString visibilityKey; int tissueIndex; QColor ColorScale(double value, int inert); |