Esempio n. 1
0
/*!
  Build a scale map

  The azimuth map translates between the scale values and angles from
  [0.0, 2 * PI[. The radial map translates scale values into the distance
  from the pole.

  \param scaleId Scale index
  \param radius Radius of the plot are in pixels
  \return Map for the scale on the canvas. With this map pixel coordinates can
          translated to plot coordinates and vice versa.

  \sa QwtScaleMap, transform(), invTransform()
*/
QwtScaleMap QwtPolarPlot::scaleMap( int scaleId, const double radius ) const
{
  if ( scaleId < 0 || scaleId >= QwtPolar::ScaleCount )
    return QwtScaleMap();

  QwtScaleMap map;
  map.setTransformation( scaleEngine( scaleId )->transformation() );

  const QwtScaleDiv *sd = scaleDiv( scaleId );
#if QWT_VERSION < 0x050200
  map.setScaleInterval( sd->lBound(), sd->hBound() );
#else
  map.setScaleInterval( sd->lowerBound(), sd->upperBound() );
#endif

  if ( scaleId == QwtPolar::Azimuth )
  {
    map.setPaintXInterval( d_data->azimuthOrigin,
                           d_data->azimuthOrigin + M_2PI );
  }
  else
  {
    map.setPaintXInterval( 0.0, radius );
  }

  return map;
}
Esempio n. 2
0
/*!
   \brief Calculate the bounding rect of the plot area

   The plot area depends on the zoom parameters.

   \param canvasRect Rectangle of the canvas
   \return Rectangle for displaying 100% of the plot
*/
QRectF QwtPolarPlot::plotRect( const QRectF &canvasRect ) const
{
    const QwtScaleDiv *sd = scaleDiv( QwtPolar::Radius );
    const QwtScaleEngine *se = scaleEngine( QwtPolar::Radius );

    const int margin = plotMarginHint();
    const QRectF cr = canvasRect;
    const int radius = qMin( cr.width(), cr.height() ) / 2 - margin;

    QwtScaleMap map;
    map.setTransformation( se->transformation() );
    map.setPaintInterval( 0.0, radius / d_data->zoomFactor );
    map.setScaleInterval( sd->lowerBound(), sd->upperBound() );

    double v = map.s1();
    if ( map.s1() <= map.s2() )
        v += d_data->zoomPos.radius();
    else
        v -= d_data->zoomPos.radius();
    v = map.transform( v );

    const QPointF off =
        QwtPointPolar( d_data->zoomPos.azimuth(), v ).toPoint();

    QPointF center( cr.center().x(), cr.top() + margin + radius );
    center -= QPointF( off.x(), -off.y() );

    QRectF rect( 0, 0, 2 * map.p2(), 2 * map.p2() );
    rect.moveCenter( center );

    return rect;
}
Esempio n. 3
0
/*!
  \param axisId Axis
  \return Map for the axis on the canvas. With this map pixel coordinates can
          translated to plot coordinates and vice versa.
  \sa QwtScaleMap, transform(), invTransform()

*/
QwtScaleMap QwtPlot::canvasMap( int axisId ) const
{
    QwtScaleMap map;
    if ( !d_data->canvas )
        return map;

    map.setTransformation( axisScaleEngine( axisId )->transformation() );

    const QwtScaleDiv &sd = axisScaleDiv( axisId );
    map.setScaleInterval( sd.lowerBound(), sd.upperBound() );

    if ( axisEnabled( axisId ) )
    {
        const QwtScaleWidget *s = axisWidget( axisId );
        if ( axisId == yLeft || axisId == yRight )
        {
            double y = s->y() + s->startBorderDist() - d_data->canvas->y();
            double h = s->height() - s->startBorderDist() - s->endBorderDist();
            map.setPaintInterval( y + h, y );
        }
        else
        {
            double x = s->x() + s->startBorderDist() - d_data->canvas->x();
            double w = s->width() - s->startBorderDist() - s->endBorderDist();
            map.setPaintInterval( x, x + w );
        }
    }
    else
    {
        const QRect &canvasRect = d_data->canvas->contentsRect();
        if ( axisId == yLeft || axisId == yRight )
        {
            int top = 0;
            if ( !plotLayout()->alignCanvasToScale( xTop ) )
                top = plotLayout()->canvasMargin( xTop );

            int bottom = 0;
            if ( !plotLayout()->alignCanvasToScale( xBottom ) )
                bottom = plotLayout()->canvasMargin( xBottom );

            map.setPaintInterval( canvasRect.bottom() - bottom,
                                  canvasRect.top() + top );
        }
        else
        {
            int left = 0;
            if ( !plotLayout()->alignCanvasToScale( yLeft ) )
                left = plotLayout()->canvasMargin( yLeft );

            int right = 0;
            if ( !plotLayout()->alignCanvasToScale( yRight ) )
                right = plotLayout()->canvasMargin( yRight );

            map.setPaintInterval( canvasRect.left() + left,
                                  canvasRect.right() - right );
        }
    }

    return map;
}
Esempio n. 4
0
/*!
  \param axisId Axis
  \return Map for the axis on the canvas. With this map pixel coordinates can
          translated to plot coordinates and vice versa.
  \sa QwtScaleMap, transform(), invTransform()

*/
QwtScaleMap QwtPlot::canvasMap( int axisId ) const
{
    QwtScaleMap map;
    if ( !d_data->canvas )
        return map;

    map.setTransformation( axisScaleEngine( axisId )->transformation() );

    const QwtScaleDiv *sd = axisScaleDiv( axisId );
    map.setScaleInterval( sd->lowerBound(), sd->upperBound() );

    if ( axisEnabled( axisId ) )
    {
        const QwtScaleWidget *s = axisWidget( axisId );
        if ( axisId == yLeft || axisId == yRight )
        {
            double y = s->y() + s->startBorderDist() - d_data->canvas->y();
            double h = s->height() - s->startBorderDist() - s->endBorderDist();
            map.setPaintInterval( y + h, y );
        }
        else
        {
            double x = s->x() + s->startBorderDist() - d_data->canvas->x();
            double w = s->width() - s->startBorderDist() - s->endBorderDist();
            map.setPaintInterval( x, x + w );
        }
    }
    else
    {
        int margin = 0;
        if ( !plotLayout()->alignCanvasToScales() )
            margin = plotLayout()->canvasMargin( axisId );

        const QRect &canvasRect = d_data->canvas->contentsRect();
        if ( axisId == yLeft || axisId == yRight )
        {
            map.setPaintInterval( canvasRect.bottom() - margin,
                canvasRect.top() + margin );
        }
        else
        {
            map.setPaintInterval( canvasRect.left() + margin,
                canvasRect.right() - margin );
        }
    }
    return map;
}
Esempio n. 5
0
/*!
   \brief Calculate the bounding rect of the plot area

   The plot area depends on the zoom parameters.

   \param canvasRect Rectangle of the canvas
   \return Rectangle for displaying 100% of the plot
*/
QwtDoubleRect QwtPolarPlot::plotRect( const QRect &canvasRect ) const
{
  const QwtScaleDiv *sd = scaleDiv( QwtPolar::Radius );
  const QwtScaleEngine *se = scaleEngine( QwtPolar::Radius );

  const int margin = plotMarginHint();
  const QRect cr = canvasRect;
  const int radius = qwtMin( cr.width(), cr.height() ) / 2 - margin;

  QwtScaleMap map;
  map.setTransformation( se->transformation() );
  map.setPaintXInterval( 0.0, radius / d_data->zoomFactor );
#if QWT_VERSION < 0x050200
  map.setScaleInterval( sd->lBound(), sd->hBound() );
#else
  map.setScaleInterval( sd->lowerBound(), sd->upperBound() );
#endif

  double v = map.s1();
  if ( map.s1() <= map.s2() )
    v += d_data->zoomPos.radius();
  else
    v -= d_data->zoomPos.radius();
  v = map.xTransform( v );

  const QwtDoublePoint off =
    QwtPolarPoint( d_data->zoomPos.azimuth(), v ).toPoint();

  QwtDoublePoint center( cr.center().x(), cr.top() + margin + radius );
  center -= QwtDoublePoint( off.x(), -off.y() );

  QwtDoubleRect rect( 0, 0, 2 * map.p2(), 2 * map.p2() );
  rect.moveCenter( center );

  return rect;
}
/*!
   Calculated the scale maps for rendering the canvas

   \param plot Plot widget
   \param canvasRect Target rectangle
   \param maps Scale maps to be calculated
*/
QwtScaleMapTable QwtPlotRenderer::buildCanvasMaps( 
    const QwtPlot *plot, const QRectF &canvasRect ) const
{
    QwtScaleMapTable mapTable;

    for ( int axisPos = 0; axisPos < QwtAxis::PosCount; axisPos++ )
    {
        for ( int i = 0; i < plot->axesCount( axisPos ); i++ )
        {
            const QwtAxisId axisId( axisPos, i );

            QwtScaleMap scaleMap;

            scaleMap.setTransformation( plot->axisScaleEngine( axisId )->transformation() );

            const QwtScaleDiv &scaleDiv = plot->axisScaleDiv( axisId );
            scaleMap.setScaleInterval(
                scaleDiv.lowerBound(), scaleDiv.upperBound() );

            double from, to;
            if ( plot->isAxisVisible( axisId ) )
            {
                const int sDist = plot->axisWidget( axisId )->startBorderDist();
                const int eDist = plot->axisWidget( axisId )->endBorderDist();
                const QRectF scaleRect = plot->plotLayout()->scaleRect( axisId );

                if ( QwtAxis::isXAxis( axisPos ) )
                {
                    from = scaleRect.left() + sDist;
                    to = scaleRect.right() - eDist;
                }
                else
                {
                    from = scaleRect.bottom() - eDist;
                    to = scaleRect.top() + sDist;
                }
            }
            else
            {
                int margin = 0;
                if ( !plot->plotLayout()->alignCanvasToScale( axisPos ) )
                    margin = plot->plotLayout()->canvasMargin( axisPos );

                if ( QwtAxis::isYAxis( axisPos ) )
                {
                    from = canvasRect.bottom() - margin;
                    to = canvasRect.top() + margin;
                }
                else
                {
                    from = canvasRect.left() + margin;
                    to = canvasRect.right() - margin;
                }
            }
            scaleMap.setPaintInterval( from, to );

            mapTable.maps[axisPos] += scaleMap;

        }
    }

    return mapTable;
}