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

Method drawOhlcPlot

qcustomplot.cpp:26754–26803  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

26752 This method is a helper function for \ref draw. It is used when the chart style is \ref csOhlc.
26753*/
26754void QCPFinancial::drawOhlcPlot(QCPPainter *painter, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, bool isSelected)
26755{
26756 QCPAxis *keyAxis = mKeyAxis.data();
26757 QCPAxis *valueAxis = mValueAxis.data();
26758 if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; }
26759
26760 if (keyAxis->orientation() == Qt::Horizontal)
26761 {
26762 for (QCPFinancialDataContainer::const_iterator it = begin; it != end; ++it)
26763 {
26764 if (isSelected && mSelectionDecorator)
26765 mSelectionDecorator->applyPen(painter);
26766 else if (mTwoColored)
26767 painter->setPen(it->close >= it->open ? mPenPositive : mPenNegative);
26768 else
26769 painter->setPen(mPen);
26770 double keyPixel = keyAxis->coordToPixel(it->key);
26771 double openPixel = valueAxis->coordToPixel(it->open);
26772 double closePixel = valueAxis->coordToPixel(it->close);
26773 // draw backbone:
26774 painter->drawLine(QPointF(keyPixel, valueAxis->coordToPixel(it->high)), QPointF(keyPixel, valueAxis->coordToPixel(it->low)));
26775 // draw open:
26776 double pixelWidth = getPixelWidth(it->key, keyPixel); // sign of this makes sure open/close are on correct sides
26777 painter->drawLine(QPointF(keyPixel-pixelWidth, openPixel), QPointF(keyPixel, openPixel));
26778 // draw close:
26779 painter->drawLine(QPointF(keyPixel, closePixel), QPointF(keyPixel+pixelWidth, closePixel));
26780 }
26781 } else
26782 {
26783 for (QCPFinancialDataContainer::const_iterator it = begin; it != end; ++it)
26784 {
26785 if (isSelected && mSelectionDecorator)
26786 mSelectionDecorator->applyPen(painter);
26787 else if (mTwoColored)
26788 painter->setPen(it->close >= it->open ? mPenPositive : mPenNegative);
26789 else
26790 painter->setPen(mPen);
26791 double keyPixel = keyAxis->coordToPixel(it->key);
26792 double openPixel = valueAxis->coordToPixel(it->open);
26793 double closePixel = valueAxis->coordToPixel(it->close);
26794 // draw backbone:
26795 painter->drawLine(QPointF(valueAxis->coordToPixel(it->high), keyPixel), QPointF(valueAxis->coordToPixel(it->low), keyPixel));
26796 // draw open:
26797 double pixelWidth = getPixelWidth(it->key, keyPixel); // sign of this makes sure open/close are on correct sides
26798 painter->drawLine(QPointF(openPixel, keyPixel-pixelWidth), QPointF(openPixel, keyPixel));
26799 // draw close:
26800 painter->drawLine(QPointF(closePixel, keyPixel), QPointF(closePixel, keyPixel+pixelWidth));
26801 }
26802 }
26803}
26804
26805/*! \internal
26806

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected