QWT 7.0.1
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Protected Member Functions | List of all members
QwtPlotTradingCurve Class Reference

QwtPlotTradingCurve illustrates movements in the price of a financial instrument over time. More...

#include <qwt_plot_tradingcurve.h>

Inheritance diagram for QwtPlotTradingCurve:
QwtPlotSeriesItem QwtSeriesStore< QwtOHLCSample > QwtPlotItem QwtAbstractSeriesStore QwtAbstractSeriesStore

Classes

class  PrivateData
 

Public Types

enum  SymbolStyle { NoSymbol = -1 , Bar , CandleStick , UserSymbol = 100 }
 Symbol styles. More...
 
enum  Direction { Increasing , Decreasing }
 Direction of a price movement. More...
 
enum  PaintAttribute { ClipSymbols = 0x01 }
 Attributes to modify the drawing algorithm. More...
 
- Public Types inherited from QwtPlotItem
enum  RttiValues {
  Rtti_PlotItem = 0 , Rtti_PlotGrid , Rtti_PlotScale , Rtti_PlotLegend ,
  Rtti_PlotMarker , Rtti_PlotCurve , Rtti_PlotSpectroCurve , Rtti_PlotIntervalCurve ,
  Rtti_PlotHistogram , Rtti_PlotSpectrogram , Rtti_PlotGraphic , Rtti_PlotTradingCurve ,
  Rtti_PlotBarChart , Rtti_PlotMultiBarChart , Rtti_PlotShape , Rtti_PlotTextLabel ,
  Rtti_PlotZone , Rtti_PlotVectorField , Rtti_PlotUserItem = 1000
}
 Runtime type information. More...
 
enum  ItemAttribute { Legend = 0x01 , AutoScale = 0x02 , Margins = 0x04 }
 Plot Item Attributes. More...
 
enum  ItemInterest { ScaleInterest = 0x01 , LegendInterest = 0x02 }
 Plot Item Interests/绘图项关注的事件类型 More...
 
enum  RenderHint { RenderAntialiased = 0x1 }
 Render hints. More...
 

Public Member Functions

 QwtPlotTradingCurve (const QString &title=QString())
 Constructor.
 
 QwtPlotTradingCurve (const QwtText &title)
 Constructor.
 
virtual ~QwtPlotTradingCurve ()
 Destructor.
 
virtual int rtti () const QWT_OVERRIDE
 
void setPaintAttribute (PaintAttribute, bool on=true)
 Specify an attribute how to draw the curve.
 
bool testPaintAttribute (PaintAttribute) const
 
void setSamples (const QVector< QwtOHLCSample > &)
 Initialize data with an array of samples.
 
void setSamples (QwtSeriesData< QwtOHLCSample > *)
 Assign a series of samples.
 
void setSymbolStyle (SymbolStyle style)
 Set the symbol style.
 
SymbolStyle symbolStyle () const
 
void setSymbolPen (const QColor &, qreal width=0.0, Qt::PenStyle=Qt::SolidLine)
 Build and assign the symbol pen.
 
void setSymbolPen (const QPen &)
 Set the symbol pen.
 
QPen symbolPen () const
 
void setSymbolBrush (Direction, const QBrush &)
 Set the symbol brush.
 
QBrush symbolBrush (Direction) const
 
void setSymbolExtent (double)
 Set the extent of the symbol.
 
double symbolExtent () const
 
void setMinSymbolWidth (double)
 Set a minimum for the symbol width.
 
double minSymbolWidth () const
 
void setMaxSymbolWidth (double)
 Set a maximum for the symbol width.
 
double maxSymbolWidth () const
 
virtual void drawSeries (QPainter *, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, int from, int to) const QWT_OVERRIDE
 Draw an interval of the curve.
 
virtual QRectF boundingRect () const QWT_OVERRIDE
 
virtual QwtGraphic legendIcon (int index, const QSizeF &) const QWT_OVERRIDE
 
- Public Member Functions inherited from QwtPlotSeriesItem
 QwtPlotSeriesItem (const QString &title=QString())
 Constructor.
 
 QwtPlotSeriesItem (const QwtText &title)
 Constructor.
 
virtual ~QwtPlotSeriesItem ()
 Destructor.
 
void setOrientation (Qt::Orientation)
 Set the orientation of the item.
 
Qt::Orientation orientation () const
 
virtual void draw (QPainter *, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect) const QWT_OVERRIDE
 Draw the complete series.
 
virtual void updateScaleDiv (const QwtScaleDiv &, const QwtScaleDiv &) QWT_OVERRIDE
 Update the item to changes of the axes scale division.
 
- Public Member Functions inherited from QwtPlotItem
 QwtPlotItem ()
 Constructor.
 
 QwtPlotItem (const QString &title)
 Constructor.
 
 QwtPlotItem (const QwtText &title)
 Constructor.
 
virtual ~QwtPlotItem ()
 Destroy the QwtPlotItem.
 
void attach (QwtPlot *plot)
 Attach the item to a plot.
 
void detach ()
 This method detaches a QwtPlotItem from any QwtPlot it has been associated with.
 
QwtPlotplot () const
 Return attached plot.
 
void setTitle (const QString &title)
 Set a new title.
 
void setTitle (const QwtText &title)
 Set a new title.
 
const QwtTexttitle () const
 
void setItemAttribute (ItemAttribute, bool on=true)
 Toggle an item attribute.
 
bool testItemAttribute (ItemAttribute) const
 Test an item attribute.
 
void setItemInterest (ItemInterest, bool on=true)
 Toggle an item interest.
 
bool testItemInterest (ItemInterest) const
 Test an item interest.
 
void setRenderHint (RenderHint, bool on=true)
 Toggle an render hint.
 
bool testRenderHint (RenderHint) const
 Test a render hint.
 
void setRenderThreadCount (uint numThreads)
 On multi core systems rendering of certain plot item ( f.e QwtPlotRasterItem ) can be done in parallel in several threads.
 
uint renderThreadCount () const
 
void setLegendIconSize (const QSize &)
 Set the size of the legend icon.
 
QSize legendIconSize () const
 
double z () const
 Plot items are painted in increasing z-order.
 
void setZ (double z)
 Set the z value.
 
void show ()
 Show the item.
 
void hide ()
 Hide the item.
 
virtual void setVisible (bool)
 Show/Hide the item.
 
bool isVisible () const
 
void setAxes (QwtAxisId xAxis, QwtAxisId yAxis)
 Set X and Y axis.
 
void setXAxis (QwtAxisId)
 Set the X axis.
 
QwtAxisId xAxis () const
 Return xAxis.
 
void setYAxis (QwtAxisId)
 Set the Y axis.
 
QwtAxisId yAxis () const
 Return yAxis.
 
virtual void itemChanged ()
 Update the legend and call QwtPlot::autoRefresh() for the parent plot.
 
virtual void legendChanged ()
 Update the legend of the parent plot.
 
virtual void getCanvasMarginHint (const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, double &left, double &top, double &right, double &bottom) const
 Calculate a hint for the canvas margin.
 
virtual void updateLegend (const QwtPlotItem *, const QList< QwtLegendData > &)
 Update the item to changes of the legend info.
 
QRectF scaleRect (const QwtScaleMap &, const QwtScaleMap &) const
 Calculate the bounding scale rectangle of 2 maps.
 
QRectF paintRect (const QwtScaleMap &, const QwtScaleMap &) const
 Calculate the bounding paint rectangle of 2 maps.
 
virtual QList< QwtLegendDatalegendData () const
 Return all information, that is needed to represent the item on the legend.
 
- Public Member Functions inherited from QwtAbstractSeriesStore
virtual ~QwtAbstractSeriesStore ()
 Destructor.
 
- Public Member Functions inherited from QwtSeriesStore< QwtOHLCSample >
 QwtSeriesStore ()
 Constructor The store contains no series.
 
 ~QwtSeriesStore ()
 Destructor.
 
void setData (QwtSeriesData< QwtOHLCSample > *series)
 Assign a series of samples.
 
QwtSeriesData< QwtOHLCSample > * data ()
 
const QwtSeriesData< QwtOHLCSample > * data () const
 
QwtOHLCSample sample (size_t index) const
 
virtual size_t dataSize () const QWT_OVERRIDE
 
virtual QRectF dataRect () const QWT_OVERRIDE
 
virtual void setRectOfInterest (const QRectF &rect) QWT_OVERRIDE
 Set a the "rect of interest" for the series.
 
QwtSeriesData< QwtOHLCSample > * swapData (QwtSeriesData< QwtOHLCSample > *series)
 Replace a series without deleting the previous one.
 

Protected Member Functions

void init ()
 Initialize internal members.
 
virtual void drawSymbols (QPainter *, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, int from, int to) const
 Draw symbols.
 
virtual void drawUserSymbol (QPainter *, SymbolStyle, const QwtOHLCSample &, Qt::Orientation, bool inverted, double symbolWidth) const
 Draw a symbol for a symbol style >= UserSymbol.
 
void drawBar (QPainter *, const QwtOHLCSample &, Qt::Orientation, bool inverted, double width) const
 Draw a bar.
 
void drawCandleStick (QPainter *, const QwtOHLCSample &, Qt::Orientation, double width) const
 Draw a candle stick.
 
virtual double scaledSymbolWidth (const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect) const
 Calculate the symbol width in paint coordinates.
 
- Protected Member Functions inherited from QwtPlotSeriesItem
virtual void dataChanged () QWT_OVERRIDE
 dataChanged() indicates, that the series has been changed.
 
- Protected Member Functions inherited from QwtPlotItem
QwtGraphic defaultIcon (const QBrush &, const QSizeF &) const
 Return a default icon from a brush.
 

Detailed Description

QwtPlotTradingCurve illustrates movements in the price of a financial instrument over time.

QwtPlotTradingCurve supports candlestick or bar ( OHLC ) charts that are used in the domain of technical analysis.

While the length ( height or width depending on orientation() ) of each symbol depends on the corresponding OHLC sample the size of the other dimension can be controlled using:

The extent is a size in scale coordinates, so that the symbol width is increasing when the plot is zoomed in. Minimum/Maximum width is in widget coordinates independent from the zoom level. When setting the minimum and maximum to the same value, the width of the symbol is fixed.

Member Enumeration Documentation

◆ Direction

Direction of a price movement.

Enumerator
Increasing 

The closing price is higher than the opening price.

Decreasing 

The closing price is lower than the opening price.

◆ PaintAttribute

Attributes to modify the drawing algorithm.

See also
setPaintAttribute(), testPaintAttribute()
Enumerator
ClipSymbols 

Check if a symbol is on the plot canvas before painting it.

◆ SymbolStyle

Symbol styles.

The default setting is QwtPlotSeriesItem::CandleStick.

See also
setSymbolStyle(), symbolStyle()
Enumerator
NoSymbol 

Nothing is displayed.

Bar 

A line on the chart shows the price range (the highest and lowest prices) over one unit of time, e.g.

one day or one hour. Tick marks project from each side of the line indicating the opening and closing price.

CandleStick 

The range between opening/closing price are displayed as a filled box.

The fill brush depends on the direction of the price movement. The box is connected to the highest/lowest values by lines.

UserSymbol 

SymbolTypes >= UserSymbol are displayed by drawUserSymbol(), that needs to be overloaded and implemented in derived curve classes.

See also
drawUserSymbol()

Constructor & Destructor Documentation

◆ QwtPlotTradingCurve() [1/2]

QwtPlotTradingCurve::QwtPlotTradingCurve ( const QString &  title = QString())
explicit

Constructor.

Parameters
titleTitle of the curve

◆ QwtPlotTradingCurve() [2/2]

QwtPlotTradingCurve::QwtPlotTradingCurve ( const QwtText title)
explicit

Constructor.

Parameters
titleTitle of the curve

Member Function Documentation

◆ boundingRect()

QRectF QwtPlotTradingCurve::boundingRect ( ) const
virtual
Returns
Bounding rectangle of all samples. For an empty series the rectangle is invalid.

Reimplemented from QwtPlotSeriesItem.

◆ drawBar()

void QwtPlotTradingCurve::drawBar ( QPainter *  painter,
const QwtOHLCSample sample,
Qt::Orientation  orientation,
bool  inverted,
double  width 
) const
protected

Draw a bar.

Parameters
painterQt painter, initialized with pen/brush
sampleSample, already translated into paint device coordinates
orientationVertical or horizontal
invertedWhen inverted is false the open tick is painted to the left/top, otherwise it is painted right/bottom. The close tick is painted in the opposite direction of the open tick. painted in the opposite d opposite direction.
widthWidth or height of the candle, depending on the orientation
See also
Bar

◆ drawCandleStick()

void QwtPlotTradingCurve::drawCandleStick ( QPainter *  painter,
const QwtOHLCSample sample,
Qt::Orientation  orientation,
double  width 
) const
protected

Draw a candle stick.

Parameters
painterQt painter, initialized with pen/brush
sampleSamples already translated into paint device coordinates
orientationVertical or horizontal
widthWidth or height of the candle, depending on the orientation
See also
CandleStick

◆ drawSeries()

void QwtPlotTradingCurve::drawSeries ( QPainter *  painter,
const QwtScaleMap xMap,
const QwtScaleMap yMap,
const QRectF &  canvasRect,
int  from,
int  to 
) const
virtual

Draw an interval of the curve.

Parameters
painterPainter
xMapMaps x-values into pixel coordinates.
yMapMaps y-values into pixel coordinates.
canvasRectContents rectangle of the canvas
fromIndex of the first point to be painted
toIndex of the last point to be painted. If to < 0 the curve will be painted to its last point.
See also
drawSymbols()

Implements QwtPlotSeriesItem.

◆ drawSymbols()

void QwtPlotTradingCurve::drawSymbols ( QPainter *  painter,
const QwtScaleMap xMap,
const QwtScaleMap yMap,
const QRectF &  canvasRect,
int  from,
int  to 
) const
protectedvirtual

Draw symbols.

Parameters
painterPainter
xMapx map
yMapy map
canvasRectContents rectangle of the canvas
fromIndex of the first point to be painted
toIndex of the last point to be painted
See also
drawSeries()

◆ drawUserSymbol()

void QwtPlotTradingCurve::drawUserSymbol ( QPainter *  painter,
SymbolStyle  symbolStyle,
const QwtOHLCSample sample,
Qt::Orientation  orientation,
bool  inverted,
double  symbolWidth 
) const
protectedvirtual

Draw a symbol for a symbol style >= UserSymbol.

The implementation does nothing and is intended to be overloaded

Parameters
painterQt painter, initialized with pen/brush
symbolStyleSymbol style
sampleSamples already translated into paint device coordinates
orientationVertical or horizontal
invertedTrue, when the opposite scale ( Qt::Vertical: x, Qt::Horizontal: y ) is increasing in the opposite direction as QPainter coordinates.
symbolWidthWidth of the symbol in paint device coordinates

◆ legendIcon()

QwtGraphic QwtPlotTradingCurve::legendIcon ( int  index,
const QSizeF &  size 
) const
virtual
Returns
A rectangle filled with the color of the symbol pen
Parameters
indexIndex of the legend entry ( usually there is only one )
sizeIcon size
See also
setLegendIconSize(), legendData()

Reimplemented from QwtPlotItem.

◆ maxSymbolWidth()

double QwtPlotTradingCurve::maxSymbolWidth ( ) const
Returns
Maximum for the symbol width
See also
setMaxSymbolWidth(), minSymbolWidth(), symbolExtent()

◆ minSymbolWidth()

double QwtPlotTradingCurve::minSymbolWidth ( ) const
Returns
Minmum for the symbol width
See also
setMinSymbolWidth(), maxSymbolWidth(), symbolExtent()

◆ rtti()

int QwtPlotTradingCurve::rtti ( ) const
virtual
Returns
QwtPlotItem::Rtti_PlotTradingCurve

Reimplemented from QwtPlotItem.

◆ scaledSymbolWidth()

double QwtPlotTradingCurve::scaledSymbolWidth ( const QwtScaleMap xMap,
const QwtScaleMap yMap,
const QRectF &  canvasRect 
) const
protectedvirtual

Calculate the symbol width in paint coordinates.

The width is calculated by scaling the symbol extent into paint device coordinates bounded by the minimum/maximum symbol width.

Parameters
xMapMaps x-values into pixel coordinates.
yMapMaps y-values into pixel coordinates.
canvasRectContents rectangle of the canvas
Returns
Symbol width in paint coordinates
See also
symbolExtent(), minSymbolWidth(), maxSymbolWidth()

◆ setMaxSymbolWidth()

void QwtPlotTradingCurve::setMaxSymbolWidth ( double  width)

Set a maximum for the symbol width.

A value <= 0.0 means an unlimited width

Parameters
widthWidth in paint device coordinates
See also
maxSymbolWidth(), setMinSymbolWidth(), setSymbolExtent()

◆ setMinSymbolWidth()

void QwtPlotTradingCurve::setMinSymbolWidth ( double  width)

Set a minimum for the symbol width.

Parameters
widthWidth in paint device coordinates
See also
minSymbolWidth(), setMaxSymbolWidth(), setSymbolExtent()

◆ setPaintAttribute()

void QwtPlotTradingCurve::setPaintAttribute ( PaintAttribute  attribute,
bool  on = true 
)

Specify an attribute how to draw the curve.

Parameters
attributePaint attribute
onOn/Off
See also
testPaintAttribute()

◆ setSamples() [1/2]

void QwtPlotTradingCurve::setSamples ( const QVector< QwtOHLCSample > &  samples)

Initialize data with an array of samples.

Parameters
samplesVector of samples
See also
QwtPlotSeriesItem::setData()

◆ setSamples() [2/2]

void QwtPlotTradingCurve::setSamples ( QwtSeriesData< QwtOHLCSample > *  data)

Assign a series of samples.

setSamples() is just a wrapper for setData() without any additional value - beside that it is easier to find for the developer.

Parameters
dataData
Warning
The item takes ownership of the data object, deleting it when its not used anymore.

◆ setSymbolBrush()

void QwtPlotTradingCurve::setSymbolBrush ( Direction  direction,
const QBrush &  brush 
)

Set the symbol brush.

Parameters
directionDirection type
brushBrush used to fill the body of all candlestick symbols with the direction
See also
symbolBrush(), setSymbolPen()

◆ setSymbolExtent()

void QwtPlotTradingCurve::setSymbolExtent ( double  extent)

Set the extent of the symbol.

The width of the symbol is given in scale coordinates. When painting a symbol the width is scaled into paint device coordinates by scaledSymbolWidth(). The scaled width is bounded by minSymbolWidth(), maxSymbolWidth()

Parameters
extentSymbol width in scale coordinates
See also
symbolExtent(), scaledSymbolWidth(), setMinSymbolWidth(), setMaxSymbolWidth()

◆ setSymbolPen() [1/2]

void QwtPlotTradingCurve::setSymbolPen ( const QColor &  color,
qreal  width = 0.0,
Qt::PenStyle  style = Qt::SolidLine 
)

Build and assign the symbol pen.

In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it non cosmetic ( see QPen::isCosmetic() ). This method has been introduced to hide this incompatibility.

Parameters
colorPen color
widthPen width
stylePen style
See also
pen(), brush()

◆ setSymbolPen() [2/2]

void QwtPlotTradingCurve::setSymbolPen ( const QPen &  pen)

Set the symbol pen.

The symbol pen is used for rendering the lines of the bar or candlestick symbols

See also
symbolPen(), setSymbolBrush()

◆ setSymbolStyle()

void QwtPlotTradingCurve::setSymbolStyle ( SymbolStyle  style)

Set the symbol style.

Parameters
styleSymbol style
See also
symbolStyle(), setSymbolExtent(), setSymbolPen(), setSymbolBrush()

◆ symbolBrush()

QBrush QwtPlotTradingCurve::symbolBrush ( Direction  direction) const
Parameters
direction
Returns
Brush used to fill the body of all candlestick symbols with the direction
See also
setSymbolPen(), symbolBrush()

◆ symbolExtent()

double QwtPlotTradingCurve::symbolExtent ( ) const
Returns
Extent of a symbol in scale coordinates
See also
setSymbolExtent(), scaledSymbolWidth(), minSymbolWidth(), maxSymbolWidth()

◆ symbolPen()

QPen QwtPlotTradingCurve::symbolPen ( ) const
Returns
Symbol pen
See also
setSymbolPen(), symbolBrush()

◆ symbolStyle()

QwtPlotTradingCurve::SymbolStyle QwtPlotTradingCurve::symbolStyle ( ) const
Returns
Symbol style
See also
setSymbolStyle(), symbolExtent(), symbolPen(), symbolBrush()

◆ testPaintAttribute()

bool QwtPlotTradingCurve::testPaintAttribute ( PaintAttribute  attribute) const
Returns
True, when attribute is enabled
See also
PaintAttribute, setPaintAttribute()

The documentation for this class was generated from the following files: