summaryrefslogtreecommitdiffstats
path: root/qt-ui/profile/diveprofileitem.cpp
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tcanabrava@kde.org>2014-01-17 15:34:15 -0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-01-17 14:04:47 -0800
commit4ff73cf5370a3233a4caf29ded6e738e3d02b3a0 (patch)
tree24766d2a532522a7f1a0d94ac7ae471c1b244cc1 /qt-ui/profile/diveprofileitem.cpp
parent779c1b6738c4378be79a46b744da2c556380ca32 (diff)
downloadsubsurface-4ff73cf5370a3233a4caf29ded6e738e3d02b3a0.tar.gz
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 <tcanabrava@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/profile/diveprofileitem.cpp')
-rw-r--r--qt-ui/profile/diveprofileitem.cpp50
1 files changed, 50 insertions, 0 deletions
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 <QPen>
#include <QPainter>
@@ -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