void PlotShapeItem::invalidateCache()
{
if(! m_xScaleDraw)
return;
m_leftIndex = m_xScaleDraw->indexOf(m_leftDate, true);
m_rightIndex = m_xScaleDraw->indexOf(m_rightDate, true);
// Scale transform
double w = m_rightIndex - m_leftIndex;
double m11;
if (w > 0)
m11 = w / (int)(m_path.controlPointRect().width() + 0.5);
else
m11 = 0;
QTransform t(m11, 0, 0, 1.0, 0, 0);
pp = t.map(pp);
// Translate transform
double dx = m_leftIndex - (int)(pp.controlPointRect().left() + 0.5);
QTransform ts(1, 0, 0, 1, dx, 0);
pp = ts.map(pp);
setShape(pp);
}
void PlotShapeItem::invalidateCache()
{
if(! m_xScaleDraw)
return;
m_leftIndex = m_xScaleDraw->indexOf(m_leftDate, true);
m_rightIndex = m_xScaleDraw->indexOf(m_rightDate, true);
QPainterPath pp = m_path.translated(0, 0);
// Scale transform
double w = m_rightIndex - m_leftIndex;
double m11;
if (w > 0)
m11 = w / (int)(m_path.controlPointRect().width() + 0.5);
else
m11 = 0;
QTransform t(m11, 0, 0, 1.0, 0, 0);
pp = t.map(pp);
// Translate transform
double dx = m_leftIndex - (int)(pp.controlPointRect().left() + 0.5);
QTransform ts(1, 0, 0, 1, dx, 0);
pp = ts.map(pp);
setShape(pp);
}
To copy to clipboard, switch view to plain text mode
This is called only when the charts/samples time frame changes, I chose to use QwtPlotShapeItem as it didn't require modification to my plot item editor. It also automatically shifts the shape as new candles come in from the server.
Bookmarks