[8127] | 1 | /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
|
---|
| 2 | * Qwt Widget Library
|
---|
| 3 | * Copyright (C) 1997 Josef Wilgen
|
---|
| 4 | * Copyright (C) 2002 Uwe Rathmann
|
---|
| 5 | *
|
---|
| 6 | * This library is free software; you can redistribute it and/or
|
---|
| 7 | * modify it under the terms of the Qwt License, Version 1.0
|
---|
| 8 | *****************************************************************************/
|
---|
| 9 |
|
---|
| 10 | #ifndef QWT_PLOT_TRADING_CURVE_H
|
---|
| 11 | #define QWT_PLOT_TRADING_CURVE_H
|
---|
| 12 |
|
---|
| 13 | #include "qwt_global.h"
|
---|
| 14 | #include "qwt_plot_seriesitem.h"
|
---|
| 15 | #include "qwt_series_data.h"
|
---|
| 16 |
|
---|
| 17 | /*!
|
---|
| 18 | \brief QwtPlotTradingCurve illustrates movements in the price of a
|
---|
| 19 | financial instrument over time.
|
---|
| 20 |
|
---|
| 21 | QwtPlotTradingCurve supports candlestick or bar ( OHLC ) charts
|
---|
| 22 | that are used in the domain of technical analysis.
|
---|
| 23 |
|
---|
[9383] | 24 | While the length ( height or width depending on orientation() )
|
---|
[8127] | 25 | of each symbol depends on the corresponding OHLC sample the size
|
---|
| 26 | of the other dimension can be controlled using:
|
---|
| 27 |
|
---|
| 28 | - setSymbolExtent()
|
---|
| 29 | - setSymbolMinWidth()
|
---|
| 30 | - setSymbolMaxWidth()
|
---|
| 31 |
|
---|
| 32 | The extent is a size in scale coordinates, so that the symbol width
|
---|
| 33 | is increasing when the plot is zoomed in. Minimum/Maximum width
|
---|
[9383] | 34 | is in widget coordinates independent from the zoom level.
|
---|
| 35 | When setting the minimum and maximum to the same value, the width of
|
---|
| 36 | the symbol is fixed.
|
---|
[8127] | 37 | */
|
---|
[9383] | 38 | class QWT_EXPORT QwtPlotTradingCurve:
|
---|
| 39 | public QwtPlotSeriesItem, public QwtSeriesStore<QwtOHLCSample>
|
---|
[8127] | 40 | {
|
---|
| 41 | public:
|
---|
| 42 | /*!
|
---|
| 43 | \brief Symbol styles.
|
---|
| 44 |
|
---|
| 45 | The default setting is QwtPlotSeriesItem::CandleStick.
|
---|
| 46 | \sa setSymbolStyle(), symbolStyle()
|
---|
| 47 | */
|
---|
| 48 | enum SymbolStyle
|
---|
| 49 | {
|
---|
| 50 | //! Nothing is displayed
|
---|
| 51 | NoSymbol = -1,
|
---|
| 52 |
|
---|
| 53 | /*!
|
---|
| 54 | A line on the chart shows the price range (the highest and lowest
|
---|
| 55 | prices) over one unit of time, e.g. one day or one hour.
|
---|
| 56 | Tick marks project from each side of the line indicating the
|
---|
| 57 | opening and closing price.
|
---|
| 58 | */
|
---|
| 59 | Bar,
|
---|
| 60 |
|
---|
| 61 | /*!
|
---|
| 62 | The range between opening/closing price are displayed as
|
---|
| 63 | a filled box. The fill brush depends on the direction of the
|
---|
| 64 | price movement. The box is connected to the highest/lowest
|
---|
| 65 | values by lines.
|
---|
| 66 | */
|
---|
| 67 | CandleStick,
|
---|
| 68 |
|
---|
| 69 | /*!
|
---|
| 70 | SymbolTypes >= UserSymbol are displayed by drawUserSymbol(),
|
---|
| 71 | that needs to be overloaded and implemented in derived
|
---|
| 72 | curve classes.
|
---|
| 73 |
|
---|
| 74 | \sa drawUserSymbol()
|
---|
| 75 | */
|
---|
| 76 | UserSymbol = 100
|
---|
| 77 | };
|
---|
| 78 |
|
---|
| 79 | /*!
|
---|
| 80 | \brief Direction of a price movement
|
---|
| 81 | */
|
---|
| 82 | enum Direction
|
---|
| 83 | {
|
---|
| 84 | //! The closing price is higher than the opening price
|
---|
| 85 | Increasing,
|
---|
| 86 |
|
---|
| 87 | //! The closing price is lower than the opening price
|
---|
| 88 | Decreasing
|
---|
| 89 | };
|
---|
| 90 |
|
---|
| 91 | /*!
|
---|
| 92 | Attributes to modify the drawing algorithm.
|
---|
| 93 | \sa setPaintAttribute(), testPaintAttribute()
|
---|
| 94 | */
|
---|
| 95 | enum PaintAttribute
|
---|
| 96 | {
|
---|
| 97 | //! Check if a symbol is on the plot canvas before painting it.
|
---|
| 98 | ClipSymbols = 0x01
|
---|
| 99 | };
|
---|
| 100 |
|
---|
| 101 | //! Paint attributes
|
---|
| 102 | typedef QFlags<PaintAttribute> PaintAttributes;
|
---|
| 103 |
|
---|
[9383] | 104 | explicit QwtPlotTradingCurve( const QString &title = QString() );
|
---|
[8127] | 105 | explicit QwtPlotTradingCurve( const QwtText &title );
|
---|
| 106 |
|
---|
| 107 | virtual ~QwtPlotTradingCurve();
|
---|
| 108 |
|
---|
| 109 | virtual int rtti() const;
|
---|
| 110 |
|
---|
| 111 | void setPaintAttribute( PaintAttribute, bool on = true );
|
---|
| 112 | bool testPaintAttribute( PaintAttribute ) const;
|
---|
| 113 |
|
---|
| 114 | void setSamples( const QVector<QwtOHLCSample> & );
|
---|
| 115 | void setSamples( QwtSeriesData<QwtOHLCSample> * );
|
---|
| 116 |
|
---|
| 117 | void setSymbolStyle( SymbolStyle style );
|
---|
| 118 | SymbolStyle symbolStyle() const;
|
---|
| 119 |
|
---|
[9383] | 120 | void setSymbolPen( const QColor &,
|
---|
[8127] | 121 | qreal width = 0.0, Qt::PenStyle = Qt::SolidLine );
|
---|
| 122 | void setSymbolPen( const QPen & );
|
---|
| 123 | QPen symbolPen() const;
|
---|
| 124 |
|
---|
| 125 | void setSymbolBrush( Direction, const QBrush & );
|
---|
| 126 | QBrush symbolBrush( Direction ) const;
|
---|
| 127 |
|
---|
[9383] | 128 | void setSymbolExtent( double );
|
---|
[8127] | 129 | double symbolExtent() const;
|
---|
| 130 |
|
---|
| 131 | void setMinSymbolWidth( double );
|
---|
| 132 | double minSymbolWidth() const;
|
---|
| 133 |
|
---|
| 134 | void setMaxSymbolWidth( double );
|
---|
| 135 | double maxSymbolWidth() const;
|
---|
| 136 |
|
---|
| 137 | virtual void drawSeries( QPainter *painter,
|
---|
| 138 | const QwtScaleMap &xMap, const QwtScaleMap &yMap,
|
---|
| 139 | const QRectF &canvasRect, int from, int to ) const;
|
---|
| 140 |
|
---|
| 141 | virtual QRectF boundingRect() const;
|
---|
| 142 |
|
---|
| 143 | virtual QwtGraphic legendIcon( int index, const QSizeF & ) const;
|
---|
| 144 |
|
---|
| 145 | protected:
|
---|
| 146 |
|
---|
| 147 | void init();
|
---|
| 148 |
|
---|
| 149 | virtual void drawSymbols( QPainter *,
|
---|
| 150 | const QwtScaleMap &xMap, const QwtScaleMap &yMap,
|
---|
| 151 | const QRectF &canvasRect, int from, int to ) const;
|
---|
| 152 |
|
---|
[9383] | 153 | virtual void drawUserSymbol( QPainter *,
|
---|
[8127] | 154 | SymbolStyle, const QwtOHLCSample &,
|
---|
[9383] | 155 | Qt::Orientation, bool inverted, double symbolWidth ) const;
|
---|
[8127] | 156 |
|
---|
[9383] | 157 | void drawBar( QPainter *painter, const QwtOHLCSample &,
|
---|
[8127] | 158 | Qt::Orientation, bool inverted, double width ) const;
|
---|
| 159 |
|
---|
[9383] | 160 | void drawCandleStick( QPainter *, const QwtOHLCSample &,
|
---|
[8127] | 161 | Qt::Orientation, double width ) const;
|
---|
| 162 |
|
---|
| 163 | virtual double scaledSymbolWidth(
|
---|
| 164 | const QwtScaleMap &xMap, const QwtScaleMap &yMap,
|
---|
| 165 | const QRectF &canvasRect ) const;
|
---|
| 166 |
|
---|
| 167 | private:
|
---|
| 168 | class PrivateData;
|
---|
| 169 | PrivateData *d_data;
|
---|
| 170 | };
|
---|
| 171 |
|
---|
| 172 | Q_DECLARE_OPERATORS_FOR_FLAGS( QwtPlotTradingCurve::PaintAttributes )
|
---|
| 173 |
|
---|
| 174 | #endif
|
---|