예제 #1
0
/*!
  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 );
        }
    }
}