From 58aeb6ce4014899e040a3ef8f4483f18fb44b432 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Thu, 16 Jan 2014 18:39:13 -0200 Subject: Added the Temperature Graph. Added the Temperature Graph with its related classes. A Temperature Axis is also created so the item is plotted on the right place. Currently the Temperature Axis is just like the depth axis - top is zero, wich means that the graph is inverted. Also, the Temperature axis is being displayed as this helps debugging. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- qt-ui/profile/diveprofileitem.cpp | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'qt-ui/profile/diveprofileitem.cpp') diff --git a/qt-ui/profile/diveprofileitem.cpp b/qt-ui/profile/diveprofileitem.cpp index 1a96d7009..44a3feb5e 100644 --- a/qt-ui/profile/diveprofileitem.cpp +++ b/qt-ui/profile/diveprofileitem.cpp @@ -6,6 +6,7 @@ #include #include #include +#include AbstractProfilePolygonItem::AbstractProfilePolygonItem(): QObject(), QGraphicsPolygonItem(), hAxis(NULL), vAxis(NULL), dataModel(NULL), hDataColumn(-1), vDataColumn(-1) @@ -96,4 +97,38 @@ void DiveProfileItem::modelDataChanged(){ pat.setColorAt(1, getColor(DEPTH_BOTTOM)); pat.setColorAt(0, getColor(DEPTH_TOP)); setBrush(QBrush(pat)); -} \ No newline at end of file +} + +DiveTemperatureItem::DiveTemperatureItem() +{ + QPen pen; + pen.setBrush(QBrush(getColor(::TEMP_PLOT))); + pen.setCosmetic(true); + pen.setWidth(2); + setPen(pen); +} + +void DiveTemperatureItem::modelDataChanged() +{ + // We don't have enougth data to calculate things, quit. + if (!hAxis || !vAxis || !dataModel || hDataColumn == -1 || vDataColumn == -1) + return; + + // Ignore empty values. things do not look good with '0' as temperature in kelvin... + QPolygonF poly; + for (int i = 0, modelDataCount = dataModel->rowCount(); i < modelDataCount; i++) { + qreal verticalValue = dataModel->index(i, vDataColumn).data().toReal(); + if(!verticalValue) + continue; + qreal horizontalValue = dataModel->index(i, hDataColumn).data().toReal(); + QPointF point( hAxis->posAtValue(horizontalValue), vAxis->posAtValue(verticalValue)); + poly.append(point); + } + setPolygon(poly); +} + +void DiveTemperatureItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) +{ + painter->setPen(pen()); + painter->drawPolyline(polygon()); +} -- cgit v1.2.3-70-g09d2