! \internal Draws the data from \a begin to \a end-1 as OHLC bars with the provided \a painter. This method is a helper function for \ref draw. It is used when the chart style is \ref csOhlc. */
| 26669 | This method is a helper function for \ref draw. It is used when the chart style is \ref csOhlc. |
| 26670 | */ |
| 26671 | void QCPFinancial::drawOhlcPlot(QCPPainter *painter, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, bool isSelected) |
| 26672 | { |
| 26673 | QCPAxis *keyAxis = mKeyAxis.data(); |
| 26674 | QCPAxis *valueAxis = mValueAxis.data(); |
| 26675 | if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } |
| 26676 | |
| 26677 | if (keyAxis->orientation() == Qt::Horizontal) |
| 26678 | { |
| 26679 | for (QCPFinancialDataContainer::const_iterator it = begin; it != end; ++it) |
| 26680 | { |
| 26681 | if (isSelected && mSelectionDecorator) |
| 26682 | mSelectionDecorator->applyPen(painter); |
| 26683 | else if (mTwoColored) |
| 26684 | painter->setPen(it->close >= it->open ? mPenPositive : mPenNegative); |
| 26685 | else |
| 26686 | painter->setPen(mPen); |
| 26687 | double keyPixel = keyAxis->coordToPixel(it->key); |
| 26688 | double openPixel = valueAxis->coordToPixel(it->open); |
| 26689 | double closePixel = valueAxis->coordToPixel(it->close); |
| 26690 | // draw backbone: |
| 26691 | painter->drawLine(QPointF(keyPixel, valueAxis->coordToPixel(it->high)), QPointF(keyPixel, valueAxis->coordToPixel(it->low))); |
| 26692 | // draw open: |
| 26693 | double pixelWidth = getPixelWidth(it->key, keyPixel); // sign of this makes sure open/close are on correct sides |
| 26694 | painter->drawLine(QPointF(keyPixel-pixelWidth, openPixel), QPointF(keyPixel, openPixel)); |
| 26695 | // draw close: |
| 26696 | painter->drawLine(QPointF(keyPixel, closePixel), QPointF(keyPixel+pixelWidth, closePixel)); |
| 26697 | } |
| 26698 | } else |
| 26699 | { |
| 26700 | for (QCPFinancialDataContainer::const_iterator it = begin; it != end; ++it) |
| 26701 | { |
| 26702 | if (isSelected && mSelectionDecorator) |
| 26703 | mSelectionDecorator->applyPen(painter); |
| 26704 | else if (mTwoColored) |
| 26705 | painter->setPen(it->close >= it->open ? mPenPositive : mPenNegative); |
| 26706 | else |
| 26707 | painter->setPen(mPen); |
| 26708 | double keyPixel = keyAxis->coordToPixel(it->key); |
| 26709 | double openPixel = valueAxis->coordToPixel(it->open); |
| 26710 | double closePixel = valueAxis->coordToPixel(it->close); |
| 26711 | // draw backbone: |
| 26712 | painter->drawLine(QPointF(valueAxis->coordToPixel(it->high), keyPixel), QPointF(valueAxis->coordToPixel(it->low), keyPixel)); |
| 26713 | // draw open: |
| 26714 | double pixelWidth = getPixelWidth(it->key, keyPixel); // sign of this makes sure open/close are on correct sides |
| 26715 | painter->drawLine(QPointF(openPixel, keyPixel-pixelWidth), QPointF(openPixel, keyPixel)); |
| 26716 | // draw close: |
| 26717 | painter->drawLine(QPointF(closePixel, keyPixel), QPointF(closePixel, keyPixel+pixelWidth)); |
| 26718 | } |
| 26719 | } |
| 26720 | } |
| 26721 | |
| 26722 | /*! \internal |
| 26723 |
nothing calls this directly
no test coverage detected