summaryrefslogtreecommitdiffstats
path: root/qt-ui/profile/diveprofileitem.cpp
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tcanabrava@kde.org>2014-01-16 18:39:13 -0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-01-17 06:18:25 +0700
commit58aeb6ce4014899e040a3ef8f4483f18fb44b432 (patch)
tree9e81e0fded3a1038ffa089e7b1bd49429d529df6 /qt-ui/profile/diveprofileitem.cpp
parent254beef5d4c0ead123556ffbc5e37dd2cc81366e (diff)
downloadsubsurface-58aeb6ce4014899e040a3ef8f4483f18fb44b432.tar.gz
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 <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.cpp37
1 files changed, 36 insertions, 1 deletions
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 <QPen>
#include <QPainter>
#include <QLinearGradient>
+#include <QDebug>
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());
+}