10 #include "qwt_plot_shapeitem.h" 
   11 #include "qwt_scale_map.h" 
   13 #include "qwt_graphic.h" 
   14 #include "qwt_painter.h" 
   15 #include "qwt_weeding_curve_fitter.h" 
   16 #include "qwt_clipper.h" 
   20 #include <qpainterpath.h> 
   22 static QPainterPath qwtTransformPath( 
const QwtScaleMap& xMap,
 
   23     const QwtScaleMap& yMap, 
const QPainterPath& path, 
bool doAlign )
 
   26     shape.setFillRule( path.fillRule() );
 
   28     for ( 
int i = 0; i < path.elementCount(); i++ )
 
   30         const QPainterPath::Element element = path.elementAt( i );
 
   35         switch( element.type )
 
   37             case QPainterPath::MoveToElement:
 
   48             case QPainterPath::LineToElement:
 
   59             case QPainterPath::CurveToElement:
 
   61                 const QPainterPath::Element element1 = path.elementAt( ++i );
 
   62                 const double x1 = xMap.
transform( element1.x );
 
   63                 const double y1 = yMap.
transform( element1.y );
 
   65                 const QPainterPath::Element element2 = path.elementAt( ++i );
 
   66                 const double x2 = xMap.
transform( element2.x );
 
   67                 const double y2 = yMap.
transform( element2.y );
 
   69                 shape.cubicTo( x, y, x1, y1, x2, y2 );
 
   72             case QPainterPath::CurveToDataElement:
 
   83 class QwtPlotShapeItem::PrivateData
 
  139 void QwtPlotShapeItem::init()
 
  141     m_data = 
new PrivateData();
 
  166         m_data->paintAttributes |= attribute;
 
  168         m_data->paintAttributes &= ~attribute;
 
  177     return ( m_data->paintAttributes & attribute );
 
  188     if ( mode != m_data->legendMode )
 
  190         m_data->legendMode = mode;
 
  201     return m_data->legendMode;
 
  207     return m_data->boundingRect;
 
  219     path.addRect( rect );
 
  233     shape.addPolygon( polygon );
 
  246     if ( 
shape != m_data->shape )
 
  248         m_data->shape = 
shape;
 
  249         if ( 
shape.isEmpty() )
 
  255             m_data->boundingRect = 
shape.boundingRect();
 
  268     return m_data->shape;
 
  286     setPen( QPen( color, width, style ) );
 
  299     if ( 
pen != m_data->pen )
 
  325     if ( 
brush != m_data->brush )
 
  327         m_data->brush = 
brush;
 
  338     return m_data->brush;
 
  359     tolerance = qwtMaxF( tolerance, 0.0 );
 
  361     if ( tolerance != m_data->renderTolerance )
 
  363         m_data->renderTolerance = tolerance;
 
  374     return m_data->renderTolerance;
 
  387     const QRectF& canvasRect )
 const 
  389     if ( m_data->shape.isEmpty() )
 
  392     if ( m_data->pen.style() == Qt::NoPen
 
  393         && m_data->brush.style() == Qt::NoBrush )
 
  399         xMap, yMap, canvasRect.toRect() );
 
  401     const QRectF& br = m_data->boundingRect;
 
  403     if ( ( br.left() > cr.right() ) || ( br.right() < cr.left() )
 
  404         || ( br.top() > cr.bottom() ) || ( br.bottom() < cr.top() ) )
 
  412     QPainterPath path = qwtTransformPath( xMap, yMap,
 
  413         m_data->shape, doAlign );
 
  418         const QRectF clipRect = canvasRect.adjusted( -pw, -pw, pw, pw );
 
  420         QPainterPath clippedPath;
 
  421         clippedPath.setFillRule( path.fillRule() );
 
  424         for ( 
int i = 0; i < polygons.size(); i++ )
 
  427             clippedPath.addPolygon( polygons[i] );
 
  434     if ( m_data->renderTolerance > 0.0 )
 
  438         QPainterPath fittedPath;
 
  439         fittedPath.setFillRule( path.fillRule() );
 
  442         for ( 
int i = 0; i < polygons.size(); i++ )
 
  443             fittedPath.addPolygon( fitter.
fitCurve( polygons[ i ] ) );
 
  448     painter->setPen( m_data->pen );
 
  449     painter->setBrush( m_data->brush );
 
  451     painter->drawPath( path );
 
  464     const QSizeF& size )
 const 
  471     if ( size.isEmpty() )
 
  476         const QRectF& br = m_data->boundingRect;
 
  478         QPainter painter( &icon );
 
  479         painter.setRenderHint( QPainter::Antialiasing,
 
  482         painter.translate( -br.topLeft() );
 
  484         painter.setPen( m_data->pen );
 
  485         painter.setBrush( m_data->brush );
 
  486         painter.drawPath( m_data->shape );
 
  491         if ( m_data->brush.style() != Qt::NoBrush )
 
  492             iconColor = m_data->brush.color();
 
  494             iconColor = m_data->pen.color();
 
A paint device for scalable graphics.
void setDefaultSize(const QSizeF &)
Set a default size.
static qreal effectivePenWidth(const QPen &)
static bool roundingAlignment()
Base class for items on the plot canvas.
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_PlotShape
For QwtPlotShapeItem.
@ RenderAntialiased
Enable antialiasing.
bool testRenderHint(RenderHint) const
virtual void itemChanged()
@ Legend
The item is represented on the legend.
virtual QRectF boundingRect() const
A plot item, which displays any graphical shape, that can be defined by a QPainterPath.
bool testPaintAttribute(PaintAttribute) const
virtual QRectF boundingRect() const override
Bounding rectangle of the shape.
void setRect(const QRectF &)
Set a path built from a rectangle.
void setShape(const QPainterPath &)
Set the shape to be displayed.
LegendMode
Mode how to display the item on the legend.
@ LegendColor
Display a filled rectangle.
@ LegendShape
Display a scaled down version of the shape.
void setLegendMode(LegendMode)
virtual QwtGraphic legendIcon(int index, const QSizeF &) const override
virtual void draw(QPainter *, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect) const override
virtual int rtti() const override
LegendMode legendMode() const
QwtPlotShapeItem(const QString &title=QString())
Constructor.
void setPen(const QColor &, qreal width=0.0, Qt::PenStyle=Qt::SolidLine)
void setRenderTolerance(double)
Set the tolerance for the weeding optimization.
void setPolygon(const QPolygonF &)
Set a path built from a polygon.
double renderTolerance() const
void setBrush(const QBrush &)
virtual ~QwtPlotShapeItem()
Destructor.
void setPaintAttribute(PaintAttribute, bool on=true)
QFlags< PaintAttribute > PaintAttributes
QPainterPath shape() const
double transform(double s) const
double invTransform(double p) const
A class representing a text.
A curve fitter implementing Douglas and Peucker algorithm.
virtual QPolygonF fitCurve(const QPolygonF &) const override
QWT_EXPORT void clipPolygonF(const QRectF &, QPolygonF &, bool closePolygon=false)