10 #include "qwt_plot_marker.h" 
   11 #include "qwt_painter.h" 
   12 #include "qwt_scale_map.h" 
   13 #include "qwt_symbol.h" 
   15 #include "qwt_graphic.h" 
   20 class QwtPlotMarker::PrivateData
 
   55     m_data = 
new PrivateData;
 
   63     m_data = 
new PrivateData;
 
   71     m_data = 
new PrivateData;
 
   90     return QPointF( m_data->xValue, m_data->yValue );
 
   96     return m_data->xValue;
 
  102     return m_data->yValue;
 
  114     if ( x != m_data->xValue || y != m_data->yValue )
 
  144     const QRectF& canvasRect )
 const 
  146     const QPointF pos( xMap.
transform( m_data->xValue ),
 
  164     const QRectF& canvasRect, 
const QPointF& pos )
 const 
  166     if ( m_data->style == 
NoLine )
 
  171     painter->setPen( m_data->pen );
 
  180             y, canvasRect.right() - 1.0, y );
 
  190             canvasRect.top(), x, canvasRect.bottom() - 1.0 );
 
  204     const QRectF& canvasRect, 
const QPointF& pos )
 const 
  206     if ( m_data->symbol == NULL )
 
  215         const QRectF clipRect = canvasRect.adjusted(
 
  216             -sz.width(), -sz.height(), sz.width(), sz.height() );
 
  218         if ( clipRect.contains( pos ) )
 
  233     const QRectF& canvasRect, 
const QPointF& pos )
 const 
  235     if ( m_data->label.isEmpty() )
 
  238     Qt::Alignment align = m_data->labelAlignment;
 
  239     QPointF alignPos = pos;
 
  241     QSizeF symbolOff( 0, 0 );
 
  243     switch ( m_data->style )
 
  250             if ( m_data->labelAlignment & Qt::AlignTop )
 
  252                 alignPos.setY( canvasRect.top() );
 
  253                 align &= ~Qt::AlignTop;
 
  254                 align |= Qt::AlignBottom;
 
  256             else if ( m_data->labelAlignment & Qt::AlignBottom )
 
  261                 alignPos.setY( canvasRect.bottom() - 1 );
 
  262                 align &= ~Qt::AlignBottom;
 
  263                 align |= Qt::AlignTop;
 
  267                 alignPos.setY( canvasRect.center().y() );
 
  273             if ( m_data->labelAlignment & Qt::AlignLeft )
 
  275                 alignPos.setX( canvasRect.left() );
 
  276                 align &= ~Qt::AlignLeft;
 
  277                 align |= Qt::AlignRight;
 
  279             else if ( m_data->labelAlignment & Qt::AlignRight )
 
  281                 alignPos.setX( canvasRect.right() - 1 );
 
  282                 align &= ~Qt::AlignRight;
 
  283                 align |= Qt::AlignLeft;
 
  287                 alignPos.setX( canvasRect.center().x() );
 
  293             if ( m_data->symbol &&
 
  296                 symbolOff = m_data->symbol->size() + QSizeF( 1, 1 );
 
  302     qreal pw2 = m_data->pen.widthF() / 2.0;
 
  306     const int spacing = m_data->spacing;
 
  308     const qreal xOff = qwtMaxF( pw2, symbolOff.width() );
 
  309     const qreal yOff = qwtMaxF( pw2, symbolOff.height() );
 
  311     const QSizeF textSize = m_data->label.textSize( painter->font() );
 
  313     if ( align & Qt::AlignLeft )
 
  315         alignPos.rx() -= xOff + 
spacing;
 
  316         if ( m_data->labelOrientation == Qt::Vertical )
 
  317             alignPos.rx() -= textSize.height();
 
  319             alignPos.rx() -= textSize.width();
 
  321     else if ( align & Qt::AlignRight )
 
  323         alignPos.rx() += xOff + 
spacing;
 
  327         if ( m_data->labelOrientation == Qt::Vertical )
 
  328             alignPos.rx() -= textSize.height() / 2;
 
  330             alignPos.rx() -= textSize.width() / 2;
 
  333     if ( align & Qt::AlignTop )
 
  335         alignPos.ry() -= yOff + 
spacing;
 
  336         if ( m_data->labelOrientation != Qt::Vertical )
 
  337             alignPos.ry() -= textSize.height();
 
  339     else if ( align & Qt::AlignBottom )
 
  341         alignPos.ry() += yOff + 
spacing;
 
  342         if ( m_data->labelOrientation == Qt::Vertical )
 
  343             alignPos.ry() += textSize.width();
 
  347         if ( m_data->labelOrientation == Qt::Vertical )
 
  348             alignPos.ry() += textSize.width() / 2;
 
  350             alignPos.ry() -= textSize.height() / 2;
 
  353     painter->translate( alignPos.x(), alignPos.y() );
 
  354     if ( m_data->labelOrientation == Qt::Vertical )
 
  355         painter->rotate( -90.0 );
 
  357     const QRectF textRect( 0, 0, textSize.width(), textSize.height() );
 
  358     m_data->label.draw( painter, textRect );
 
  368     if ( style != m_data->style )
 
  370         m_data->style = style;
 
  383     return m_data->style;
 
  393     if ( 
symbol != m_data->symbol )
 
  395         delete m_data->symbol;
 
  412     return m_data->symbol;
 
  422     if ( 
label != m_data->label )
 
  424         m_data->label = 
label;
 
  435     return m_data->label;
 
  454     if ( align != m_data->labelAlignment )
 
  456         m_data->labelAlignment = align;
 
  467     return m_data->labelAlignment;
 
  482     if ( orientation != m_data->labelOrientation )
 
  484         m_data->labelOrientation = orientation;
 
  495     return m_data->labelOrientation;
 
  512     if ( 
spacing == m_data->spacing )
 
  525     return m_data->spacing;
 
  554     if ( pen != m_data->pen )
 
  576     switch (m_data->style)
 
  579             return QRectF( m_data->xValue, m_data->yValue, -1.0, 0.0 );
 
  582             return QRectF( m_data->xValue, m_data->yValue, 0.0, -1.0 );
 
  585             return QRectF( m_data->xValue, m_data->yValue, 0.0, 0.0 );
 
  602     if ( size.isEmpty() )
 
  609     QPainter painter( &icon );
 
  610     painter.setRenderHint( QPainter::Antialiasing,
 
  615         painter.setPen( m_data->pen );
 
  620             const double y = 0.5 * size.height();
 
  623                 0.0, y, size.width(), y );
 
  629             const double x = 0.5 * size.width();
 
  632                 x, 0.0, x, size.height() );
 
  636     if ( m_data->symbol )
 
  638         const QRect r( 0.0, 0.0, size.width(), size.height() );
 
  639         m_data->symbol->drawSymbol( &painter, r );
 
A paint device for scalable graphics.
void setRenderHint(RenderHint, bool on=true)
void setDefaultSize(const QSizeF &)
Set a default size.
static bool roundingAlignment()
static void drawLine(QPainter *, qreal x1, qreal y1, qreal x2, qreal y2)
Wrapper for QPainter::drawLine()
Base class for items on the plot canvas.
void setLegendIconSize(const QSize &)
virtual void legendChanged()
void setZ(double z)
Set the z value.
@ Rtti_PlotMarker
For QwtPlotMarker.
@ RenderAntialiased
Enable antialiasing.
bool testRenderHint(RenderHint) const
virtual void itemChanged()
A class for drawing markers.
void setXValue(double)
Set X Value.
void setLineStyle(LineStyle)
Set the line style.
LineStyle lineStyle() const
@ HLine
A horizontal line.
void setLabelOrientation(Qt::Orientation)
Set the orientation of the label.
virtual void drawLines(QPainter *, const QRectF &, const QPointF &) const
const QPen & linePen() const
void setYValue(double)
Set Y Value.
virtual void drawLabel(QPainter *, const QRectF &, const QPointF &) const
virtual void drawSymbol(QPainter *, const QRectF &, const QPointF &) const
Qt::Orientation labelOrientation() const
void setSpacing(int)
Set the spacing.
QwtPlotMarker()
Sets alignment to Qt::AlignCenter, and style to QwtPlotMarker::NoLine.
virtual int rtti() const override
virtual ~QwtPlotMarker()
Destructor.
virtual void draw(QPainter *, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &) const override
void setLinePen(const QColor &, qreal width=0.0, Qt::PenStyle=Qt::SolidLine)
double yValue() const
Return y Value.
void setLabelAlignment(Qt::Alignment)
Set the alignment of the label.
void setValue(double, double)
Set Value.
void setLabel(const QwtText &)
Set the label.
Qt::Alignment labelAlignment() const
double xValue() const
Return x Value.
QPointF value() const
Return Value.
virtual QRectF boundingRect() const override
void setSymbol(const QwtSymbol *)
Assign a symbol.
const QwtSymbol * symbol() const
virtual QwtGraphic legendIcon(int index, const QSizeF &) const override
double transform(double s) const
A class for drawing symbols.
void drawSymbol(QPainter *, const QRectF &) const
Draw the symbol into a rectangle.
virtual QRect boundingRect() const
@ NoSymbol
No Style. The symbol cannot be drawn.
const QSize & size() const
A class representing a text.