diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2021-01-03 23:18:48 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2021-01-10 15:57:39 -0800 |
commit | acee77e516bc77cd49a57b5aac620833ea655eb6 (patch) | |
tree | bf2ef5c8cee16bfdad7eb727d7d7d7a5e428d8cc /profile-widget/diveprofileitem.cpp | |
parent | 0146a0c8925e243d808a4e5488d068d6f8f065b6 (diff) | |
download | subsurface-acee77e516bc77cd49a57b5aac620833ea655eb6.tar.gz |
profile: move calculations out of DivePercentageItem::paint()
The DivePercentageItem is a polygon-item with a custom paint()
method. Calculation of the polygon is done once in replot(),
but calculation of the corresponding colors is done in every
paint() call. The problem is, we have no control over paint().
It is called whenever Qt feels like. Therefore using live
dive data is a dangerous proposition if we ever want to get
rid of the global displayed_dive.
Do all the calculations in replot(). Store the colors in an
additional array of the same size as the polygon.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'profile-widget/diveprofileitem.cpp')
-rw-r--r-- | profile-widget/diveprofileitem.cpp | 28 |
1 files changed, 13 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(); } |