diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2021-01-14 09:48:44 +0100 |
---|---|---|
committer | bstoeger <32835590+bstoeger@users.noreply.github.com> | 2021-01-20 08:47:18 +0100 |
commit | 218c844ad4fa3f562c375b97694025f6cdaa3ca1 (patch) | |
tree | a09ddbcc1c09d04d89691a1ce0980d99950d6675 /stats/statsview.cpp | |
parent | 790d2b2ddb36fd39fe8f002290288603ba1f0065 (diff) | |
download | subsurface-218c844ad4fa3f562c375b97694025f6cdaa3ca1.tar.gz |
statistics: convert HistogramMarkers to QSGNodes
This is in analogy to the quartile markers.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'stats/statsview.cpp')
-rw-r--r-- | stats/statsview.cpp | 41 |
1 files changed, 7 insertions, 34 deletions
diff --git a/stats/statsview.cpp b/stats/statsview.cpp index b4b82ccfa..1e09a8cc5 100644 --- a/stats/statsview.cpp +++ b/stats/statsview.cpp @@ -2,6 +2,7 @@ #include "statsview.h" #include "barseries.h" #include "boxseries.h" +#include "histogrammarker.h" #include "legend.h" #include "pieseries.h" #include "quartilemarker.h" @@ -214,8 +215,8 @@ void StatsView::plotAreaChanged(const QSizeF &s) marker->updatePosition(); for (RegressionLine &line: regressionLines) line.updatePosition(); - for (HistogramMarker &marker: histogramMarkers) - marker.updatePosition(); + for (auto &marker: histogramMarkers) + marker->updatePosition(); if (legend) legend->resize(); updateTitlePos(); @@ -849,33 +850,9 @@ void StatsView::RegressionLine::updatePosition() central->setPolygon(line.intersected(box)); } -StatsView::HistogramMarker::HistogramMarker(double val, bool horizontal, QPen pen, QGraphicsScene *scene, StatsAxis *xAxis, StatsAxis *yAxis) : - item(createItemPtr<QGraphicsLineItem>(scene)), - xAxis(xAxis), yAxis(yAxis), - val(val), horizontal(horizontal) -{ - item->setZValue(ZValues::chartFeatures); - item->setPen(pen); -} - -void StatsView::HistogramMarker::updatePosition() -{ - if (!xAxis || !yAxis) - return; - if (horizontal) { - double y = yAxis->toScreen(val); - auto [x1, x2] = xAxis->minMaxScreen(); - item->setLine(x1, y, x2, y); - } else { - double x = xAxis->toScreen(val); - auto [y1, y2] = yAxis->minMaxScreen(); - item->setLine(x, y1, x, y2); - } -} - -void StatsView::addHistogramMarker(double pos, const QPen &pen, bool isHorizontal, StatsAxis *xAxis, StatsAxis *yAxis) +void StatsView::addHistogramMarker(double pos, QColor color, bool isHorizontal, StatsAxis *xAxis, StatsAxis *yAxis) { - histogramMarkers.emplace_back(pos, isHorizontal, pen, &scene, xAxis, yAxis); + histogramMarkers.push_back(createChartItem<HistogramMarker>(pos, isHorizontal, color, xAxis, yAxis)); } void StatsView::addLinearRegression(const struct regression_data reg, StatsAxis *xAxis, StatsAxis *yAxis) @@ -959,17 +936,13 @@ void StatsView::plotHistogramCountChart(const std::vector<dive *> &dives, if (categoryVariable->type() == StatsVariable::Type::Numeric) { if (showMean) { double mean = categoryVariable->mean(dives); - QPen meanPen(Qt::green); - meanPen.setWidth(2); if (!std::isnan(mean)) - addHistogramMarker(mean, meanPen, isHorizontal, xAxis, yAxis); + addHistogramMarker(mean, Qt::green, isHorizontal, xAxis, yAxis); } if (showMedian) { double median = categoryVariable->quartiles(dives).q2; - QPen medianPen(Qt::red); - medianPen.setWidth(2); if (!std::isnan(median)) - addHistogramMarker(median, medianPen, isHorizontal, xAxis, yAxis); + addHistogramMarker(median, Qt::red, isHorizontal, xAxis, yAxis); } } } |