Exemplo n.º 1
0
MainWin::MainWin()
{
    int i;

    xMap.setScaleInterval( -0.5, 10.5 );
    yMap.setScaleInterval( -1.1, 1.1 );

    //
    //  Frame style
    //
    setFrameStyle( QFrame::Box | QFrame::Raised );
    setLineWidth( 2 );
    setMidLineWidth( 3 );

    //
    // Calculate values
    //
    for( i = 0; i < Size; i++ )
    {
        xval[i] = double( i ) * 10.0 / double( Size - 1 );
        yval[i] = qSin( xval[i] ) * qCos( 2.0 * xval[i] );
    }

    curve.setRawSamples( xval, yval, Size );
}
Exemplo n.º 2
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;
}
/*!
  Calculate the viewBox from an rect and boundingRect().

  \param rect Rectangle in scale coordinates
  \return viewBox View Box, see QSvgRenderer::viewBox
*/
QRect QwtPlotSvgItem::viewBox(const QwtDoubleRect &rect) const
{
#if QT_VERSION >= 0x040100
    const QSize sz = d_data->renderer.defaultSize();
#else
#if QT_VERSION > 0x040000
    const QSize sz(d_data->picture.width(), 
        d_data->picture.height());
#else
    QPaintDeviceMetrics metrics(&d_data->picture);
    const QSize sz(metrics.width(), metrics.height());
#endif
#endif
    const QwtDoubleRect br = boundingRect();

    if ( !rect.isValid() || !br.isValid() || sz.isNull() )
        return QRect();

    QwtScaleMap xMap;
    xMap.setScaleInterval(br.left(), br.right());
    xMap.setPaintInterval(0, sz.width());

    QwtScaleMap yMap;
    yMap.setScaleInterval(br.top(), br.bottom());
    yMap.setPaintInterval(sz.height(), 0);

    return transform(xMap, yMap, rect);
}
Exemplo n.º 4
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;
}
Exemplo n.º 5
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;
}
Exemplo n.º 6
0
static void qwtAdjustMaps( QwtScaleMap &xMap, QwtScaleMap &yMap,
    const QRectF &area, const QRectF &paintRect)
{
    double sx1 = area.left();
    double sx2 = area.right();
    if ( xMap.isInverting() )
        qSwap(sx1, sx2);

    double sy1 = area.top();
    double sy2 = area.bottom();

    if ( yMap.isInverting() )
        qSwap(sy1, sy2);

    xMap.setPaintInterval(paintRect.left(), paintRect.right());
    xMap.setScaleInterval(sx1, sx2);

    yMap.setPaintInterval(paintRect.top(), paintRect.bottom());
    yMap.setScaleInterval(sy1, sy2);
}
/*!
  Calculate the view box from rect and boundingRect().

  \param rect Rectangle in scale coordinates
  \return View box, see QSvgRenderer::viewBox()
*/
QRectF QwtPlotSvgItem::viewBox( const QRectF &rect ) const
{
    const QSize sz = d_data->renderer.defaultSize();
    const QRectF br = boundingRect();

    if ( !rect.isValid() || !br.isValid() || sz.isNull() )
        return QRectF();

    QwtScaleMap xMap;
    xMap.setScaleInterval( br.left(), br.right() );
    xMap.setPaintInterval( 0, sz.width() );

    QwtScaleMap yMap;
    yMap.setScaleInterval( br.top(), br.bottom() );
    yMap.setPaintInterval( sz.height(), 0 );

    const double x1 = xMap.transform( rect.left() );
    const double x2 = xMap.transform( rect.right() );
    const double y1 = yMap.transform( rect.bottom() );
    const double y2 = yMap.transform( rect.top() );

    return QRectF( x1, y1, x2 - x1, y2 - y1 );
}
Exemplo n.º 8
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;
}
Exemplo n.º 9
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;
}
Exemplo n.º 10
0
/*!
   \brief Calculate a scale map for painting to an image

   \param orientation Orientation, Qt::Horizontal means a X axis
   \param map Scale map for rendering the plot item
   \param area Area to be painted on the image
   \param imageSize Image size
   \param pixelSize Width/Height of a data pixel

   \return Calculated scale map
*/
QwtScaleMap QwtPlotRasterItem::imageMap(
    Qt::Orientation orientation,
    const QwtScaleMap &map, const QRectF &area,
    const QSize &imageSize, double pixelSize) const
{
    double p1, p2, s1, s2;

    if ( orientation == Qt::Horizontal )
    {
        p1 = 0.0;
        p2 = imageSize.width();
        s1 = area.left();
        s2 = area.right();
    }
    else
    {
        p1 = 0.0;
        p2 = imageSize.height();
        s1 = area.top();
        s2 = area.bottom();
    }

    if ( pixelSize > 0.0 )
    {
        double off = 0.5 * pixelSize;
        if ( map.isInverting() )
            off = -off;

        s1 += off;
        s2 += off;
    }
    else
    {
        p2--;
    }

    if ( map.isInverting() && ( s1 < s2 ) )
        qSwap( s1, s2 );

    QwtScaleMap newMap = map;
    newMap.setPaintInterval( p1, p2 );
    newMap.setScaleInterval( s1, s2 );

    return newMap;
}
Exemplo n.º 11
0
MainWin::MainWin() 
{
    int i;

    xMap.setScaleInterval(-0.5, 10.5);
    yMap.setScaleInterval(-1.1, 1.1);

    //
    //  Frame style
    //  
    setFrameStyle(QFrame::Box|QFrame::Raised);
    setLineWidth(2);
    setMidLineWidth(3);

    //
    // Calculate values
    //
    for(i=0; i<Size;i++)
    {   xval[i] = double(i) * 10.0 / double(Size - 1);
        yval[i] = sin(xval[i]) * cos(2.0 * xval[i]);
    }
    
    //
    //  define curve styles
    // 
    QwtSymbol sym;
    i = 0;

    sym.setStyle(QwtSymbol::Cross);
    sym.setPen(QColor(Qt::black));
    sym.setSize(5);
    crv[i].setSymbol(sym);
    crv[i].setPen(QColor(Qt::darkGreen));
    crv[i].setStyle(QwtPlotCurve::Lines);
    crv[i].setCurveAttribute(QwtPlotCurve::Fitted);
    i++;

    sym.setStyle(QwtSymbol::Ellipse);
    sym.setPen(QColor(Qt::blue));
    sym.setBrush(QColor(Qt::yellow));
    sym.setSize(5);
    crv[i].setSymbol(sym);
    crv[i].setPen(QColor(Qt::red));
    crv[i].setStyle(QwtPlotCurve::Sticks);
    i++;

    crv[i].setPen(QColor(Qt::darkBlue));
    crv[i].setStyle(QwtPlotCurve::Lines);
    i++;

#if QT_VERSION >= 0x040000
    crv[i].setPen(QColor(Qt::darkBlue));
    crv[i].setStyle(QwtPlotCurve::Lines);
    crv[i].setRenderHint(QwtPlotItem::RenderAntialiased);
    i++;
#endif


    crv[i].setPen(QColor(Qt::darkCyan));
    crv[i].setStyle(QwtPlotCurve::Steps);
    i++;

    sym.setStyle(QwtSymbol::XCross);
    sym.setPen(QColor(Qt::darkMagenta));
    crv[i].setSymbol(sym);
    crv[i].setStyle(QwtPlotCurve::NoCurve);
    i++;


    //
    // attach data
    //
    for(i=0;i<CurvCnt;i++)
        crv[i].setRawData(xval,yval,Size);
}
Exemplo n.º 12
0
MainWin::MainWin()
{
    int i;

    xMap.setScaleInterval(-0.5, 10.5);
    yMap.setScaleInterval(-1.1, 1.1);

    //
    //  Frame style
    //
    setFrameStyle(QFrame::Box|QFrame::Raised);
    setLineWidth(2);
    setMidLineWidth(3);

    //
    // Calculate values
    //
    for(i=0; i<Size;i++)
    {
        xval[i] = double(i) * 10.0 / double(Size - 1);
        yval[i] = qSin(xval[i]) * qCos(2.0 * xval[i]);
    }

    //
    //  define curve styles
    //
    i = 0;

    d_curves[i].setSymbol(new QwtSymbol(QwtSymbol::Cross, Qt::NoBrush,
        QPen(Qt::black), QSize(5, 5) ) );
    d_curves[i].setPen(QColor(Qt::darkGreen));
    d_curves[i].setStyle(QwtPlotCurve::Lines);
    d_curves[i].setCurveAttribute(QwtPlotCurve::Fitted);
    i++;

    d_curves[i].setSymbol(new QwtSymbol(QwtSymbol::Ellipse, Qt::yellow,
        QPen(Qt::blue), QSize(5, 5) ) );
    d_curves[i].setPen(QColor(Qt::red));
    d_curves[i].setStyle(QwtPlotCurve::Sticks);
    i++;

    d_curves[i].setPen(QColor(Qt::darkBlue));
    d_curves[i].setStyle(QwtPlotCurve::Lines);
    i++;

    d_curves[i].setPen(QColor(Qt::darkBlue));
    d_curves[i].setStyle(QwtPlotCurve::Lines);
    d_curves[i].setRenderHint(QwtPlotItem::RenderAntialiased);
    i++;

    d_curves[i].setPen(QColor(Qt::darkCyan));
    d_curves[i].setStyle(QwtPlotCurve::Steps);
    i++;

    d_curves[i].setSymbol(new QwtSymbol(QwtSymbol::XCross, Qt::NoBrush,
        QPen(Qt::darkMagenta), QSize(5, 5) ) );
    d_curves[i].setStyle(QwtPlotCurve::NoCurve);
    i++;


    //
    // attach data
    //
    for(i=0;i<CurvCnt;i++)
        d_curves[i].setRawSamples(xval, yval, Size);
}
Exemplo n.º 13
0
/*!
   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;
}