! \internal Draws the data from \a begin to \a end-1 as Candlesticks with the provided \a painter. This method is a helper function for \ref draw. It is used when the chart style is \ref csCandlestick. */
| 26809 | This method is a helper function for \ref draw. It is used when the chart style is \ref csCandlestick. |
| 26810 | */ |
| 26811 | void QCPFinancial::drawCandlestickPlot(QCPPainter *painter, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, bool isSelected) |
| 26812 | { |
| 26813 | QCPAxis *keyAxis = mKeyAxis.data(); |
| 26814 | QCPAxis *valueAxis = mValueAxis.data(); |
| 26815 | if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } |
| 26816 | |
| 26817 | if (keyAxis->orientation() == Qt::Horizontal) |
| 26818 | { |
| 26819 | for (QCPFinancialDataContainer::const_iterator it = begin; it != end; ++it) |
| 26820 | { |
| 26821 | if (isSelected && mSelectionDecorator) |
| 26822 | { |
| 26823 | mSelectionDecorator->applyPen(painter); |
| 26824 | mSelectionDecorator->applyBrush(painter); |
| 26825 | } else if (mTwoColored) |
| 26826 | { |
| 26827 | painter->setPen(it->close >= it->open ? mPenPositive : mPenNegative); |
| 26828 | painter->setBrush(it->close >= it->open ? mBrushPositive : mBrushNegative); |
| 26829 | } else |
| 26830 | { |
| 26831 | painter->setPen(mPen); |
| 26832 | painter->setBrush(mBrush); |
| 26833 | } |
| 26834 | double keyPixel = keyAxis->coordToPixel(it->key); |
| 26835 | double openPixel = valueAxis->coordToPixel(it->open); |
| 26836 | double closePixel = valueAxis->coordToPixel(it->close); |
| 26837 | // draw high: |
| 26838 | painter->drawLine(QPointF(keyPixel, valueAxis->coordToPixel(it->high)), QPointF(keyPixel, valueAxis->coordToPixel(qMax(it->open, it->close)))); |
| 26839 | // draw low: |
| 26840 | painter->drawLine(QPointF(keyPixel, valueAxis->coordToPixel(it->low)), QPointF(keyPixel, valueAxis->coordToPixel(qMin(it->open, it->close)))); |
| 26841 | // draw open-close box: |
| 26842 | double pixelWidth = getPixelWidth(it->key, keyPixel); |
| 26843 | painter->drawRect(QRectF(QPointF(keyPixel-pixelWidth, closePixel), QPointF(keyPixel+pixelWidth, openPixel))); |
| 26844 | } |
| 26845 | } else // keyAxis->orientation() == Qt::Vertical |
| 26846 | { |
| 26847 | for (QCPFinancialDataContainer::const_iterator it = begin; it != end; ++it) |
| 26848 | { |
| 26849 | if (isSelected && mSelectionDecorator) |
| 26850 | { |
| 26851 | mSelectionDecorator->applyPen(painter); |
| 26852 | mSelectionDecorator->applyBrush(painter); |
| 26853 | } else if (mTwoColored) |
| 26854 | { |
| 26855 | painter->setPen(it->close >= it->open ? mPenPositive : mPenNegative); |
| 26856 | painter->setBrush(it->close >= it->open ? mBrushPositive : mBrushNegative); |
| 26857 | } else |
| 26858 | { |
| 26859 | painter->setPen(mPen); |
| 26860 | painter->setBrush(mBrush); |
| 26861 | } |
| 26862 | double keyPixel = keyAxis->coordToPixel(it->key); |
| 26863 | double openPixel = valueAxis->coordToPixel(it->open); |
| 26864 | double closePixel = valueAxis->coordToPixel(it->close); |
| 26865 | // draw high: |
| 26866 | painter->drawLine(QPointF(valueAxis->coordToPixel(it->high), keyPixel), QPointF(valueAxis->coordToPixel(qMax(it->open, it->close)), keyPixel)); |
| 26867 | // draw low: |
| 26868 | painter->drawLine(QPointF(valueAxis->coordToPixel(it->low), keyPixel), QPointF(valueAxis->coordToPixel(qMin(it->open, it->close)), keyPixel)); |
nothing calls this directly
no test coverage detected