summaryrefslogtreecommitdiffstats
path: root/qt-ui/profile/diveprofileitem.cpp
diff options
context:
space:
mode:
authorGravatar Krzysztof Arentowicz <karent.bug@gmail.com>2015-01-02 00:28:38 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-01-01 16:23:22 -0800
commite3378e299a64e4aa807858b49bf5794a2a5babe7 (patch)
tree3505cbb39efd9b706af3e35220653bffd0aeaa2a /qt-ui/profile/diveprofileitem.cpp
parentee1ef5233036be26ab28228465985f1cf71ba157 (diff)
downloadsubsurface-e3378e299a64e4aa807858b49bf5794a2a5babe7.tar.gz
Plot mean depth data
As we already have running depth sum values for each sample why don't just plot running average depth graph. Signed-off-by: Krzysztof Arentowicz <k.arentowicz@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/profile/diveprofileitem.cpp')
-rw-r--r--qt-ui/profile/diveprofileitem.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/qt-ui/profile/diveprofileitem.cpp b/qt-ui/profile/diveprofileitem.cpp
index 57873e9c2..07d622260 100644
--- a/qt-ui/profile/diveprofileitem.cpp
+++ b/qt-ui/profile/diveprofileitem.cpp
@@ -568,6 +568,53 @@ void DiveTemperatureItem::paint(QPainter *painter, const QStyleOptionGraphicsIte
painter->restore();
}
+DiveMeanDepthItem::DiveMeanDepthItem()
+{
+ QPen pen;
+ pen.setBrush(QBrush(getColor(::MEAN_DEPTH)));
+ pen.setCosmetic(true);
+ pen.setWidth(2);
+ setPen(pen);
+ settingsChanged();
+}
+
+void DiveMeanDepthItem::modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
+{
+ double meandepthvalue;
+ // We don't have enougth data to calculate things, quit.
+ if (!shouldCalculateStuff(topLeft, bottomRight))
+ return;
+
+ QPolygonF poly;
+ plot_data *entry = dataModel->data().entry;
+ for (int i = 0, modelDataCount = dataModel->rowCount(); i < modelDataCount; i++, entry++) {
+ // Ignore empty values
+ if (entry->running_sum == 0 || entry->sec == 0)
+ continue;
+
+ meandepthvalue = entry->running_sum / entry->sec ;
+ QPointF point(hAxis->posAtValue(entry->sec), vAxis->posAtValue(meandepthvalue));
+ poly.append(point);
+ }
+
+ setPolygon(poly);
+}
+
+
+void DiveMeanDepthItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
+{
+ if (polygon().isEmpty())
+ return;
+ painter->save();
+ painter->setPen(pen());
+ painter->drawPolyline(polygon());
+ painter->restore();
+}
+
+void DiveMeanDepthItem::settingsChanged()
+{
+ setVisible(prefs.show_average_depth);
+}
void DiveGasPressureItem::modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
{
// We don't have enougth data to calculate things, quit.