24 #include "KDChartStockDiagram_p.h" 27 #include "KDChartPainterSaver_p.h" 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 );
void setThreeDBarAttributes(const ThreeDBarAttributes &attr)
QPen downTrendCandlestickPen() const
void setDataBoundariesDirty() const
int rowCount(const QModelIndex &) const override
[reimplemented]
qreal threeDItemDepth(int column) const override
QPen lowHighLinePen() const
QPainter * painter() const
virtual AttributesModel * attributesModel() const
Returns the AttributesModel, that is used by this diagram.
int columnCount(const QModelIndex &) const override
[reimplemented]
QPen upTrendCandlestickPen() const
StockDiagram(QWidget *parent=0, CartesianCoordinatePlane *plane=0)
AbstractCoordinatePlane * coordinatePlane() const
The coordinate plane associated with the diagram.
QVariant modelData(int role) const
void setDatasetDimensionInternal(int dimension)
void setDownTrendCandlestickBrush(const QBrush &brush)
StockBarAttributes stockBarAttributes() const
virtual const int numberOfOrdinateSegments() const
QBrush brush() const
Retrieve the brush to be used for painting datapoints globally.
void setPen(const QModelIndex &index, const QPen &pen)
Set the pen to be used, for painting the datapoint at the given index.
void setStockBarAttributes(const StockBarAttributes &attr)
void setDownTrendCandlestickPen(const QPen &pen)
void propertiesChanged()
Emitted upon change of a property of the Diagram.
Base class for diagrams based on a cartesian coordianate system.
QBrush downTrendCandlestickBrush() const
Stores information about painting diagrams.
A set of 3D bar attributes.
void setUpTrendCandlestickBrush(const QBrush &brush)
virtual qreal zoomFactorY() const
QPen pen() const
Retrieve the pen to be used for painting datapoints globally.
virtual const int numberOfAbscissaSegments() const
QModelIndex attributesModelRootIndex() const
QBrush upTrendCandlestickBrush() const
Cartesian coordinate plane.
void setLowHighLinePen(const QPen &pen)
void setUpTrendCandlestickPen(const QPen &pen)
ThreeDBarAttributes threeDBarAttributes() const
void paint(PaintContext *paintContext) override
Draw the diagram contents to the rectangle and painter, that are passed in as part of the paint conte...
bool setModelData(const QVariant value, int role)
const QPair< QPointF, QPointF > calculateDataBoundaries() const override
virtual qreal zoomFactorX() const
void resize(const QSizeF &size) override
Called by the widget's sizeEvent.
Attributes to customize the appearance of a column in a stock chart.