! \internal This method is a helper function for \ref selectTest. It is used to test for selection when the chart style is \ref csOhlc. 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 respective data poi
| 26929 | representation of the plottable, and \a closestDataPoint will point to the respective data point. |
| 26930 | */ |
| 26931 | double QCPFinancial::ohlcSelectTest(const QPointF &pos, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, QCPFinancialDataContainer::const_iterator &closestDataPoint) const |
| 26932 | { |
| 26933 | closestDataPoint = mDataContainer->constEnd(); |
| 26934 | QCPAxis *keyAxis = mKeyAxis.data(); |
| 26935 | QCPAxis *valueAxis = mValueAxis.data(); |
| 26936 | if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return -1; } |
| 26937 | |
| 26938 | double minDistSqr = (std::numeric_limits<double>::max)(); |
| 26939 | if (keyAxis->orientation() == Qt::Horizontal) |
| 26940 | { |
| 26941 | for (QCPFinancialDataContainer::const_iterator it=begin; it!=end; ++it) |
| 26942 | { |
| 26943 | double keyPixel = keyAxis->coordToPixel(it->key); |
| 26944 | // calculate distance to backbone: |
| 26945 | double currentDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(keyPixel, valueAxis->coordToPixel(it->high)), QCPVector2D(keyPixel, valueAxis->coordToPixel(it->low))); |
| 26946 | if (currentDistSqr < minDistSqr) |
| 26947 | { |
| 26948 | minDistSqr = currentDistSqr; |
| 26949 | closestDataPoint = it; |
| 26950 | } |
| 26951 | } |
| 26952 | } else // keyAxis->orientation() == Qt::Vertical |
| 26953 | { |
| 26954 | for (QCPFinancialDataContainer::const_iterator it=begin; it!=end; ++it) |
| 26955 | { |
| 26956 | double keyPixel = keyAxis->coordToPixel(it->key); |
| 26957 | // calculate distance to backbone: |
| 26958 | double currentDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(valueAxis->coordToPixel(it->high), keyPixel), QCPVector2D(valueAxis->coordToPixel(it->low), keyPixel)); |
| 26959 | if (currentDistSqr < minDistSqr) |
| 26960 | { |
| 26961 | minDistSqr = currentDistSqr; |
| 26962 | closestDataPoint = it; |
| 26963 | } |
| 26964 | } |
| 26965 | } |
| 26966 | return qSqrt(minDistSqr); |
| 26967 | } |
| 26968 | |
| 26969 | /*! \internal |
| 26970 |
nothing calls this directly
no test coverage detected