Add the DiveCalculatedCeiling item.

This item plots the DiveCalculatedCeiling over the profile. I still need
to add the Calc All Tissues version.

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-21 14:59:19 -02:00 committed by Dirk Hohndel
parent b1df7aeb4e
commit 8065374793
7 changed files with 56 additions and 3 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 CEILING: return item.ceiling;
case SAC: return item.sac;
}
}
@ -73,6 +74,7 @@ QVariant DivePlotDataModel::headerData(int section, Qt::Orientation orientation,
case CYLINDERINDEX: return tr("Cylinder Index");
case SENSOR_PRESSURE: return tr("Pressure S");
case INTERPOLATED_PRESSURE: return tr("Pressure I");
case CEILING: return tr("Ceiling");
case SAC: return tr("SAC");
}
return QVariant();

View file

@ -10,7 +10,8 @@ struct plot_info;
class DivePlotDataModel : public QAbstractTableModel{
Q_OBJECT
public:
enum {DEPTH, TIME, PRESSURE, TEMPERATURE, USERENTERED, COLOR, CYLINDERINDEX, SENSOR_PRESSURE, INTERPOLATED_PRESSURE, SAC, COLUMNS};
enum {DEPTH, TIME, PRESSURE, TEMPERATURE, USERENTERED, COLOR, CYLINDERINDEX, SENSOR_PRESSURE, INTERPOLATED_PRESSURE,
SAC, CEILING, 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

@ -318,3 +318,30 @@ void DiveGasPressureItem::paint(QPainter* painter, const QStyleOptionGraphicsIte
}
}
}
void DiveCalculatedCeiling::modelDataChanged()
{
// We don't have enougth data to calculate things, quit.
if (!hAxis || !vAxis || !dataModel || hDataColumn == -1 || vDataColumn == -1)
return;
AbstractProfilePolygonItem::modelDataChanged();
// Add 2 points to close the polygon.
QPolygonF poly = polygon();
QPointF p1 = poly.first();
QPointF p2 = poly.last();
poly.prepend(QPointF(p1.x(), vAxis->posAtValue(0)));
poly.append(QPointF(p2.x(), vAxis->posAtValue(0)));
setPolygon(poly);
QLinearGradient pat(0, polygon().boundingRect().top(), 0, polygon().boundingRect().bottom());
pat.setColorAt(0, getColor(CALC_CEILING_SHALLOW));
pat.setColorAt(1, getColor(CALC_CEILING_DEEP));
setPen(QPen(QBrush(Qt::NoBrush),0));
setBrush(pat);
}
void DiveCalculatedCeiling::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
{
QGraphicsPolygonItem::paint(painter, option, widget);
}

View file

@ -65,7 +65,6 @@ public:
virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0);
private:
void createTextItem(int seconds, int mkelvin);
QList<DiveTextItem*> texts;
};
class DiveGasPressureItem : public AbstractProfilePolygonItem{
@ -80,4 +79,12 @@ private:
QVector<QPolygonF> polygons;
};
class DiveCalculatedCeiling : public AbstractProfilePolygonItem{
Q_OBJECT
public:
virtual void modelDataChanged();
virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0);
};
#endif

View file

@ -38,7 +38,8 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) :
gasPressureItem(NULL),
cartesianPlane(new DiveCartesianPlane()),
meanDepth(new DiveLineItem()),
diveComputerText(new DiveTextItem())
diveComputerText(new DiveTextItem()),
diveCeiling(NULL)
{
setScene(new QGraphicsScene());
scene()->setSceneRect(0, 0, 100, 100);
@ -358,6 +359,18 @@ void ProfileWidget2::plotDives(QList<dive*> dives)
gasPressureItem->setHorizontalDataColumn(DivePlotDataModel::TIME);
scene()->addItem(gasPressureItem);
if(diveCeiling){
scene()->removeItem(diveCeiling);
delete diveCeiling;
}
diveCeiling = new DiveCalculatedCeiling();
diveCeiling->setHorizontalAxis(timeAxis);
diveCeiling->setVerticalAxis(profileYAxis);
diveCeiling->setModel(dataModel);
diveCeiling->setVerticalDataColumn(DivePlotDataModel::CEILING);
diveCeiling->setHorizontalDataColumn(DivePlotDataModel::TIME);
scene()->addItem(diveCeiling);
diveComputerText->setText(currentdc->model);
diveComputerText->animateMoveTo(1 , sceneRect().height());

View file

@ -32,6 +32,7 @@ struct DiveCartesianPlane;
struct DiveTemperatureItem;
struct plot_info;
struct DiveGasPressureItem;
struct DiveCalculatedCeiling;
class ProfileWidget2 : public QGraphicsView {
Q_OBJECT
@ -83,6 +84,7 @@ private:
DiveLineItem *meanDepth;
QList<DiveEventItem*> eventItems;
DiveTextItem *diveComputerText;
DiveCalculatedCeiling *diveCeiling;
};
#endif

View file

@ -1312,6 +1312,7 @@ void ProfileGraphicsView::plot_depth_profile()
scene()->addItem(neatFill);
}
}
/* next show where we have been bad and crossed the dc's ceiling */
if (prefs.profile_dc_ceiling) {
pat.setColorAt(0, getColor(CEILING_SHALLOW));