Public Types | Public Member Functions

QwtSymbol Class Reference

A class for drawing symbols. More...

#include <qwt_symbol.h>

List of all members.

Public Types

enum  Style {
  NoSymbol = -1, Ellipse, Rect, Diamond,
  Triangle, DTriangle, UTriangle, LTriangle,
  RTriangle, Cross, XCross, HLine,
  VLine, Star1, Star2, Hexagon,
  StyleCnt
}

Public Member Functions

 QwtSymbol ()
 QwtSymbol (Style st, const QBrush &bd, const QPen &pn, const QSize &s)
 Constructor.
virtual ~QwtSymbol ()
 Destructor.
bool operator!= (const QwtSymbol &) const
 != operator
virtual bool operator== (const QwtSymbol &) const
 == operator
virtual QwtSymbolclone () const
void setSize (const QSize &s)
void setSize (int a, int b=-1)
 Specify the symbol's size.
void setBrush (const QBrush &b)
 Assign a brush.
void setPen (const QPen &p)
void setStyle (Style s)
 Specify the symbol style.
const QBrush & brush () const
 Return Brush.
const QPen & pen () const
 Return Pen.
const QSize & size () const
 Return Size.
Style style () const
 Return Style.
void draw (QPainter *p, const QPoint &pt) const
 Draw the symbol at a specified point.
void draw (QPainter *p, int x, int y) const
 Draw the symbol at a point (x,y).
virtual void draw (QPainter *p, const QRect &r) const
 Draw the symbol into a bounding rectangle.

Detailed Description

A class for drawing symbols.

Definition at line 22 of file qwt_symbol.h.


Member Enumeration Documentation

Style

See also:
setStyle(), style()
Enumerator:
NoSymbol 
Ellipse 
Rect 
Diamond 
Triangle 
DTriangle 
UTriangle 
LTriangle 
RTriangle 
Cross 
XCross 
HLine 
VLine 
Star1 
Star2 
Hexagon 
StyleCnt 

Definition at line 29 of file qwt_symbol.h.


Constructor & Destructor Documentation

QwtSymbol::QwtSymbol (  )

Default Constructor

The symbol is constructed with gray interior, black outline with zero width, no size and style 'NoSymbol'.

Definition at line 22 of file qwt_symbol.cpp.

Referenced by clone().

                    : 
    d_brush(Qt::gray), 
    d_pen(Qt::black), 
    d_size(0,0),
    d_style(QwtSymbol::NoSymbol)
{
}
QwtSymbol::QwtSymbol ( QwtSymbol::Style  style,
const QBrush &  brush,
const QPen &  pen,
const QSize &  size 
)

Constructor.

Parameters:
styleSymbol Style
brushbrush to fill the interior
penoutline pen
sizesize

Definition at line 37 of file qwt_symbol.cpp.

                                           : 
    d_brush(brush), 
    d_pen(pen), 
    d_size(size),
    d_style(style)
{
}
QwtSymbol::~QwtSymbol (  ) [virtual]

Destructor.

Definition at line 47 of file qwt_symbol.cpp.

{
}

Member Function Documentation

const QBrush& QwtSymbol::brush (  ) const [inline]
QwtSymbol * QwtSymbol::clone (  ) const [virtual]

Allocate and return a symbol with the same attributes

Returns:
Cloned symbol

Definition at line 55 of file qwt_symbol.cpp.

References QwtSymbol().

Referenced by QwtLegendItem::QwtLegendItem(), QwtPlotMarker::setSymbol(), QwtPlotCurve::setSymbol(), and QwtLegendItem::setSymbol().

{
    QwtSymbol *other = new QwtSymbol;
    *other = *this;

    return other;
}
void QwtSymbol::draw ( QPainter *  painter,
const QRect &  r 
) const [virtual]

Draw the symbol into a bounding rectangle.

This function assumes that the painter has been initialized with brush and pen before. This allows a much more performant implementation when painting many symbols with the same brush and pen like in curves.

Parameters:
painterPainter
rBounding rectangle

Definition at line 135 of file qwt_symbol.cpp.

References Cross, Diamond, QwtPainter::drawEllipse(), QwtPainter::drawLine(), QwtPainter::drawPolygon(), QwtPainter::drawRect(), DTriangle, Ellipse, Hexagon, HLine, int(), LTriangle, Rect, RTriangle, Star1, Star2, Triangle, UTriangle, VLine, and XCross.

{
    switch(d_style)
    {
        case QwtSymbol::Ellipse:
            QwtPainter::drawEllipse(painter, r);
            break;
        case QwtSymbol::Rect:
            QwtPainter::drawRect(painter, r);
            break;
        case QwtSymbol::Diamond:
        {
            const int w2 = r.width() / 2;
            const int h2 = r.height() / 2;

            QwtPolygon pa(4);
            pa.setPoint(0, r.x() + w2, r.y());
            pa.setPoint(1, r.right(), r.y() + h2);
            pa.setPoint(2, r.x() + w2, r.bottom());
            pa.setPoint(3, r.x(), r.y() + h2);
            QwtPainter::drawPolygon(painter, pa);
            break;
        }
        case QwtSymbol::Cross:
        {
            const int w2 = r.width() / 2;
            const int h2 = r.height() / 2;

            QwtPainter::drawLine(painter, r.x() + w2, r.y(), 
                r.x() + w2, r.bottom());
            QwtPainter::drawLine(painter, r.x(), r.y() + h2, 
                r.right(), r.y() + h2);
            break;
        }
        case QwtSymbol::XCross:
        {
            QwtPainter::drawLine(painter, r.left(), r.top(), 
                r.right(), r.bottom());
            QwtPainter::drawLine(painter, r.left(), r.bottom(), 
                r.right(), r.top());
            break;
        }
        case QwtSymbol::Triangle:
        case QwtSymbol::UTriangle:
        {
            const int w2 = r.width() / 2;

            QwtPolygon pa(3);
            pa.setPoint(0, r.x() + w2, r.y());
            pa.setPoint(1, r.right(), r.bottom());
            pa.setPoint(2, r.x(), r.bottom());
            QwtPainter::drawPolygon(painter, pa);
            break;
        }
        case QwtSymbol::DTriangle:
        {
            const int w2 = r.width() / 2;

            QwtPolygon pa(3);
            pa.setPoint(0, r.x(), r.y());
            pa.setPoint(1, r.right(), r.y());
            pa.setPoint(2, r.x() + w2, r.bottom());
            QwtPainter::drawPolygon(painter, pa);
            break;
        }
        case QwtSymbol::RTriangle:
        {
            const int h2 = r.height() / 2;

            QwtPolygon pa(3);
            pa.setPoint(0, r.x(), r.y());
            pa.setPoint(1, r.right(), r.y() + h2);
            pa.setPoint(2, r.x(), r.bottom());
            QwtPainter::drawPolygon(painter, pa);
            break;
        }
        case QwtSymbol::LTriangle:
        {
            const int h2 = r.height() / 2;

            QwtPolygon pa(3);
            pa.setPoint(0, r.right(), r.y());
            pa.setPoint(1, r.x(), r.y() + h2);
            pa.setPoint(2, r.right(), r.bottom());
            QwtPainter::drawPolygon(painter, pa);
            break;
        }
        case QwtSymbol::HLine:
        {
            const int h2 = r.height() / 2;
            QwtPainter::drawLine(painter, r.left(), r.top() + h2,
                    r.right(), r.top() + h2);
            break;
        }
        case QwtSymbol::VLine:
        {
            const int w2 = r.width() / 2;
            QwtPainter::drawLine(painter, r.left() + w2, r.top(),
                    r.left() + w2, r.bottom());
            break;
        }
        case QwtSymbol::Star1:
        {
            const double sqrt1_2 = 0.70710678118654752440; /* 1/sqrt(2) */

            const int w2 = r.width() / 2;
            const int h2 = r.height() / 2;
            const int d1  = (int)( (double)w2 * (1.0 - sqrt1_2) );

            QwtPainter::drawLine(painter, r.left() + d1, r.top() + d1,
                    r.right() - d1, r.bottom() - d1);
            QwtPainter::drawLine(painter, r.left() + d1, r.bottom() - d1,
                    r.right() - d1, r.top() + d1);
            QwtPainter::drawLine(painter, r.left() + w2, r.top(),
                    r.left() + w2, r.bottom());
            QwtPainter::drawLine(painter, r.left(), r.top() + h2,
                    r.right(), r.top() + h2);
            break;
        }
        case QwtSymbol::Star2:
        {
            const int w = r.width();
            const int side = (int)(((double)r.width() * (1.0 - 0.866025)) /
                2.0);  // 0.866025 = cos(30°)
            const int h4 = r.height() / 4;
            const int h2 = r.height() / 2;
            const int h34 = (r.height() * 3) / 4;

            QwtPolygon pa(12);
            pa.setPoint(0, r.left() + (w / 2), r.top());
            pa.setPoint(1, r.right() - (side + (w - 2 * side) / 3),
                r.top() + h4 );
            pa.setPoint(2, r.right() - side, r.top() + h4);
            pa.setPoint(3, r.right() - (side + (w / 2 - side) / 3),
                r.top() + h2 );
            pa.setPoint(4, r.right() - side, r.top() + h34);
            pa.setPoint(5, r.right() - (side + (w - 2 * side) / 3),
                r.top() + h34 );
            pa.setPoint(6, r.left() + (w / 2), r.bottom());
            pa.setPoint(7, r.left() + (side + (w - 2 * side) / 3),
                r.top() + h34 );
            pa.setPoint(8, r.left() + side, r.top() + h34);
            pa.setPoint(9, r.left() + (side + (w / 2 - side) / 3),
                r.top() + h2 );
            pa.setPoint(10, r.left() + side, r.top() + h4);
            pa.setPoint(11, r.left() + (side + (w - 2 * side) / 3),
                r.top() + h4 );
            QwtPainter::drawPolygon(painter, pa);
            break;
        }
        case QwtSymbol::Hexagon:
        {
            const int w2 = r.width() / 2;
            const int side = (int)(((double)r.width() * (1.0 - 0.866025)) /
                2.0);  // 0.866025 = cos(30°)
            const int h4 = r.height() / 4;
            const int h34 = (r.height() * 3) / 4;

            QwtPolygon pa(6);
            pa.setPoint(0, r.left() + w2, r.top());
            pa.setPoint(1, r.right() - side, r.top() + h4);
            pa.setPoint(2, r.right() - side, r.top() + h34);
            pa.setPoint(3, r.left() + w2, r.bottom());
            pa.setPoint(4, r.left() + side, r.top() + h34);
            pa.setPoint(5, r.left() + side, r.top() + h4);
            QwtPainter::drawPolygon(painter, pa);
            break;
        }
        default:;
    }
}
void QwtSymbol::draw ( QPainter *  painter,
const QPoint &  pos 
) const

Draw the symbol at a specified point.

Parameters:
painterPainter
posCenter of the symbol

Definition at line 313 of file qwt_symbol.cpp.

References QwtPainter::metricsMap(), and QwtPainter::scaledPen().

Referenced by draw(), QwtPlotMarker::drawAt(), QwtLegendItem::drawIdentifier(), and QwtPlotCurve::drawSymbols().

{
    QRect rect;
    rect.setSize(QwtPainter::metricsMap().screenToLayout(d_size));
    rect.moveCenter(pos);

    painter->setBrush(d_brush);
    painter->setPen(QwtPainter::scaledPen(d_pen));
    
    draw(painter, rect);
}
void QwtSymbol::draw ( QPainter *  p,
int  x,
int  y 
) const

Draw the symbol at a point (x,y).

Definition at line 119 of file qwt_symbol.cpp.

References draw().

{
    draw(painter, QPoint(x, y));
}
bool QwtSymbol::operator!= ( const QwtSymbol other ) const

!= operator

Definition at line 361 of file qwt_symbol.cpp.

{
    return !(*this == other);
}
bool QwtSymbol::operator== ( const QwtSymbol other ) const [virtual]

== operator

Definition at line 354 of file qwt_symbol.cpp.

References brush(), pen(), size(), and style().

{
    return brush() == other.brush() && pen() == other.pen()
            && style() == other.style() && size() == other.size();
}
const QPen& QwtSymbol::pen (  ) const [inline]
void QwtSymbol::setBrush ( const QBrush &  brush )

Assign a brush.

The brush is used to draw the interior of the symbol.

Parameters:
brushBrush

Definition at line 95 of file qwt_symbol.cpp.

References brush().

Referenced by QwtPlotPrintFilter::apply(), and QwtPlotPrintFilter::reset().

{
    d_brush = brush;
}
void QwtSymbol::setPen ( const QPen &  pen )

Assign a pen

The pen is used to draw the symbol's outline.

The width of non cosmetic pens is scaled according to the resolution of the paint device.

Parameters:
penPen
See also:
pen(), setBrush(), QwtPainter::scaledPen()

Definition at line 111 of file qwt_symbol.cpp.

References pen().

Referenced by QwtPlotPrintFilter::apply(), and QwtPlotPrintFilter::reset().

{
    d_pen = pen;
}
void QwtSymbol::setSize ( const QSize &  size )

Set the symbol's size

Parameters:
sizeSize

Definition at line 83 of file qwt_symbol.cpp.

{
    if (size.isValid()) 
        d_size = size;
}
void QwtSymbol::setSize ( int  width,
int  height = -1 
)

Specify the symbol's size.

If the 'h' parameter is left out or less than 0, and the 'w' parameter is greater than or equal to 0, the symbol size will be set to (w,w).

Parameters:
widthWidth
heightHeight (defaults to -1)

Definition at line 72 of file qwt_symbol.cpp.

{
    if ((width >= 0) && (height < 0)) 
        height = width;
    d_size = QSize(width, height);
}
void QwtSymbol::setStyle ( QwtSymbol::Style  s )

Specify the symbol style.

The following styles are defined:

NoSymbol
No Style. The symbol cannot be drawn.
Ellipse
Ellipse or circle
Rect
Rectangle
Diamond
Diamond
Triangle
Triangle pointing upwards
DTriangle
Triangle pointing downwards
UTriangle
Triangle pointing upwards
LTriangle
Triangle pointing left
RTriangle
Triangle pointing right
Cross
Cross (+)
XCross
Diagonal cross (X)
HLine
Horizontal line
VLine
Vertical line
Star1
X combined with +
Star2
Six-pointed star
Hexagon
Hexagon
Parameters:
sstyle

Definition at line 348 of file qwt_symbol.cpp.

{
    d_style = s;
}
const QSize& QwtSymbol::size (  ) const [inline]

Return Size.

Definition at line 73 of file qwt_symbol.h.

Referenced by QwtLegendItem::drawIdentifier(), QwtPlotCurve::drawSymbols(), and operator==().

{ return d_size; }
Style QwtSymbol::style (  ) const [inline]

Return Style.

Definition at line 75 of file qwt_symbol.h.

Referenced by QwtPlotCurve::draw(), QwtPlotMarker::drawAt(), QwtLegendItem::drawIdentifier(), and operator==().

{ return d_style; } 

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines