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>
This commit is contained in:
Tomaz Canabrava 2014-01-17 15:34:15 -02:00 committed by Dirk Hohndel
parent 779c1b6738
commit 4ff73cf537
6 changed files with 80 additions and 14 deletions

View file

@ -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();
}

View file

@ -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;

View file

@ -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]);
}
}
}

View file

@ -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

View file

@ -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();
}

View file

@ -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;
};