From bd5cc109f0ad0b16ac0d5402a60268331cfdf2b9 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Fri, 14 Feb 2014 21:17:31 -0200 Subject: Show the last temperature on the graph. The code shamelessy copied from the old profile introduced a bug where the old temperature was not correctly shown. I'v added a new member to the class that will store the last valid temperature, and use that to calculate if there's a reason or not to display it. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- qt-ui/profile/diveprofileitem.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/qt-ui/profile/diveprofileitem.cpp b/qt-ui/profile/diveprofileitem.cpp index 0b1d32a4e..7246309bf 100644 --- a/qt-ui/profile/diveprofileitem.cpp +++ b/qt-ui/profile/diveprofileitem.cpp @@ -227,7 +227,7 @@ DiveTemperatureItem::DiveTemperatureItem() void DiveTemperatureItem::modelDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight) { - int last = -300, last_printed_temp = 0, sec = 0; + int last = -300, last_printed_temp = 0, sec = 0, last_valid_temp = 0; // We don't have enougth data to calculate things, quit. if (!shouldCalculateStuff(topLeft, bottomRight)) return; @@ -240,6 +240,7 @@ void DiveTemperatureItem::modelDataChanged(const QModelIndex& topLeft, const QMo int mkelvin = dataModel->index(i, vDataColumn).data().toInt(); if (!mkelvin) continue; + last_valid_temp = mkelvin; sec = dataModel->index(i, hDataColumn).data().toInt(); QPointF point( hAxis->posAtValue(sec), vAxis->posAtValue(mkelvin)); poly.append(point); @@ -262,10 +263,9 @@ void DiveTemperatureItem::modelDataChanged(const QModelIndex& topLeft, const QMo /* it would be nice to print the end temperature, if it's * different or if the last temperature print has been more * than a quarter of the dive back */ - int last_temperature = dataModel->data(dataModel->index(dataModel->rowCount()-1, DivePlotDataModel::TEMPERATURE)).toInt(); - if (last_temperature > 200000 && - ((abs(last_temperature - last_printed_temp) > 500) || ((double)last / (double)sec < 0.75))) { - createTextItem(sec, last_temperature); + if (last_valid_temp > 200000 && + ((abs(last_valid_temp - last_printed_temp) > 500) || ((double)last / (double)sec < 0.75))) { + createTextItem(sec, last_valid_temp); } } -- cgit v1.2.3-70-g09d2