Exemple #1
0
/*!
  Draw symbols

  \param painter Painter
  \param symbol Curve symbol
  \param azimuthMap Maps azimuth values to values related to 0.0, M_2PI
  \param radialMap Maps radius values into painter coordinates.
  \param pole Position of the pole in painter coordinates
  \param from index of the first point to be painted
  \param to index of the last point to be painted.

  \sa setSymbol(), draw(), drawCurve()
*/
void QwtPolarCurve::drawSymbols( QPainter *painter, const QwtSymbol &symbol,
    const QwtScaleMap &azimuthMap, const QwtScaleMap &radialMap,
    const QPointF &pole, int from, int to ) const
{
    painter->setBrush( symbol.brush() );
    painter->setPen( symbol.pen() );

    const int chunkSize = 500;

    for ( int i = from; i <= to; i += chunkSize )
    {
        const int n = qMin( chunkSize, to - i + 1 );

        QPolygonF points;
        for ( int j = 0; j < n; j++ )
        {
            const QwtPointPolar point = sample( i + j );

            if ( !qwtInsidePole( radialMap, point.radius() ) )
            {
                const double r = radialMap.transform( point.radius() );
                const double a = azimuthMap.transform( point.azimuth() );

                points += qwtPolar2Pos( pole, r, a );
            }
            else
            {
                points += pole;
            }
        }

        if ( points.size() > 0 )
            symbol.drawSymbols( painter, points );
    }
}
/*!
  Draw symbols

  \param painter Painter
  \param symbol Curve symbol
  \param xMap x map
  \param yMap y map
  \param canvasRect Contents rectangle of the canvas
  \param from Index of the first point to be painted
  \param to Index of the last point to be painted

  \sa setSymbol(), drawSeries(), drawCurve()
*/
void QwtPlotCurve::drawSymbols( QPainter *painter, const QwtSymbol &symbol,
    const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    const QRectF &canvasRect, int from, int to ) const
{
    QwtPointMapper mapper;
    mapper.setFlag( QwtPointMapper::RoundPoints,
        QwtPainter::roundingAlignment( painter ) );
    mapper.setFlag( QwtPointMapper::WeedOutPoints,
        testPaintAttribute( QwtPlotCurve::FilterPoints ) );

    const QRectF clipRect = qwtIntersectedClipRect( canvasRect, painter );
    mapper.setBoundingRect( clipRect );

    const int chunkSize = 500;

    for ( int i = from; i <= to; i += chunkSize )
    {
        const int n = qMin( chunkSize, to - i + 1 );

        const QPolygonF points = mapper.toPointsF( xMap, yMap,
            data(), i, i + n - 1 );

        if ( points.size() > 0 )
            symbol.drawSymbols( painter, points );
    }
}
/*!
  Draw symbols

  \param painter Painter
  \param symbol Curve symbol
  \param xMap x map
  \param yMap y map
  \param canvasRect Contents rect of the canvas
  \param from Index of the first point to be painted
  \param to Index of the last point to be painted

  \sa setSymbol(), drawSeries(), drawCurve()
*/
void QwtPlotCurve::drawSymbols( QPainter *painter, const QwtSymbol &symbol,
    const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    const QRectF &canvasRect, int from, int to ) const
{
    const bool doAlign = QwtPainter::roundingAlignment( painter );

    bool usePixmap = testPaintAttribute( CacheSymbols );
    if ( usePixmap && !doAlign )
    {
        // Don't use the pixmap, when the paint device
        // could generate scalable vectors

        usePixmap = false;
    }

    if ( usePixmap )
    {
        QPixmap pm( symbol.boundingSize() );
        pm.fill( Qt::transparent );

        const double pw2 = 0.5 * pm.width();
        const double ph2 = 0.5 * pm.height();

        QPainter p( &pm );
        p.setRenderHints( painter->renderHints() );
        symbol.drawSymbol( &p, QPointF( pw2, ph2 ) );
        p.end();

        for ( int i = from; i <= to; i++ )
        {
            const QPointF sample = d_series->sample( i );

            double xi = xMap.transform( sample.x() );
            double yi = yMap.transform( sample.y() );
            if ( doAlign )
            {
                xi = qRound( xi );
                yi = qRound( yi );
            }

            if ( canvasRect.contains( xi, yi ) )
            {
                const int left = qCeil( xi - pw2 );
                const int top = qCeil( yi - ph2 );

                painter->drawPixmap( left, top, pm );
            }
        }
    }
    else
    {
        const int chunkSize = 500;

        for ( int i = from; i <= to; i += chunkSize )
        {
            const int n = qMin( chunkSize, to - i + 1 );

            QPolygonF points;
            for ( int j = 0; j < n; j++ )
            {
                const QPointF sample = d_series->sample( i + j );

                const double xi = xMap.transform( sample.x() );
                const double yi = yMap.transform( sample.y() );

                if ( canvasRect.contains( xi, yi ) )
                    points += QPointF( xi, yi );
            }

            if ( points.size() > 0 )
                symbol.drawSymbols( painter, points );
        }
    }
}