diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2021-01-04 00:00:38 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2021-01-10 15:57:39 -0800 |
commit | 0392994df0c9cd99df946633d6e318bd0548a3b9 (patch) | |
tree | a907006308ea681cb6a92bcd952a874a900be2f5 /profile-widget/diveprofileitem.cpp | |
parent | acee77e516bc77cd49a57b5aac620833ea655eb6 (diff) | |
download | subsurface-0392994df0c9cd99df946633d6e318bd0548a3b9.tar.gz |
profile: move calculations out of DiveGasPressureItem::paint()
With the same argument as for DivePercentageItem, move access
to live data out of the paint() function. Instead, calculate
colors in replot(), where the other data are calculated.
This is slightly more complicated than in DivePercentageItem,
since there are multiple polygons. Therefore, replace QPolygonF
by a vector of structures contained the position and color
of the data point.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'profile-widget/diveprofileitem.cpp')
-rw-r--r-- | profile-widget/diveprofileitem.cpp | 47 |
1 files changed, 24 insertions, 23 deletions
diff --git a/profile-widget/diveprofileitem.cpp b/profile-widget/diveprofileitem.cpp index c48f345b6..48bd02f51 100644 --- a/profile-widget/diveprofileitem.cpp +++ b/profile-widget/diveprofileitem.cpp @@ -569,7 +569,7 @@ void DiveGasPressureItem::replot() const struct plot_info *pInfo = &dataModel.data(); std::vector<int> plotted_cyl(pInfo->nr_cylinders, false); std::vector<int> last_plotted(pInfo->nr_cylinders, 0); - std::vector<QPolygonF> poly(pInfo->nr_cylinders); + std::vector<std::vector<Entry>> poly(pInfo->nr_cylinders); QPolygonF boundingPoly; polygons.clear(); @@ -586,29 +586,42 @@ void DiveGasPressureItem::replot() QPointF point(hAxis.posAtValue(time), vAxis.posAtValue(mbar)); boundingPoly.push_back(point); + QColor color; + if (!in_planner()) { + if (entry->sac) + color = getSacColor(entry->sac, displayed_dive.sac); + else + color = MED_GRAY_HIGH_TRANS; + } else { + if (mbar < 0) + color = MAGENTA; + else + color = getPressureColor(entry->density); + } + if (plotted_cyl[cyl]) { - /* Have we used this culinder in the last two minutes? Continue */ + /* Have we used this cylinder in the last two minutes? Continue */ if (time - last_plotted[cyl] <= 2*60) { - poly[cyl].push_back(point); + poly[cyl].push_back({ point, color }); last_plotted[cyl] = time; continue; } /* Finish the previous one, start a new one */ - polygons.append(poly[cyl]); - poly[cyl] = QPolygonF(); + polygons.push_back(std::move(poly[cyl])); + poly[cyl].clear(); } plotted_cyl[cyl] = true; last_plotted[cyl] = time; - poly[cyl].push_back(point); + poly[cyl].push_back({ point, color }); } } for (int cyl = 0; cyl < pInfo->nr_cylinders; cyl++) { if (!plotted_cyl[cyl]) continue; - polygons.append(poly[cyl]); + polygons.push_back(poly[cyl]); } setPolygon(boundingPoly); @@ -707,23 +720,11 @@ void DiveGasPressureItem::paint(QPainter *painter, const QStyleOptionGraphicsIte pen.setCosmetic(true); pen.setWidth(2); painter->save(); - struct plot_data *entry; - Q_FOREACH (const QPolygonF &poly, polygons) { - entry = dataModel.data().entry; - for (int i = 1, count = poly.count(); i < count; i++, entry++) { - if (!in_planner()) { - if (entry->sac) - pen.setBrush(getSacColor(entry->sac, displayed_dive.sac)); - else - pen.setBrush(MED_GRAY_HIGH_TRANS); - } else { - if (vAxis.valueAt(poly[i]) < 0) - pen.setBrush(MAGENTA); - else - pen.setBrush(getPressureColor(entry->density)); - } + for (const std::vector<Entry> &poly: polygons) { + for (size_t i = 1; i < poly.size(); i++) { + pen.setBrush(poly[i].col); painter->setPen(pen); - painter->drawLine(poly[i - 1], poly[i]); + painter->drawLine(poly[i - 1].pos, poly[i].pos); } } painter->restore(); |