summaryrefslogtreecommitdiffstats
path: root/qt-ui/profile/diveprofileitem.cpp
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2014-02-23 15:28:31 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-02-23 15:28:31 -0800
commitb5a02e50aa94c10d2c9f2062af6b4e8d9cfb9294 (patch)
treebbb1b714255c8c66fd9bf9d4d05d7f2d8f1c9d24 /qt-ui/profile/diveprofileitem.cpp
parent76393a2f536dd6823b08ec3a53ffcb16b216bbf4 (diff)
downloadsubsurface-b5a02e50aa94c10d2c9f2062af6b4e8d9cfb9294.tar.gz
New profile: create new class for DiveHeartrateItem
This allows us to give it a different color (red) and make it a smaller size. While implementing this I also fixed the size of the temperature text in the new profile. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/profile/diveprofileitem.cpp')
-rw-r--r--qt-ui/profile/diveprofileitem.cpp69
1 files changed, 68 insertions, 1 deletions
diff --git a/qt-ui/profile/diveprofileitem.cpp b/qt-ui/profile/diveprofileitem.cpp
index a16ef7dd3..cb0a8cc46 100644
--- a/qt-ui/profile/diveprofileitem.cpp
+++ b/qt-ui/profile/diveprofileitem.cpp
@@ -216,6 +216,73 @@ void DiveProfileItem::plot_depth_sample(struct plot_data *entry,QFlags<Qt::Align
texts.append(item);
}
+DiveHeartrateItem::DiveHeartrateItem()
+{
+ QPen pen;
+ pen.setBrush(QBrush(getColor(::HR_PLOT)));
+ pen.setCosmetic(true);
+ pen.setWidth(1);
+ setPen(pen);
+}
+
+void DiveHeartrateItem::modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
+{
+ int last = -300, last_printed_hr = 0, sec = 0, last_valid_hr = 0;
+ // We don't have enougth data to calculate things, quit.
+ if (!shouldCalculateStuff(topLeft, bottomRight))
+ return;
+
+ qDeleteAll(texts);
+ texts.clear();
+ // 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++) {
+ int hr = dataModel->index(i, vDataColumn).data().toInt();
+ if (!hr)
+ continue;
+ last_valid_hr = hr;
+ sec = dataModel->index(i, hDataColumn).data().toInt();
+ QPointF point( hAxis->posAtValue(sec), vAxis->posAtValue(hr));
+ poly.append(point);
+
+ /* don't print a HR
+ * if it's been less than 5min and less than a 20 beats change OR
+ * if it's been less than 2min OR if the change from the
+ * last print is less than 10 beats */
+ if (((sec < last + 300) && (abs(hr - last_printed_hr) < 20)) ||
+ (sec < last + 120) ||
+ (abs(hr - last_printed_hr) < 10))
+ continue;
+ last = sec;
+ if (hr > 0)
+ createTextItem(sec, hr);
+ last_printed_hr = hr;
+ }
+ setPolygon(poly);
+
+ if( texts.count())
+ texts.last()->setAlignment(Qt::AlignLeft | Qt::AlignBottom);
+}
+
+void DiveHeartrateItem::createTextItem(int sec, int hr)
+{
+ DiveTextItem *text = new DiveTextItem(this);
+ text->setAlignment(Qt::AlignRight | Qt::AlignBottom);
+ text->setBrush(getColor(HR_TEXT));
+ text->setPos(QPointF(hAxis->posAtValue(sec), vAxis->posAtValue(hr)));
+ text->setScale(0.7); // need to call this BEFORE setText()
+ text->setText(QString("%1").arg(hr));
+ texts.append(text);
+}
+
+void DiveHeartrateItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
+{
+ if(polygon().isEmpty())
+ return;
+ painter->setPen(pen());
+ painter->drawPolyline(polygon());
+}
+
DiveTemperatureItem::DiveTemperatureItem()
{
QPen pen;
@@ -281,8 +348,8 @@ void DiveTemperatureItem::createTextItem(int sec, int mkelvin)
text->setAlignment(Qt::AlignRight | Qt::AlignBottom);
text->setBrush(getColor(TEMP_TEXT));
text->setPos(QPointF(hAxis->posAtValue(sec), vAxis->posAtValue(mkelvin)));
+ text->setScale(0.8); // need to call this BEFORE setText()
text->setText(QString("%1%2").arg(deg, 0, 'f', 1).arg(unit));
- // text->setSize(TEMP_TEXT_SIZE); //TODO: TEXT SIZE!
texts.append(text);
}