File indexing completed on 2024-12-15 04:02:33
0001 /* 0002 * SPDX-FileCopyrightText: 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved. 0003 * 0004 * This file is part of the KD Chart library. 0005 * 0006 * SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #ifndef KCHART_STOCK_DIAGRAM_H 0010 #define KCHART_STOCK_DIAGRAM_H 0011 0012 #include "KChartAbstractCartesianDiagram.h" 0013 #include "KChartCartesianCoordinatePlane.h" 0014 #include "KChartStockBarAttributes.h" 0015 #include "KChartThreeDBarAttributes.h" 0016 0017 namespace KChart { 0018 class PaintContext; 0019 0020 class KCHART_EXPORT StockDiagram : public AbstractCartesianDiagram 0021 { 0022 Q_OBJECT 0023 0024 Q_DISABLE_COPY( StockDiagram ) 0025 0026 KCHART_DECLARE_DERIVED_DIAGRAM( StockDiagram, CartesianCoordinatePlane ) 0027 0028 public: 0029 enum Type { 0030 HighLowClose, 0031 OpenHighLowClose, 0032 Candlestick 0033 }; 0034 0035 explicit StockDiagram( QWidget *parent = nullptr, CartesianCoordinatePlane *plane = nullptr ); 0036 ~StockDiagram() override; 0037 0038 0039 /** 0040 * Switches between the supported types of stock charts, 0041 * depending on \a type 0042 */ 0043 void setType( Type type ); 0044 0045 /** 0046 * @return the type of this diagram 0047 */ 0048 Type type() const; 0049 0050 void setStockBarAttributes( const StockBarAttributes &attr ); 0051 StockBarAttributes stockBarAttributes() const; 0052 0053 void setStockBarAttributes( int column, const StockBarAttributes &attr ); 0054 StockBarAttributes stockBarAttributes( int column ) const; 0055 0056 0057 /** 0058 * Sets the 3D attributes for all bars (i.e. candlesticks) 0059 * 0060 * @param attr The 3D attributes to set 0061 */ 0062 0063 /** 0064 * Sets the 3D attributes for the bar (i.e. candlestick) in certain column 0065 * of the diagram 0066 * 0067 * Note: Every column in a StockDiagram is represented by a row in the model 0068 * 0069 * @param column The column to set the 3D bar attributes for 0070 * @param attr The 3D attributes to set 0071 */ 0072 void setThreeDBarAttributes( const ThreeDBarAttributes &attr ); 0073 0074 /** 0075 * Returns the 3D attributes for all bars (i.e. candlesticks) 0076 * 0077 * @return the 3D bar attributes 0078 */ 0079 ThreeDBarAttributes threeDBarAttributes() const; 0080 0081 /** 0082 * Returns the 3D attributes for a bars (i.e. candlestick) in a certain column 0083 * of the diagram 0084 * 0085 * Note: Every column in a StockDiagram is represented by a row in the model 0086 * 0087 * @param column The column to get the 3D bar attributes for 0088 * @return The 3D attributes for the specified column 0089 */ 0090 ThreeDBarAttributes threeDBarAttributes( int column ) const; 0091 0092 void setThreeDBarAttributes( int column, const ThreeDBarAttributes &attr ); 0093 0094 void setLowHighLinePen( const QPen &pen ); 0095 QPen lowHighLinePen() const; 0096 0097 void setLowHighLinePen( int column, const QPen &pen ); 0098 QPen lowHighLinePen( int column ) const; 0099 0100 void setUpTrendCandlestickBrush( const QBrush &brush ); 0101 QBrush upTrendCandlestickBrush() const; 0102 0103 void setDownTrendCandlestickBrush( const QBrush &brush ); 0104 QBrush downTrendCandlestickBrush() const; 0105 0106 void setUpTrendCandlestickBrush( int column, const QBrush &brush ); 0107 QBrush upTrendCandlestickBrush( int column ) const; 0108 0109 void setDownTrendCandlestickBrush( int column, const QBrush &brush ); 0110 QBrush downTrendCandlestickBrush( int column ) const; 0111 0112 void setUpTrendCandlestickPen( const QPen &pen ); 0113 QPen upTrendCandlestickPen() const; 0114 0115 void setDownTrendCandlestickPen( const QPen &pen ); 0116 QPen downTrendCandlestickPen() const; 0117 0118 void setUpTrendCandlestickPen( int column, const QPen &pen ); 0119 QPen upTrendCandlestickPen( int column ) const; 0120 0121 void setDownTrendCandlestickPen( int column, const QPen &pen ); 0122 QPen downTrendCandlestickPen( int column ) const; 0123 0124 #if defined(Q_COMPILER_MANGLES_RETURN_TYPE) 0125 virtual const int numberOfAbscissaSegments() const; 0126 virtual const int numberOfOrdinateSegments() const; 0127 #else 0128 int numberOfAbscissaSegments() const override; 0129 int numberOfOrdinateSegments() const override; 0130 #endif 0131 0132 void paint( PaintContext *paintContext ) override; 0133 0134 void resize( const QSizeF &size ) override; 0135 0136 qreal threeDItemDepth( int column ) const override; 0137 qreal threeDItemDepth( const QModelIndex &index ) const override; 0138 0139 protected: 0140 const QPair<QPointF, QPointF> calculateDataBoundaries() const override; 0141 }; 0142 0143 } // namespace KChart 0144 0145 #endif // KCHART_STOCK_DIAGRAM_H 0146