From aa0cd792bbe3e5c2dbaaaaff77688f4ee96c694c Mon Sep 17 00:00:00 2001 From: Jan Mulder Date: Sat, 15 Mar 2014 19:00:58 +0100 Subject: [PATCH] Bugfix: generalize pp graphs to allow for multi over-threshold periods Especially in O2 decompression parts of a dive, the pp02 is typically very close to the threshold value (normally 1.60 bar). The old implementation of the pp profile graphs assumes that there is exacty 1 consecutive set of samples that needs to be in the "warning color". This results in an erroneous display of the mentioned graphs, connecting multiple episodes of too high pp with bogus lines in between. This fix generalizes the pp graph logic to allow for multiple segments of high pp, each to been drawn seperately in the "warning color". Signed-off-by: Jan Mulder Signed-off-by: Dirk Hohndel --- qt-ui/profile/diveprofileitem.cpp | 24 ++++++++++++++++++++---- qt-ui/profile/diveprofileitem.h | 2 +- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/qt-ui/profile/diveprofileitem.cpp b/qt-ui/profile/diveprofileitem.cpp index b84f2928d..f42bbef50 100644 --- a/qt-ui/profile/diveprofileitem.cpp +++ b/qt-ui/profile/diveprofileitem.cpp @@ -636,17 +636,29 @@ void PartialPressureGasItem::modelDataChanged(const QModelIndex &topLeft, const plot_data *entry = dataModel->data().entry; QPolygonF poly; - alertPoly.clear(); + QPolygonF alertpoly; + alertPolygons.clear(); QSettings s; s.beginGroup("TecDetails"); double threshould = s.value(threshouldKey).toDouble(); + bool inAlertFragment = false; 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)); poly.push_back(point); - if (value >= threshould) - alertPoly.push_back(point); + if (value >= threshould) { + if (inAlertFragment) { + alertPolygons.back().push_back(point); + } else { + alertpoly.clear(); + alertpoly.push_back(point); + alertPolygons.append(alertpoly); + inAlertFragment = true; + } + } else { + inAlertFragment = false; + } } setPolygon(poly); /* @@ -658,8 +670,12 @@ void PartialPressureGasItem::paint(QPainter *painter, const QStyleOptionGraphics { painter->setPen(normalColor); painter->drawPolyline(polygon()); + + QPolygonF poly; painter->setPen(alertColor); - painter->drawPolyline(alertPoly); + Q_FOREACH(const QPolygonF & poly, alertPolygons) + painter->drawPolyline(poly); + } void PartialPressureGasItem::setThreshouldSettingsKey(const QString &threshouldSettingsKey) diff --git a/qt-ui/profile/diveprofileitem.h b/qt-ui/profile/diveprofileitem.h index ee7132c40..480776546 100644 --- a/qt-ui/profile/diveprofileitem.h +++ b/qt-ui/profile/diveprofileitem.h @@ -177,7 +177,7 @@ public: void setColors(const QColor &normalColor, const QColor &alertColor); private: - QPolygonF alertPoly; + QVector alertPolygons; QString threshouldKey; QString visibilityKey; QColor normalColor;