qwt_plot_tradingcurve.h 5.1 KB

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