diff options
author | Tomaz Canabrava <tcanabrava@kde.org> | 2014-01-17 15:34:15 -0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-01-17 14:04:47 -0800 |
commit | 4ff73cf5370a3233a4caf29ded6e738e3d02b3a0 (patch) | |
tree | 24766d2a532522a7f1a0d94ac7ae471c1b244cc1 /qt-ui | |
parent | 779c1b6738c4378be79a46b744da2c556380ca32 (diff) | |
download | subsurface-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')
-rw-r--r-- | qt-ui/profile/diveplotdatamodel.cpp | 18 | ||||
-rw-r--r-- | qt-ui/profile/diveplotdatamodel.h | 2 | ||||
-rw-r--r-- | qt-ui/profile/diveprofileitem.cpp | 50 | ||||
-rw-r--r-- | qt-ui/profile/diveprofileitem.h | 8 | ||||
-rw-r--r-- | qt-ui/profile/profilewidget2.cpp | 14 | ||||
-rw-r--r-- | qt-ui/profile/profilewidget2.h | 2 |
6 files changed, 80 insertions, 14 deletions
diff --git a/qt-ui/profile/diveplotdatamodel.cpp b/qt-ui/profile/diveplotdatamodel.cpp index 09985b1ca..32067d3e0 100644 --- a/qt-ui/profile/diveplotdatamodel.cpp +++ b/qt-ui/profile/diveplotdatamodel.cpp @@ -34,6 +34,7 @@ QVariant DivePlotDataModel::data(const QModelIndex& index, int role) const case CYLINDERINDEX: return item.cylinderindex; case SENSOR_PRESSURE: return item.pressure[0]; case INTERPOLATED_PRESSURE: return item.pressure[1]; + case SAC: return item.sac; } } if (role == Qt::BackgroundRole) { @@ -65,8 +66,9 @@ QVariant DivePlotDataModel::headerData(int section, Qt::Orientation orientation, case COLOR: return tr("Color"); case USERENTERED: return tr("User Entered"); case CYLINDERINDEX: return tr("Cylinder Index"); - case SENSOR_PRESSURE: return tr("Sensor Pressure"); - case INTERPOLATED_PRESSURE: return tr("Interpolated Pressure"); + case SENSOR_PRESSURE: return tr("Pressure S"); + case INTERPOLATED_PRESSURE: return tr("Pressure I"); + case SAC: return tr("SAC"); } return QVariant(); } @@ -88,16 +90,8 @@ void DivePlotDataModel::setDive(dive* d,const plot_info& pInfo) if (d) dc = select_dc(&d->dc); - - /* Create the new plot data */ - if (plotData) - free((void *)plotData); - - plot_info info = pInfo; - plotData = populate_plot_entries(d, dc, &info); // Create the plot data. - analyze_plot_info(&info); // Get the Velocity Color information. - - sampleCount = info.nr; + plotData = pInfo.entry; + sampleCount = pInfo.nr; beginInsertRows(QModelIndex(), 0, sampleCount-1); endInsertRows(); } diff --git a/qt-ui/profile/diveplotdatamodel.h b/qt-ui/profile/diveplotdatamodel.h index 6d7191953..dc032734e 100644 --- a/qt-ui/profile/diveplotdatamodel.h +++ b/qt-ui/profile/diveplotdatamodel.h @@ -10,7 +10,7 @@ struct plot_info; class DivePlotDataModel : public QAbstractTableModel{ Q_OBJECT public: - enum {DEPTH, TIME, PRESSURE, TEMPERATURE, USERENTERED, COLOR, CYLINDERINDEX, SENSOR_PRESSURE, INTERPOLATED_PRESSURE, COLUMNS}; + enum {DEPTH, TIME, PRESSURE, TEMPERATURE, USERENTERED, COLOR, CYLINDERINDEX, SENSOR_PRESSURE, INTERPOLATED_PRESSURE, SAC, COLUMNS}; explicit DivePlotDataModel(QObject* parent = 0); virtual int columnCount(const QModelIndex& parent = QModelIndex()) const; virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; 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 diff --git a/qt-ui/profile/diveprofileitem.h b/qt-ui/profile/diveprofileitem.h index 9d2893a65..ddecef947 100644 --- a/qt-ui/profile/diveprofileitem.h +++ b/qt-ui/profile/diveprofileitem.h @@ -59,4 +59,12 @@ public: virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0); }; +class DiveGasPressureItem : public AbstractProfilePolygonItem{ + Q_OBJECT +public: + virtual void modelDataChanged(); + virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0); +private: + QVector<QPolygonF> polygons; +}; #endif
\ No newline at end of file diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp index 3970e6f3a..201c68f41 100644 --- a/qt-ui/profile/profilewidget2.cpp +++ b/qt-ui/profile/profilewidget2.cpp @@ -70,7 +70,7 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) : temperatureAxis->setTickSize(2); temperatureAxis->setTickInterval(300); - cylinderPressureAxis->setOrientation(DiveCartesianAxis::TopToBottom); + cylinderPressureAxis->setOrientation(DiveCartesianAxis::BottomToTop); cylinderPressureAxis->setLine(0,20,0,60); cylinderPressureAxis->setX(3); cylinderPressureAxis->setTickSize(2); @@ -336,6 +336,18 @@ void ProfileWidget2::plotDives(QList<dive*> dives) temperatureItem->setHorizontalDataColumn(DivePlotDataModel::TIME); scene()->addItem(temperatureItem); + if(gasPressureItem){ + scene()->removeItem(gasPressureItem); + delete gasPressureItem; + } + gasPressureItem = new DiveGasPressureItem(); + gasPressureItem->setHorizontalAxis(timeAxis); + gasPressureItem->setVerticalAxis(cylinderPressureAxis); + gasPressureItem->setModel(dataModel); + gasPressureItem->setVerticalDataColumn(DivePlotDataModel::TEMPERATURE); + gasPressureItem->setHorizontalDataColumn(DivePlotDataModel::TIME); + scene()->addItem(gasPressureItem); + emit startProfileState(); } diff --git a/qt-ui/profile/profilewidget2.h b/qt-ui/profile/profilewidget2.h index b5d9f0a31..5f988651d 100644 --- a/qt-ui/profile/profilewidget2.h +++ b/qt-ui/profile/profilewidget2.h @@ -29,6 +29,7 @@ struct QStateMachine; struct DiveCartesianPlane; struct DiveTemperatureItem; struct plot_info; +struct DiveGasPressureItem; class ProfileWidget2 : public QGraphicsView { Q_OBJECT @@ -76,6 +77,7 @@ private: DiveCartesianPlane *cartesianPlane; DiveTemperatureItem *temperatureItem; DiveCartesianAxis *cylinderPressureAxis; + DiveGasPressureItem *gasPressureItem; QList<DiveEventItem*> eventItems; }; |