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 <jlmulder@planet.nl>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Jan Mulder 2014-03-15 19:00:58 +01:00 committed by Dirk Hohndel
parent ce6f2cdda4
commit aa0cd792bb
2 changed files with 21 additions and 5 deletions

View file

@ -636,17 +636,29 @@ void PartialPressureGasItem::modelDataChanged(const QModelIndex &topLeft, const
plot_data *entry = dataModel->data().entry; plot_data *entry = dataModel->data().entry;
QPolygonF poly; QPolygonF poly;
alertPoly.clear(); QPolygonF alertpoly;
alertPolygons.clear();
QSettings s; QSettings s;
s.beginGroup("TecDetails"); s.beginGroup("TecDetails");
double threshould = s.value(threshouldKey).toDouble(); double threshould = s.value(threshouldKey).toDouble();
bool inAlertFragment = false;
for (int i = 0; i < dataModel->rowCount(); i++, entry++) { for (int i = 0; i < dataModel->rowCount(); i++, entry++) {
double value = dataModel->index(i, vDataColumn).data().toDouble(); double value = dataModel->index(i, vDataColumn).data().toDouble();
int time = dataModel->index(i, hDataColumn).data().toInt(); 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); poly.push_back(point);
if (value >= threshould) if (value >= threshould) {
alertPoly.push_back(point); if (inAlertFragment) {
alertPolygons.back().push_back(point);
} else {
alertpoly.clear();
alertpoly.push_back(point);
alertPolygons.append(alertpoly);
inAlertFragment = true;
}
} else {
inAlertFragment = false;
}
} }
setPolygon(poly); setPolygon(poly);
/* /*
@ -658,8 +670,12 @@ void PartialPressureGasItem::paint(QPainter *painter, const QStyleOptionGraphics
{ {
painter->setPen(normalColor); painter->setPen(normalColor);
painter->drawPolyline(polygon()); painter->drawPolyline(polygon());
QPolygonF poly;
painter->setPen(alertColor); painter->setPen(alertColor);
painter->drawPolyline(alertPoly); Q_FOREACH(const QPolygonF & poly, alertPolygons)
painter->drawPolyline(poly);
} }
void PartialPressureGasItem::setThreshouldSettingsKey(const QString &threshouldSettingsKey) void PartialPressureGasItem::setThreshouldSettingsKey(const QString &threshouldSettingsKey)

View file

@ -177,7 +177,7 @@ public:
void setColors(const QColor &normalColor, const QColor &alertColor); void setColors(const QColor &normalColor, const QColor &alertColor);
private: private:
QPolygonF alertPoly; QVector<QPolygonF> alertPolygons;
QString threshouldKey; QString threshouldKey;
QString visibilityKey; QString visibilityKey;
QColor normalColor; QColor normalColor;