9#include "KChartStockDiagram.h"
10#include "KChartStockDiagram_p.h"
12#include "KChartPaintContext.h"
13#include "KChartPainterSaver_p.h"
25StockDiagram::~StockDiagram()
32void StockDiagram::init()
38 d->type = HighLowClose;
45 setDatasetDimensionInternal( 3 );
51void StockDiagram::setType( Type type )
57StockDiagram::Type StockDiagram::type()
const
66 StockBarAttributesRole );
83 const QVariant attr( d->datasetAttrs( column, StockBarAttributesRole ) );
86 return stockBarAttributes();
93 ThreeDBarAttributesRole );
110 const QVariant attr( d->datasetAttrs( column, ThreeDBarAttributesRole ) );
111 if ( attr.isValid() )
113 return threeDBarAttributes();
117void StockDiagram::setLowHighLinePen(
const QPen &pen )
119 d->lowHighLinePen =
pen;
122QPen StockDiagram::lowHighLinePen()
const
124 return d->lowHighLinePen;
127void StockDiagram::setLowHighLinePen(
int column,
const QPen &pen )
129 d->lowHighLinePens[column] =
pen;
132QPen StockDiagram::lowHighLinePen(
int column )
const
134 if ( d->lowHighLinePens.contains( column ) )
135 return d->lowHighLinePens[column];
136 return d->lowHighLinePen;
139void StockDiagram::setUpTrendCandlestickBrush(
const QBrush &brush )
141 d->upTrendCandlestickBrush =
brush;
144QBrush StockDiagram::upTrendCandlestickBrush()
const
146 return d->upTrendCandlestickBrush;
149void StockDiagram::setDownTrendCandlestickBrush(
const QBrush &brush )
151 d->downTrendCandlestickBrush =
brush;
154QBrush StockDiagram::downTrendCandlestickBrush()
const
156 return d->downTrendCandlestickBrush;
159void StockDiagram::setUpTrendCandlestickBrush(
int column,
const QBrush &brush )
161 d->upTrendCandlestickBrushes[column] =
brush;
164QBrush StockDiagram::upTrendCandlestickBrush(
int column )
const
166 if ( d->upTrendCandlestickBrushes.contains( column ) )
167 return d->upTrendCandlestickBrushes[column];
168 return d->upTrendCandlestickBrush;
171void StockDiagram::setDownTrendCandlestickBrush(
int column,
const QBrush &brush )
173 d->downTrendCandlestickBrushes[column] =
brush;
176QBrush StockDiagram::downTrendCandlestickBrush(
int column )
const
178 if ( d->downTrendCandlestickBrushes.contains( column ) )
179 return d->downTrendCandlestickBrushes[column];
180 return d->downTrendCandlestickBrush;
184void StockDiagram::setUpTrendCandlestickPen(
const QPen &pen )
186 d->upTrendCandlestickPen =
pen;
189QPen StockDiagram::upTrendCandlestickPen()
const
191 return d->upTrendCandlestickPen;
194void StockDiagram::setDownTrendCandlestickPen(
const QPen &pen )
196 d->downTrendCandlestickPen =
pen;
199QPen StockDiagram::downTrendCandlestickPen()
const
201 return d->downTrendCandlestickPen;
204void StockDiagram::setUpTrendCandlestickPen(
int column,
const QPen &pen )
206 d->upTrendCandlestickPens[column] =
pen;
209QPen StockDiagram::upTrendCandlestickPen(
int column )
const
211 if ( d->upTrendCandlestickPens.contains( column ) )
212 return d->upTrendCandlestickPens[column];
213 return d->upTrendCandlestickPen;
216void StockDiagram::setDownTrendCandlestickPen(
int column,
const QPen &pen )
218 d->downTrendCandlestickPens[column] =
pen;
221QPen StockDiagram::downTrendCandlestickPen(
int column )
const
223 if ( d->downTrendCandlestickPens.contains( column ) )
224 return d->downTrendCandlestickPens[column];
225 return d->downTrendCandlestickPen;
228#if defined(Q_COMPILER_MANGLES_RETURN_TYPE)
231int StockDiagram::numberOfAbscissaSegments()
const {
return 1; }
233#if defined(Q_COMPILER_MANGLES_RETURN_TYPE)
236int StockDiagram::numberOfOrdinateSegments()
const {
return 1; }
242 d->reverseMapper.clear();
244 PainterSaver painterSaver( context->painter() );
246 const int divisor = ( d->type == OpenHighLowClose || d->type == Candlestick ) ? 4 : 3;
248 for (
int col = 0; col < colCount; ++col )
250 for (
int row = 0; row < rowCount; row++ ) {
251 CartesianDiagramDataCompressor::DataPoint low;
252 CartesianDiagramDataCompressor::DataPoint high;
253 CartesianDiagramDataCompressor::DataPoint
open;
254 CartesianDiagramDataCompressor::DataPoint
close;
255 CartesianDiagramDataCompressor::DataPoint
volume;
257 if ( d->type == HighLowClose ) {
258 const CartesianDiagramDataCompressor::CachePosition highPos( row, col * divisor );
259 const CartesianDiagramDataCompressor::CachePosition lowPos( row, col * divisor + 1 );
260 const CartesianDiagramDataCompressor::CachePosition closePos( row, col * divisor + 2 );
261 low = d->compressor.data( lowPos );
262 high = d->compressor.data( highPos );
263 close = d->compressor.data( closePos );
264 }
else if ( d->type == OpenHighLowClose || d->type == Candlestick ) {
265 const CartesianDiagramDataCompressor::CachePosition openPos( row, col * divisor );
266 const CartesianDiagramDataCompressor::CachePosition highPos( row, col * divisor + 1 );
267 const CartesianDiagramDataCompressor::CachePosition lowPos( row, col * divisor + 2 );
268 const CartesianDiagramDataCompressor::CachePosition closePos( row, col * divisor + 3 );
269 open = d->compressor.data( openPos );
270 low = d->compressor.data( lowPos );
271 high = d->compressor.data( highPos );
272 close = d->compressor.data( closePos );
281 case OpenHighLowClose:
282 if (
close.index.isValid() && low.index.isValid() && high.index.isValid() )
283 d->drawOHLCBar( col, open, high, low,
close, context );
286 d->drawCandlestick( col, open, high, low,
close, context );
293void StockDiagram::resize(
const QSizeF &size )
295 d->compressor.setResolution(
static_cast< int >(
size.width() *
coordinatePlane()->zoomFactorX() ),
297 setDataBoundariesDirty();
301qreal StockDiagram::threeDItemDepth(
int column )
const
308qreal StockDiagram::threeDItemDepth(
const QModelIndex &index )
const
315const QPair<QPointF, QPointF> StockDiagram::calculateDataBoundaries()
const
320 qreal xMax = rowCount;
323 for (
int row = 0; row < rowCount; row++ ) {
324 for (
int col = 0; col < colCount; col++ ) {
325 const CartesianDiagramDataCompressor::CachePosition
pos( row, col );
326 const CartesianDiagramDataCompressor::DataPoint point = d->compressor.data(
pos );
327 yMax = qMax( yMax, point.value );
328 yMin = qMin( yMin, point.value );
331 return QPair<QPointF, QPointF>(
QPointF( xMin, yMin ),
QPointF( xMax, yMax ) );
Base class for diagrams based on a cartesian coordianate system.
virtual AttributesModel * attributesModel() const
Returns the AttributesModel, that is used by this diagram.
void setPen(const QModelIndex &index, const QPen &pen)
Set the pen to be used, for painting the datapoint at the given index.
QModelIndex attributesModelRootIndex() const
void propertiesChanged()
Emitted upon change of a property of the Diagram.
QPen pen() const
Retrieve the pen to be used for painting datapoints globally.
AbstractCoordinatePlane * coordinatePlane() const
The coordinate plane associated with the diagram.
QBrush brush() const
Retrieve the brush to be used for painting datapoints globally.
int rowCount(const QModelIndex &) const override
\reimpl
int columnCount(const QModelIndex &) const override
\reimpl
Cartesian coordinate plane.
Stores information about painting diagrams.
Attributes to customize the appearance of a column in a stock chart.
A set of 3D bar attributes.
Type type(const QSqlDatabase &db)
const QList< QKeySequence > & open()
QVariant fromValue(T &&value)