24 #include "KDChartStockDiagram_p.h"
27 #include "KDChartPainterSaver_p.h"
29 using namespace KDChart;
39 StockDiagram::~StockDiagram()
46 void StockDiagram::init()
53 d->upTrendCandlestickBrush = QBrush( Qt::white );
54 d->downTrendCandlestickBrush = QBrush( Qt::black );
55 d->upTrendCandlestickPen = QPen( Qt::black );
56 d->downTrendCandlestickPen = QPen( Qt::black );
58 d->lowHighLinePen = QPen( Qt::black );
62 setPen( QPen( Qt::black ) );
86 qVariantFromValue( attr ),
105 if ( attr.isValid() )
118 qVariantFromValue( attr ),
160 if ( attr.isValid() )
168 d->lowHighLinePen =
pen;
173 return d->lowHighLinePen;
178 d->lowHighLinePens[column] =
pen;
183 if (
d->lowHighLinePens.contains( column ) )
184 return d->lowHighLinePens[column];
185 return d->lowHighLinePen;
190 d->upTrendCandlestickBrush =
brush;
195 return d->upTrendCandlestickBrush;
200 d->downTrendCandlestickBrush =
brush;
205 return d->downTrendCandlestickBrush;
210 d->upTrendCandlestickBrushes[column] =
brush;
215 if (
d->upTrendCandlestickBrushes.contains( column ) )
216 return d->upTrendCandlestickBrushes[column];
217 return d->upTrendCandlestickBrush;
222 d->downTrendCandlestickBrushes[column] =
brush;
227 if (
d->downTrendCandlestickBrushes.contains( column ) )
228 return d->downTrendCandlestickBrushes[column];
229 return d->downTrendCandlestickBrush;
235 d->upTrendCandlestickPen =
pen;
240 return d->upTrendCandlestickPen;
245 d->downTrendCandlestickPen =
pen;
250 return d->downTrendCandlestickPen;
255 d->upTrendCandlestickPens[column] =
pen;
260 if (
d->upTrendCandlestickPens.contains( column ) )
261 return d->upTrendCandlestickPens[column];
262 return d->upTrendCandlestickPen;
267 d->downTrendCandlestickPens[column] =
pen;
272 if (
d->downTrendCandlestickPens.contains( column ) )
273 return d->downTrendCandlestickPens[column];
274 return d->downTrendCandlestickPen;
277 #if QT_VERSION < 0x040400 || defined(Q_COMPILER_MANGLES_RETURN_TYPE)
282 #if QT_VERSION < 0x040400 || defined(Q_COMPILER_MANGLES_RETURN_TYPE)
291 d->reverseMapper.clear();
293 PainterSaver painterSaver( context->
painter() );
297 for (
int col = 0; col < colCount; ++col )
299 for (
int row = 0; row < rowCount; row++ ) {
300 CartesianDiagramDataCompressor::DataPoint low;
301 CartesianDiagramDataCompressor::DataPoint high;
302 CartesianDiagramDataCompressor::DataPoint open;
303 CartesianDiagramDataCompressor::DataPoint close;
304 CartesianDiagramDataCompressor::DataPoint volume;
307 const CartesianDiagramDataCompressor::CachePosition highPos( row, col * divisor );
308 const CartesianDiagramDataCompressor::CachePosition lowPos( row, col * divisor + 1 );
309 const CartesianDiagramDataCompressor::CachePosition closePos( row, col * divisor + 2 );
310 low =
d->compressor.data( lowPos );
311 high =
d->compressor.data( highPos );
312 close =
d->compressor.data( closePos );
314 const CartesianDiagramDataCompressor::CachePosition openPos( row, col * divisor );
315 const CartesianDiagramDataCompressor::CachePosition highPos( row, col * divisor + 1 );
316 const CartesianDiagramDataCompressor::CachePosition lowPos( row, col * divisor + 2 );
317 const CartesianDiagramDataCompressor::CachePosition closePos( row, col * divisor + 3 );
318 open =
d->compressor.data( openPos );
319 low =
d->compressor.data( lowPos );
320 high =
d->compressor.data( highPos );
321 close =
d->compressor.data( closePos );
330 if ( close.index.isValid() && low.index.isValid() && high.index.isValid() )
331 d->drawOHLCBar( col, open, high, low, close, context );
334 d->drawCandlestick( col, open, high, low, close, context );
346 QAbstractItemView::resize( size.toSize() );
368 qreal xMax = rowCount;
371 for (
int row = 0; row < rowCount; row++ ) {
372 for (
int col = 0; col < colCount; col++ ) {
373 const CartesianDiagramDataCompressor::CachePosition pos( row, col );
374 const CartesianDiagramDataCompressor::DataPoint point =
d->compressor.data( pos );
375 yMax = qMax( yMax, point.value );
376 yMin = qMin( yMin, point.value );