MCPcopy Create free account
hub / github.com/collin80/SavvyCAN / candlestickSelectTest

Method candlestickSelectTest

qcustomplot.cpp:26978–27042  ·  view source on GitHub ↗

! \internal This method is a helper function for \ref selectTest. It is used to test for selection when the chart style is \ref csCandlestick. It only tests against the data points between \a begin and \a end. Like \ref selectTest, this method returns the shortest distance of \a pos to the graphical representation of the plottable, and \a closestDataPoint will point to the respecti

Source from the content-addressed store, hash-verified

26976 representation of the plottable, and \a closestDataPoint will point to the respective data point.
26977*/
26978double QCPFinancial::candlestickSelectTest(const QPointF &pos, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, QCPFinancialDataContainer::const_iterator &closestDataPoint) const
26979{
26980 closestDataPoint = mDataContainer->constEnd();
26981 QCPAxis *keyAxis = mKeyAxis.data();
26982 QCPAxis *valueAxis = mValueAxis.data();
26983 if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return -1; }
26984
26985 double minDistSqr = (std::numeric_limits<double>::max)();
26986 if (keyAxis->orientation() == Qt::Horizontal)
26987 {
26988 for (QCPFinancialDataContainer::const_iterator it=begin; it!=end; ++it)
26989 {
26990 double currentDistSqr;
26991 // determine whether pos is in open-close-box:
26992 QCPRange boxKeyRange(it->key-mWidth*0.5, it->key+mWidth*0.5);
26993 QCPRange boxValueRange(it->close, it->open);
26994 double posKey, posValue;
26995 pixelsToCoords(pos, posKey, posValue);
26996 if (boxKeyRange.contains(posKey) && boxValueRange.contains(posValue)) // is in open-close-box
26997 {
26998 currentDistSqr = mParentPlot->selectionTolerance()*0.99 * mParentPlot->selectionTolerance()*0.99;
26999 } else
27000 {
27001 // calculate distance to high/low lines:
27002 double keyPixel = keyAxis->coordToPixel(it->key);
27003 double highLineDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(keyPixel, valueAxis->coordToPixel(it->high)), QCPVector2D(keyPixel, valueAxis->coordToPixel(qMax(it->open, it->close))));
27004 double lowLineDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(keyPixel, valueAxis->coordToPixel(it->low)), QCPVector2D(keyPixel, valueAxis->coordToPixel(qMin(it->open, it->close))));
27005 currentDistSqr = qMin(highLineDistSqr, lowLineDistSqr);
27006 }
27007 if (currentDistSqr < minDistSqr)
27008 {
27009 minDistSqr = currentDistSqr;
27010 closestDataPoint = it;
27011 }
27012 }
27013 } else // keyAxis->orientation() == Qt::Vertical
27014 {
27015 for (QCPFinancialDataContainer::const_iterator it=begin; it!=end; ++it)
27016 {
27017 double currentDistSqr;
27018 // determine whether pos is in open-close-box:
27019 QCPRange boxKeyRange(it->key-mWidth*0.5, it->key+mWidth*0.5);
27020 QCPRange boxValueRange(it->close, it->open);
27021 double posKey, posValue;
27022 pixelsToCoords(pos, posKey, posValue);
27023 if (boxKeyRange.contains(posKey) && boxValueRange.contains(posValue)) // is in open-close-box
27024 {
27025 currentDistSqr = mParentPlot->selectionTolerance()*0.99 * mParentPlot->selectionTolerance()*0.99;
27026 } else
27027 {
27028 // calculate distance to high/low lines:
27029 double keyPixel = keyAxis->coordToPixel(it->key);
27030 double highLineDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(valueAxis->coordToPixel(it->high), keyPixel), QCPVector2D(valueAxis->coordToPixel(qMax(it->open, it->close)), keyPixel));
27031 double lowLineDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(valueAxis->coordToPixel(it->low), keyPixel), QCPVector2D(valueAxis->coordToPixel(qMin(it->open, it->close)), keyPixel));
27032 currentDistSqr = qMin(highLineDistSqr, lowLineDistSqr);
27033 }
27034 if (currentDistSqr < minDistSqr)
27035 {

Callers

nothing calls this directly

Calls 5

constEndMethod · 0.80
containsMethod · 0.80
coordToPixelMethod · 0.80
distanceSquaredToLineMethod · 0.80
dataMethod · 0.45

Tested by

no test coverage detected