/*! Draw the shape item \param painter Painter \param xMap X-Scale Map \param yMap Y-Scale Map \param canvasRect Contents rect of the plot canvas */ void QwtPlotShapeItem::draw( QPainter *painter, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect ) const { if ( d_data->shape.isEmpty() ) return; if ( d_data->pen.style() == Qt::NoPen && d_data->brush.style() == Qt::NoBrush ) { return; } const QRectF cRect = QwtScaleMap::invTransform( xMap, yMap, canvasRect.toRect() ); if ( d_data->boundingRect.intersects( cRect ) ) { const bool doAlign = QwtPainter::roundingAlignment( painter ); QPainterPath path = qwtTransformPath( xMap, yMap, d_data->shape, doAlign ); if ( testPaintAttribute( QwtPlotShapeItem::ClipPolygons ) ) { qreal pw = qMax( qreal( 1.0 ), painter->pen().widthF()); QRectF clipRect = canvasRect.adjusted( -pw, -pw, pw, pw ); QPainterPath clippedPath; clippedPath.setFillRule( path.fillRule() ); const QList<QPolygonF> polygons = path.toSubpathPolygons(); for ( int i = 0; i < polygons.size(); i++ ) { const QPolygonF p = QwtClipper::clipPolygonF( clipRect, polygons[i], true ); clippedPath.addPolygon( p ); } path = clippedPath; } if ( d_data->renderTolerance > 0.0 ) { QwtWeedingCurveFitter fitter( d_data->renderTolerance ); QPainterPath fittedPath; fittedPath.setFillRule( path.fillRule() ); const QList<QPolygonF> polygons = path.toSubpathPolygons(); for ( int i = 0; i < polygons.size(); i++ ) fittedPath.addPolygon( fitter.fitCurve( polygons[ i ] ) ); path = fittedPath; } painter->setPen( d_data->pen ); painter->setBrush( d_data->brush ); painter->drawPath( path ); } }
/*! Draw the shape item \param painter Painter \param xMap X-Scale Map \param yMap Y-Scale Map \param canvasRect Contents rect of the plot canvas */ void QwtPlotShapeItem::draw( QPainter *painter, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect ) const { if ( d_data->shape.isEmpty() ) return; if ( d_data->pen.style() == Qt::NoPen && d_data->brush.style() == Qt::NoBrush ) { return; } const QRectF cr = QwtScaleMap::invTransform( xMap, yMap, canvasRect.toRect() ); const QRectF &br = d_data->boundingRect; if ( ( br.left() > cr.right() ) || ( br.right() < cr.left() ) || ( br.top() > cr.bottom() ) || ( br.bottom() < cr.top() ) ) { // outside the visisble area return; } const bool doAlign = QwtPainter::roundingAlignment( painter ); QPainterPath path = qwtTransformPath( xMap, yMap, d_data->shape, doAlign ); if ( testPaintAttribute( QwtPlotShapeItem::ClipPolygons ) ) { const qreal pw = QwtPainter::effectivePenWidth( painter->pen() ); const QRectF clipRect = canvasRect.adjusted( -pw, -pw, pw, pw ); QPainterPath clippedPath; clippedPath.setFillRule( path.fillRule() ); QList<QPolygonF> polygons = path.toSubpathPolygons(); for ( int i = 0; i < polygons.size(); i++ ) { QwtClipper::clipPolygonF( clipRect, polygons[i], true ); clippedPath.addPolygon( polygons[i] ); } path = clippedPath; } if ( d_data->renderTolerance > 0.0 ) { QwtWeedingCurveFitter fitter( d_data->renderTolerance ); QPainterPath fittedPath; fittedPath.setFillRule( path.fillRule() ); const QList<QPolygonF> polygons = path.toSubpathPolygons(); for ( int i = 0; i < polygons.size(); i++ ) fittedPath.addPolygon( fitter.fitCurve( polygons[ i ] ) ); path = fittedPath; } painter->setPen( d_data->pen ); painter->setBrush( d_data->brush ); painter->drawPath( path ); }