Functions | |
int | closeValueColumn () const |
Returns the column of the close value in the model. | |
void | drawCandlestick (const CartesianDiagramDataCompressor::DataPoint &open, const CartesianDiagramDataCompressor::DataPoint &high, const CartesianDiagramDataCompressor::DataPoint &low, const CartesianDiagramDataCompressor::DataPoint &close, PaintContext *context) |
Draws a line connecting the low and the high value of an OHLC chart. | |
void | drawLine (int col, const QPointF &point1, const QPointF &point2, PaintContext *context) |
Draws a line connecting two points. | |
void | drawOHLCBar (const CartesianDiagramDataCompressor::DataPoint &open, const CartesianDiagramDataCompressor::DataPoint &high, const CartesianDiagramDataCompressor::DataPoint &low, const CartesianDiagramDataCompressor::DataPoint &close, PaintContext *context) |
int | highValueColumn () const |
Returns the column of the high value in the model. | |
int | lowValueColumn () const |
Returns the column of the low value in the model. | |
int | openValueColumn () const |
Returns the column of the open value in the model. | |
Private (const Private &r) | |
Private () | |
QRectF | projectCandlestick (PaintContext *context, const QPointF &open, const QPointF &close, qreal width) const |
Projects a candlestick onto the coordinate plane. | |
QPointF | projectPoint (PaintContext *context, const QPointF &point) const |
Projects a point onto the coordinate plane. | |
~Private () |
int StockDiagram::Private::closeValueColumn | ( | ) | const |
Returns the column of the close value in the model.
Definition at line 509 of file KDChartStockDiagram_p.cpp.
References StockDiagram::type().
Referenced by drawCandlestick().
00510 { 00511 return type == HighLowClose ? 2 : 3; 00512 }
void StockDiagram::Private::drawCandlestick | ( | const CartesianDiagramDataCompressor::DataPoint & | open, | |
const CartesianDiagramDataCompressor::DataPoint & | high, | |||
const CartesianDiagramDataCompressor::DataPoint & | low, | |||
const CartesianDiagramDataCompressor::DataPoint & | close, | |||
PaintContext * | context | |||
) |
Draws a line connecting the low and the high value of an OHLC chart.
low | The low data point | |
high | The high data point | |
context | The context to draw the candlestick in |
Definition at line 314 of file KDChartStockDiagram_p.cpp.
References KDChart::ThreeDBarAttributes::angle(), KDChart::StockBarAttributes::candlestickWidth(), closeValueColumn(), KDChart::AbstractThreeDAttributes::depth(), KDChart::AbstractThreeDAttributes::isEnabled(), openValueColumn(), KDChart::PaintContext::painter(), projectCandlestick(), projectPoint(), and KDChart::ThreeDBarAttributes::useShadowColors().
00319 { 00320 PainterSaver painterSaver( context->painter() ); 00321 00322 // Note: A row in the model is a column in a StockDiagram, and the other way around 00323 const int row = low.index.row(); 00324 const int col = low.index.column(); 00325 00326 QPointF bottomCandlestickPoint; 00327 QPointF topCandlestickPoint; 00328 QBrush brush; 00329 QPen pen; 00330 bool drawLowerLine; 00331 bool drawCandlestick = !open.hidden && !close.hidden; 00332 bool drawUpperLine; 00333 00334 // Find out if we need to paint a down-trend or up-trend candlestick 00335 // and set brush and pen accordingly 00336 // Also, determine what the top and bottom points of the candlestick are 00337 if ( open.value <= close.value ) { 00338 pen = diagram->upTrendCandlestickPen( row ); 00339 brush = diagram->upTrendCandlestickBrush( row ); 00340 bottomCandlestickPoint = QPointF( open.key, open.value ); 00341 topCandlestickPoint = QPointF( close.key, close.value ); 00342 drawLowerLine = !low.hidden && !open.hidden; 00343 drawUpperLine = !low.hidden && !close.hidden; 00344 } else { 00345 pen = diagram->downTrendCandlestickPen( row ); 00346 brush = diagram->downTrendCandlestickBrush( row ); 00347 bottomCandlestickPoint = QPointF( close.key, close.value ); 00348 topCandlestickPoint = QPointF( open.key, open.value ); 00349 drawLowerLine = !low.hidden && !close.hidden; 00350 drawUpperLine = !low.hidden && !open.hidden; 00351 } 00352 00353 StockBarAttributes attr = diagram->stockBarAttributes( col ); 00354 ThreeDBarAttributes threeDAttr = diagram->threeDBarAttributes( col ); 00355 00356 const QPointF lowPoint = projectPoint( context, QPointF( low.key, low.value ) ); 00357 const QPointF highPoint = projectPoint( context, QPointF( high.key, high.value ) ); 00358 const QLineF lowerLine = QLineF( lowPoint, projectPoint( context, bottomCandlestickPoint ) ); 00359 const QLineF upperLine = QLineF( projectPoint( context, topCandlestickPoint ), highPoint ); 00360 00361 // Convert the data point into coordinates on the coordinate plane 00362 QRectF candlestick = projectCandlestick( context, bottomCandlestickPoint, 00363 topCandlestickPoint, attr.candlestickWidth() ); 00364 00365 // Remember the drawn polygon to add it to the ReverseMapper later 00366 QPolygonF drawnPolygon; 00367 00368 // Use the ThreeDPainter class to draw a 3D candlestick 00369 if ( threeDAttr.isEnabled() ) { 00370 ThreeDPainter threeDPainter( context->painter() ); 00371 00372 ThreeDPainter::ThreeDProperties threeDProps; 00373 threeDProps.depth = threeDAttr.depth(); 00374 threeDProps.angle = threeDAttr.angle(); 00375 threeDProps.useShadowColors = threeDAttr.useShadowColors(); 00376 00377 // If the perspective angle is within [0,180], we paint from bottom to top, 00378 // otherwise from top to bottom to ensure the correct z order 00379 if ( threeDProps.angle > 0.0 && threeDProps.angle < 180.0 ) { 00380 if ( drawLowerLine ) 00381 drawnPolygon = threeDPainter.drawTwoDLine( lowerLine, pen, threeDProps ); 00382 if ( drawCandlestick ) 00383 drawnPolygon = threeDPainter.drawThreeDRect( candlestick, brush, pen, threeDProps ); 00384 if ( drawUpperLine ) 00385 drawnPolygon = threeDPainter.drawTwoDLine( upperLine, pen, threeDProps ); 00386 } else { 00387 if ( drawUpperLine ) 00388 drawnPolygon = threeDPainter.drawTwoDLine( upperLine, pen, threeDProps ); 00389 if ( drawCandlestick ) 00390 drawnPolygon = threeDPainter.drawThreeDRect( candlestick, brush, pen, threeDProps ); 00391 if ( drawLowerLine ) 00392 drawnPolygon = threeDPainter.drawTwoDLine( lowerLine, pen, threeDProps ); 00393 } 00394 } else { 00395 QPainter *const painter = context->painter(); 00396 painter->setBrush( brush ); 00397 painter->setPen( pen ); 00398 if ( drawLowerLine ) 00399 painter->drawLine( lowerLine ); 00400 if ( drawUpperLine ) 00401 painter->drawLine( upperLine ); 00402 if ( drawCandlestick ) 00403 painter->drawRect( candlestick ); 00404 00405 // The 2D representation is the projected candlestick itself 00406 drawnPolygon = candlestick; 00407 00408 // FIXME: Add lower and upper line to reverse mapper 00409 } 00410 00411 DataValueTextInfoList list; 00412 00413 if ( !low.hidden ) 00414 appendDataValueTextInfoToList( diagram, list, diagram->attributesModel()->mapToSource( low.index ), 0, 00415 PositionPoints( lowPoint ), Position::South, Position::South, low.value ); 00416 if ( drawCandlestick ) { 00417 // Both, the open as well as the close value are represented by this candlestick 00418 reverseMapper.addPolygon( row, openValueColumn(), drawnPolygon ); 00419 reverseMapper.addPolygon( row, closeValueColumn(), drawnPolygon ); 00420 00421 appendDataValueTextInfoToList( diagram, list, diagram->attributesModel()->mapToSource( open.index ), 0, 00422 PositionPoints( candlestick.bottomRight() ), Position::South, Position::South, open.value ); 00423 appendDataValueTextInfoToList( diagram, list, diagram->attributesModel()->mapToSource( close.index ), 0, 00424 PositionPoints( candlestick.topRight() ), Position::South, Position::South, close.value ); 00425 } 00426 if ( !high.hidden ) 00427 appendDataValueTextInfoToList( diagram, list, diagram->attributesModel()->mapToSource( high.index ), 0, 00428 PositionPoints( highPoint ), Position::South, Position::South, high.value ); 00429 00430 paintDataValueTextsAndMarkers( diagram, context, list, false ); 00431 }
void StockDiagram::Private::drawLine | ( | int | col, | |
const QPointF & | point1, | |||
const QPointF & | point2, | |||
PaintContext * | context | |||
) |
Draws a line connecting two points.
col | The column of the diagram to paint the line in | |
point1 | The first point | |
point2 | The second point | |
context | The context to draw the low-high line in |
Definition at line 441 of file KDChartStockDiagram_p.cpp.
References KDChart::ThreeDBarAttributes::angle(), KDChart::PaintContext::coordinatePlane(), KDChart::AbstractThreeDAttributes::depth(), KDChart::AbstractThreeDAttributes::isEnabled(), KDChart::PaintContext::painter(), KDChart::AbstractCoordinatePlane::translate(), and KDChart::ThreeDBarAttributes::useShadowColors().
Referenced by drawOHLCBar().
00442 { 00443 PainterSaver painterSaver( context->painter() ); 00444 00445 // A row in the model is a column in the diagram 00446 const int modelRow = col; 00447 const int modelCol = 0; 00448 00449 const QPen pen = diagram->pen( col ); 00450 const QBrush brush = diagram->brush( col ); 00451 const ThreeDBarAttributes threeDBarAttr = diagram->threeDBarAttributes( col ); 00452 00453 QPointF transP1 = context->coordinatePlane()->translate( point1 ); 00454 QPointF transP2 = context->coordinatePlane()->translate( point2 ); 00455 QLineF line = QLineF( transP1, transP2 ); 00456 00457 if ( threeDBarAttr.isEnabled() ) { 00458 ThreeDPainter::ThreeDProperties threeDProps; 00459 threeDProps.angle = threeDBarAttr.angle(); 00460 threeDProps.depth = threeDBarAttr.depth(); 00461 threeDProps.useShadowColors = threeDBarAttr.useShadowColors(); 00462 00463 ThreeDPainter painter( context->painter() ); 00464 reverseMapper.addPolygon( modelCol, modelRow, painter.drawThreeDLine( line, brush, pen, threeDProps ) ); 00465 } else { 00466 context->painter()->setPen( pen ); 00467 //context->painter()->setBrush( brush ); 00468 reverseMapper.addLine( modelCol, modelRow, transP1, transP2 ); 00469 context->painter()->drawLine( line ); 00470 } 00471 }
void StockDiagram::Private::drawOHLCBar | ( | const CartesianDiagramDataCompressor::DataPoint & | open, | |
const CartesianDiagramDataCompressor::DataPoint & | high, | |||
const CartesianDiagramDataCompressor::DataPoint & | low, | |||
const CartesianDiagramDataCompressor::DataPoint & | close, | |||
PaintContext * | context | |||
) |
Definition at line 243 of file KDChartStockDiagram_p.cpp.
References KDChart::ThreeDBarAttributes::angle(), drawLine(), KDChart::AbstractThreeDAttributes::isEnabled(), and KDChart::StockBarAttributes::tickLength().
00248 { 00249 // Note: A row in the model is a column in a StockDiagram 00250 const int col = low.index.row(); 00251 00252 StockBarAttributes attr = diagram->stockBarAttributes( col ); 00253 ThreeDBarAttributes threeDAttr = diagram->threeDBarAttributes( col ); 00254 const qreal tickLength = attr.tickLength(); 00255 00256 const QPointF leftOpenPoint( open.key + 0.5 - tickLength, open.value ); 00257 const QPointF rightOpenPoint( open.key + 0.5, open.value ); 00258 const QPointF highPoint( high.key + 0.5, high.value ); 00259 const QPointF lowPoint( low.key + 0.5, low.value ); 00260 const QPointF leftClosePoint( close.key + 0.5, close.value ); 00261 const QPointF rightClosePoint( close.key + 0.5 + tickLength, close.value ); 00262 00263 bool reversedOrder = false; 00264 // If 3D mode is enabled, we have to make sure the z-order is right 00265 if ( threeDAttr.isEnabled() ) { 00266 const int angle = threeDAttr.angle(); 00267 // Z-order is from right to left 00268 if ( angle >= 0 && angle < 90 || angle >= 180 && angle < 270 ) 00269 reversedOrder = true; 00270 // Z-order is from left to right 00271 if ( angle >= 90 && angle < 180 || angle >= 270 && angle < 0 ) 00272 reversedOrder = false; 00273 } 00274 00275 if ( reversedOrder ) { 00276 if ( !open.hidden ) 00277 drawLine( col, leftOpenPoint, rightOpenPoint, context ); // Open marker 00278 if ( !low.hidden && !high.hidden ) 00279 drawLine( col, lowPoint, highPoint, context ); // Low-High line 00280 if ( !close.hidden ) 00281 drawLine( col, leftClosePoint, rightClosePoint, context ); // Close marker 00282 } else { 00283 if ( !close.hidden ) 00284 drawLine( col, leftClosePoint, rightClosePoint, context ); // Close marker 00285 if ( !low.hidden && !high.hidden ) 00286 drawLine( col, lowPoint, highPoint, context ); // Low-High line 00287 if ( !open.hidden ) 00288 drawLine( col, leftOpenPoint, rightOpenPoint, context ); // Open marker 00289 } 00290 00291 DataValueTextInfoList list; 00292 if ( !open.hidden ) 00293 appendDataValueTextInfoToList( diagram, list, diagram->attributesModel()->mapToSource( open.index ), 0, 00294 PositionPoints( leftOpenPoint ), Position::South, Position::South, open.value ); 00295 if ( !high.hidden ) 00296 appendDataValueTextInfoToList( diagram, list, diagram->attributesModel()->mapToSource( high.index ), 0, 00297 PositionPoints( highPoint ), Position::South, Position::South, high.value ); 00298 if ( !low.hidden ) 00299 appendDataValueTextInfoToList( diagram, list, diagram->attributesModel()->mapToSource( low.index ), 0, 00300 PositionPoints( lowPoint ), Position::South, Position::South, low.value ); 00301 if ( !close.hidden ) 00302 appendDataValueTextInfoToList( diagram, list, diagram->attributesModel()->mapToSource( close.index ), 0, 00303 PositionPoints( rightClosePoint ), Position::South, Position::South, close.value ); 00304 paintDataValueTextsAndMarkers( diagram, context, list, false ); 00305 }
int StockDiagram::Private::highValueColumn | ( | ) | const |
Returns the column of the high value in the model.
Definition at line 489 of file KDChartStockDiagram_p.cpp.
References StockDiagram::type().
00490 { 00491 return type == HighLowClose ? 0 : 1; 00492 }
int StockDiagram::Private::lowValueColumn | ( | ) | const |
Returns the column of the low value in the model.
Definition at line 499 of file KDChartStockDiagram_p.cpp.
References StockDiagram::type().
00500 { 00501 return type == HighLowClose ? 1 : 2; 00502 }
int StockDiagram::Private::openValueColumn | ( | ) | const |
Returns the column of the open value in the model.
Definition at line 478 of file KDChartStockDiagram_p.cpp.
References StockDiagram::type().
Referenced by drawCandlestick().
00479 { 00480 // Return an invalid column if diagram has no open values 00481 return type == HighLowClose ? -1 : 0; 00482 }
StockDiagram::Private::Private | ( | const Private & | r | ) |
Definition at line 206 of file KDChartStockDiagram_p.cpp.
Referenced by KDChart::CartesianCoordinatePlane::calculateRawDataBoundingRect(), KDChart::RingDiagram::clone(), KDChart::PolarDiagram::clone(), KDChart::Plotter::clone(), KDChart::PieDiagram::clone(), KDChart::LineDiagram::clone(), KDChart::LeveyJenningsDiagram::clone(), KDChart::Legend::clone(), KDChart::HeaderFooter::clone(), KDChart::BarDiagram::clone(), KDGantt::DateTimeScaleFormatter::operator=(), KDGantt::DateTimeGrid::paintDayScaleHeader(), KDGantt::DateTimeGrid::paintHourScaleHeader(), KDGantt::DateTimeGrid::paintMonthScaleHeader(), and KDGantt::DateTimeGrid::paintWeekScaleHeader().
00207 : AbstractCartesianDiagram::Private( r ) 00208 { 00209 }
StockDiagram::Private::Private | ( | ) |
Definition at line 201 of file KDChartStockDiagram_p.cpp.
00202 : AbstractCartesianDiagram::Private() 00203 { 00204 }
QRectF StockDiagram::Private::projectCandlestick | ( | PaintContext * | context, | |
const QPointF & | open, | |||
const QPointF & | close, | |||
qreal | width | |||
) | const |
Projects a candlestick onto the coordinate plane.
context | The context to paint the candlestick in | |
low | The |
Definition at line 233 of file KDChartStockDiagram_p.cpp.
References KDChart::PaintContext::coordinatePlane(), and KDChart::AbstractCoordinatePlane::translate().
Referenced by drawCandlestick().
00234 { 00235 const QPointF leftHighPoint = context->coordinatePlane()->translate( QPointF( close.x() + 0.5 - width / 2.0, close.y() ) ); 00236 const QPointF rightLowPoint = context->coordinatePlane()->translate( QPointF( open.x() + 0.5 + width / 2.0, open.y() ) ); 00237 const QPointF rightHighPoint = context->coordinatePlane()->translate( QPointF( close.x() + 0.5 + width / 2.0, close.y() ) ); 00238 00239 return QRectF( leftHighPoint, QSizeF( rightHighPoint.x() - leftHighPoint.x(), 00240 rightLowPoint.y() - leftHighPoint.y() ) ); 00241 }
QPointF StockDiagram::Private::projectPoint | ( | PaintContext * | context, | |
const QPointF & | point | |||
) | const |
Projects a point onto the coordinate plane.
context | The context to paint the point in The point to project onto the coordinate plane |
Definition at line 222 of file KDChartStockDiagram_p.cpp.
References KDChart::PaintContext::coordinatePlane(), and KDChart::AbstractCoordinatePlane::translate().
Referenced by drawCandlestick().
00223 { 00224 return context->coordinatePlane()->translate( QPointF( point.x() + 0.5, point.y() ) ); 00225 }
StockDiagram::Private::~Private | ( | ) |