subsurface/stats/histogrammarker.cpp
Berthold Stoeger 2eebae13dd stats: break out common QtQuick part of the code
Move most of the QtQuick code to its own directory, so that it
can be reused in the future for the chart.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-09-11 10:35:04 +02:00

29 lines
788 B
C++

// SPDX-License-Identifier: GPL-2.0
#include "histogrammarker.h"
#include "statsaxis.h"
#include "zvalues.h"
static const double histogramMarkerWidth = 2.0;
HistogramMarker::HistogramMarker(ChartView &view, double val, bool horizontal,
QColor color, StatsAxis *xAxis, StatsAxis *yAxis) :
ChartLineItem(view, ChartZValue::ChartFeatures, color, histogramMarkerWidth),
xAxis(xAxis), yAxis(yAxis),
val(val), horizontal(horizontal)
{
}
void HistogramMarker::updatePosition()
{
if (!xAxis || !yAxis)
return;
if (horizontal) {
double y = yAxis->toScreen(val);
auto [x1, x2] = xAxis->minMaxScreen();
setLine(QPointF(x1, y), QPointF(x2, y));
} else {
double x = xAxis->toScreen(val);
auto [y1, y2] = yAxis->minMaxScreen();
setLine(QPointF(x, y1), QPointF(x, y2));
}
}