MCPcopy Create free account
hub / github.com/LUX-Core/lux / drawCandlestickPlot

Method drawCandlestickPlot

src/qt/qcustomplot.cpp:26728–26791  ·  view source on GitHub ↗

! \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. */

Source from the content-addressed store, hash-verified

26726 This method is a helper function for \ref draw. It is used when the chart style is \ref csCandlestick.
26727*/
26728void QCPFinancial::drawCandlestickPlot(QCPPainter *painter, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, bool isSelected)
26729{
26730 QCPAxis *keyAxis = mKeyAxis.data();
26731 QCPAxis *valueAxis = mValueAxis.data();
26732 if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; }
26733
26734 if (keyAxis->orientation() == Qt::Horizontal)
26735 {
26736 for (QCPFinancialDataContainer::const_iterator it = begin; it != end; ++it)
26737 {
26738 if (isSelected && mSelectionDecorator)
26739 {
26740 mSelectionDecorator->applyPen(painter);
26741 mSelectionDecorator->applyBrush(painter);
26742 } else if (mTwoColored)
26743 {
26744 painter->setPen(it->close >= it->open ? mPenPositive : mPenNegative);
26745 painter->setBrush(it->close >= it->open ? mBrushPositive : mBrushNegative);
26746 } else
26747 {
26748 painter->setPen(mPen);
26749 painter->setBrush(mBrush);
26750 }
26751 double keyPixel = keyAxis->coordToPixel(it->key);
26752 double openPixel = valueAxis->coordToPixel(it->open);
26753 double closePixel = valueAxis->coordToPixel(it->close);
26754 // draw high:
26755 painter->drawLine(QPointF(keyPixel, valueAxis->coordToPixel(it->high)), QPointF(keyPixel, valueAxis->coordToPixel(qMax(it->open, it->close))));
26756 // draw low:
26757 painter->drawLine(QPointF(keyPixel, valueAxis->coordToPixel(it->low)), QPointF(keyPixel, valueAxis->coordToPixel(qMin(it->open, it->close))));
26758 // draw open-close box:
26759 double pixelWidth = getPixelWidth(it->key, keyPixel);
26760 painter->drawRect(QRectF(QPointF(keyPixel-pixelWidth, closePixel), QPointF(keyPixel+pixelWidth, openPixel)));
26761 }
26762 } else // keyAxis->orientation() == Qt::Vertical
26763 {
26764 for (QCPFinancialDataContainer::const_iterator it = begin; it != end; ++it)
26765 {
26766 if (isSelected && mSelectionDecorator)
26767 {
26768 mSelectionDecorator->applyPen(painter);
26769 mSelectionDecorator->applyBrush(painter);
26770 } else if (mTwoColored)
26771 {
26772 painter->setPen(it->close >= it->open ? mPenPositive : mPenNegative);
26773 painter->setBrush(it->close >= it->open ? mBrushPositive : mBrushNegative);
26774 } else
26775 {
26776 painter->setPen(mPen);
26777 painter->setBrush(mBrush);
26778 }
26779 double keyPixel = keyAxis->coordToPixel(it->key);
26780 double openPixel = valueAxis->coordToPixel(it->open);
26781 double closePixel = valueAxis->coordToPixel(it->close);
26782 // draw high:
26783 painter->drawLine(QPointF(valueAxis->coordToPixel(it->high), keyPixel), QPointF(valueAxis->coordToPixel(qMax(it->open, it->close)), keyPixel));
26784 // draw low:
26785 painter->drawLine(QPointF(valueAxis->coordToPixel(it->low), keyPixel), QPointF(valueAxis->coordToPixel(qMin(it->open, it->close)), keyPixel));

Callers

nothing calls this directly

Calls 7

applyPenMethod · 0.80
applyBrushMethod · 0.80
setPenMethod · 0.80
setBrushMethod · 0.80
coordToPixelMethod · 0.80
drawLineMethod · 0.80
dataMethod · 0.45

Tested by

no test coverage detected