From 4ff73cf5370a3233a4caf29ded6e738e3d02b3a0 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Fri, 17 Jan 2014 15:34:15 -0200 Subject: Add the gas pressure plot. Added the Gas Pressure Graph with the related Model Changes to access the cylinder index, pressure, interpolated pressure and SAC. The plot does not correctly plot its color right now but it's not hard to do. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- qt-ui/profile/diveprofileitem.cpp | 50 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'qt-ui/profile/diveprofileitem.cpp') diff --git a/qt-ui/profile/diveprofileitem.cpp b/qt-ui/profile/diveprofileitem.cpp index 44a3feb5e..3e6b05a09 100644 --- a/qt-ui/profile/diveprofileitem.cpp +++ b/qt-ui/profile/diveprofileitem.cpp @@ -2,6 +2,7 @@ #include "diveplotdatamodel.h" #include "divecartesianaxis.h" #include "graphicsview-common.h" +#include "profile.h" #include #include @@ -132,3 +133,52 @@ void DiveTemperatureItem::paint(QPainter* painter, const QStyleOptionGraphicsIte painter->setPen(pen()); painter->drawPolyline(polygon()); } + + +void DiveGasPressureItem::modelDataChanged() +{ + // We don't have enougth data to calculate things, quit. + if (!hAxis || !vAxis || !dataModel || hDataColumn == -1 || vDataColumn == -1) + return; + int last_index = -1; + int lift_pen = false; + int first_plot = true; + QPolygonF boundingPoly; // This is the "Whole Item", but a pressure can be divided in N Polygons. + polygons.clear(); + +#define M_PRESSURE( ROW ) + for (int i = 0; i < dataModel->rowCount(); i++) { + int sPressure = dataModel->index(i, DivePlotDataModel::SENSOR_PRESSURE).data().toInt(); + int iPressure = dataModel->index(i, DivePlotDataModel::INTERPOLATED_PRESSURE).data().toInt(); + int cylIndex = dataModel->index(i, DivePlotDataModel::CYLINDERINDEX).data().toInt(); + int sec = dataModel->index(i, DivePlotDataModel::TIME).data().toInt(); + int mbar = sPressure ? sPressure : iPressure; + + if (cylIndex != last_index) { + polygons.append(QPolygonF()); // this is the polygon that will be actually drawned on screen. + last_index = cylIndex; + } + if (!mbar) { + continue; + } + + QPointF point(hAxis->posAtValue(sec), vAxis->posAtValue(mbar)); + boundingPoly.push_back(point); // The BoundingRect + polygons.last().push_back(point); // The polygon thta will be plotted. + } + setPolygon(boundingPoly); +} + +void DiveGasPressureItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) +{ + QPen pen; + pen.setCosmetic(true); + pen.setWidth(2); + Q_FOREACH(const QPolygonF& poly, polygons){ + for (int i = 1, count = poly.count(); i < count; i++) { + pen.setBrush(QBrush(Qt::red)); // TODO: Fix the color. + painter->setPen(pen); + painter->drawLine(poly[i-1],poly[i]); + } + } +} \ No newline at end of file -- cgit v1.2.3-70-g09d2