10#include "qwt_plot_tradingcurve.h" 
   11#include "qwt_scale_map.h" 
   12#include "qwt_painter.h" 
   14#include "qwt_graphic.h" 
   19static inline bool qwtIsSampleInside( 
const QwtOHLCSample& sample,
 
   20    double tMin, 
double tMax, 
double vMin, 
double vMax )
 
   22    const double t = sample.
time;
 
   25    const bool isOffScreen = ( t < tMin ) || ( t > tMax )
 
   31class QwtPlotTradingCurve::PrivateData
 
   37        , minSymbolWidth( 2.0 )
 
   38        , maxSymbolWidth( -1.0 )
 
   41        symbolBrush[0] = QBrush( Qt::white );
 
   42        symbolBrush[1] = QBrush( Qt::black );
 
   47    double minSymbolWidth;
 
   48    double maxSymbolWidth;
 
   51    QBrush symbolBrush[2]; 
 
   88    m_data = 
new PrivateData;
 
 
  111        m_data->paintAttributes |= attribute;
 
  113        m_data->paintAttributes &= ~attribute;
 
 
  123    return ( m_data->paintAttributes & attribute );
 
 
  164    if ( style != m_data->symbolStyle )
 
  166        m_data->symbolStyle = style;
 
 
  179    return m_data->symbolStyle;
 
 
  196    const QColor& color, qreal width, Qt::PenStyle style )
 
 
  211    if ( pen != m_data->symbolPen )
 
  213        m_data->symbolPen = pen;
 
 
  226    return m_data->symbolPen;
 
 
  239    Direction direction, 
const QBrush& brush )
 
  242    const int index = 
static_cast< int >( direction );
 
  243    if ( index < 0 || index >= 2 )
 
  246    if ( brush != m_data->symbolBrush[ index ] )
 
  248        m_data->symbolBrush[ index ] = brush;
 
 
  264    const int index = 
static_cast< int >( direction );
 
  265    if ( index < 0 || index >= 2 )
 
  268    return m_data->symbolBrush[ index ];
 
 
  286    extent = qwtMaxF( 0.0, extent );
 
  287    if ( extent != m_data->symbolExtent )
 
  289        m_data->symbolExtent = extent;
 
 
  303    return m_data->symbolExtent;
 
 
  314    width = qwtMaxF( width, 0.0 );
 
  315    if ( width != m_data->minSymbolWidth )
 
  317        m_data->minSymbolWidth = width;
 
 
  330    return m_data->minSymbolWidth;
 
 
  343    if ( width != m_data->maxSymbolWidth )
 
  345        m_data->maxSymbolWidth = width;
 
 
  358    return m_data->maxSymbolWidth;
 
 
  369        rect.setRect( rect.y(), rect.x(), rect.height(), rect.width() );
 
 
  389    const QRectF& canvasRect, 
int from, 
int to )
 const 
  403        drawSymbols( painter, xMap, yMap, canvasRect, from, to );
 
 
  422    const QRectF& canvasRect, 
int from, 
int to )
 const 
  427    double tMin, tMax, vMin, vMax;
 
  430    if ( orient == Qt::Vertical )
 
  452    const bool doClip = m_data->paintAttributes & 
ClipSymbols;
 
  457        symbolWidth = std::floor( 0.5 * symbolWidth ) * 2.0;
 
  459    QPen pen = m_data->symbolPen;
 
  460    pen.setCapStyle( Qt::FlatCap );
 
  462    painter->setPen( pen );
 
  464    for ( 
int i = from; i <= to; i++ )
 
  468        if ( !doClip || qwtIsSampleInside( s, tMin, tMax, vMin, vMax ) )
 
  478            const int brushIndex = ( s.
open < s.
close )
 
  484                translatedSample.
time = qRound( translatedSample.
time );
 
  485                translatedSample.
open = qRound( translatedSample.
open );
 
  486                translatedSample.
high = qRound( translatedSample.
high );
 
  487                translatedSample.
low = qRound( translatedSample.
low );
 
  488                translatedSample.
close = qRound( translatedSample.
close );
 
  491            switch( m_data->symbolStyle )
 
  495                    drawBar( painter, translatedSample,
 
  496                        orient, inverted, symbolWidth );
 
  501                    painter->setBrush( m_data->symbolBrush[ brushIndex ] );
 
  503                        orient, symbolWidth );
 
  510                        painter->setBrush( m_data->symbolBrush[ brushIndex ] );
 
  512                            translatedSample, orient, inverted, symbolWidth );
 
 
  536    Qt::Orientation orientation, 
bool inverted, 
double symbolWidth )
 const 
  542    Q_UNUSED( symbolWidth )
 
 
  564    bool inverted, 
double width )
 const 
  566    double w2 = 0.5 * width;
 
 
  626        const QRectF rect( 
sample.
open, t - 0.5 * width,
 
 
  643    const QSizeF& size )
 const 
  646    return defaultIcon( m_data->symbolPen.color(), size );
 
 
  666    const QRectF& canvasRect )
 const 
  668    Q_UNUSED( canvasRect );
 
  670    if ( m_data->maxSymbolWidth > 0.0 &&
 
  671        m_data->minSymbolWidth >= m_data->maxSymbolWidth )
 
  673        return m_data->minSymbolWidth;
 
  679    const double pos = map->
transform( map->
s1() + m_data->symbolExtent );
 
  681    double width = qAbs( pos - map->
p1() );
 
  683    width = qwtMaxF( width,  m_data->minSymbolWidth );
 
  684    if ( m_data->maxSymbolWidth > 0.0 )
 
  685        width = qwtMinF( width, m_data->maxSymbolWidth );
 
 
Template class for data, that is organized as QVector.
A paint device for scalable graphics.
A class representing an interval.
Open-High-Low-Close sample used in financial charts.
double high
Highest price.
double open
Opening price.
double close
Closing price.
QwtInterval boundingInterval() const
Calculate the bounding interval of the OHLC values.
static void drawRect(QPainter *, qreal x, qreal y, qreal w, qreal h)
Wrapper for QPainter::drawRect()
static bool roundingAlignment()
static void drawLine(QPainter *, qreal x1, qreal y1, qreal x2, qreal y2)
Wrapper for QPainter::drawLine()
virtual void legendChanged()
void setZ(double z)
Set the z value.
void setItemAttribute(ItemAttribute, bool on=true)
QwtGraphic defaultIcon(const QBrush &, const QSizeF &) const
Return a default icon from a brush.
@ Rtti_PlotTradingCurve
For QwtPlotTradingCurve.
virtual void itemChanged()
@ Legend
The item is represented on the legend.
Base class for plot items representing a series of samples.
Qt::Orientation orientation() const
virtual QRectF boundingRect() const override
QwtPlotTradingCurve illustrates movements in the price of a financial instrument over time.
void setSymbolStyle(SymbolStyle style)
QBrush symbolBrush(Direction) const
bool testPaintAttribute(PaintAttribute) const
void drawBar(QPainter *, const QwtOHLCSample &, Qt::Orientation, bool inverted, double width) const
Draw a bar.
SymbolStyle symbolStyle() const
void drawCandleStick(QPainter *, const QwtOHLCSample &, Qt::Orientation, double width) const
Draw a candle stick.
QFlags< PaintAttribute > PaintAttributes
double minSymbolWidth() const
virtual void drawUserSymbol(QPainter *, SymbolStyle, const QwtOHLCSample &, Qt::Orientation, bool inverted, double symbolWidth) const
Draw a symbol for a symbol style >= UserSymbol.
void setSamples(const QVector< QwtOHLCSample > &)
virtual QwtGraphic legendIcon(int index, const QSizeF &) const override
virtual QRectF boundingRect() const override
virtual void drawSymbols(QPainter *, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, int from, int to) const
virtual void drawSeries(QPainter *, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, int from, int to) const override
void setMinSymbolWidth(double)
double maxSymbolWidth() const
virtual ~QwtPlotTradingCurve()
Destructor.
void init()
Initialize internal members.
void setSymbolPen(const QColor &, qreal width=0.0, Qt::PenStyle=Qt::SolidLine)
void setSymbolExtent(double)
Set the extent of the symbol.
Direction
Direction of a price movement.
@ Increasing
The closing price is higher than the opening price.
@ Decreasing
The closing price is lower than the opening price.
void setPaintAttribute(PaintAttribute, bool on=true)
virtual double scaledSymbolWidth(const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect) const
void setSymbolBrush(Direction, const QBrush &)
double symbolExtent() const
SymbolStyle
Symbol styles.
@ NoSymbol
Nothing is displayed.
virtual int rtti() const override
void setMaxSymbolWidth(double)
QwtPlotTradingCurve(const QString &title=QString())
@ ClipSymbols
Check if a symbol is on the plot canvas before painting it.
double transform(double s) const
double invTransform(double p) const
QwtOHLCSample sample(int index) const
virtual size_t dataSize() const override
QwtSeriesData< QwtOHLCSample > * data()
void setData(QwtSeriesData< QwtOHLCSample > *series)
A class representing a text.