コード例 #1
0
/*!
  Fill the area between the curve and the baseline with
  the curve brush

  \param painter Painter
  \param xMap x map
  \param yMap y map
  \param canvasRect Contents rectangle of the canvas
  \param polygon Polygon - will be modified !

  \sa setBrush(), setBaseline(), setStyle()
*/
void QwtPlotCurve::fillCurve( QPainter *painter,
    const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    const QRectF &canvasRect, QPolygonF &polygon ) const
{
    if ( d_data->brush.style() == Qt::NoBrush )
        return;

    closePolyline( painter, xMap, yMap, polygon );
    if ( polygon.count() <= 2 ) // a line can't be filled
        return;

    QBrush brush = d_data->brush;
    if ( !brush.color().isValid() )
        brush.setColor( d_data->pen.color() );

    if ( d_data->paintAttributes & ClipPolygons )
        polygon = QwtClipper::clipPolygonF( canvasRect, polygon, true );

    painter->save();

    painter->setPen( Qt::NoPen );
    painter->setBrush( brush );

    QwtPainter::drawPolygon( painter, polygon );

    painter->restore();
}
コード例 #2
0
/*!
  \brief Draw step function
  \param painter Painter
  \param xMap x map
  \param yMap y map
  \param from index of the first point to be painted
  \param to index of the last point to be painted
  \sa QwtCurve::draw, QwtCurve::drawCurve, QwtCurve::drawDots, 
      QwtCurve::drawLines, QwtCurve::drawSpline, QwtCurve::drawSticks
*/
void QwtCurve::drawSteps(QPainter *painter,
    const QwtDiMap &xMap, const QwtDiMap &yMap, int from, int to)
{
    QPointArray polyline(2 * (to - from) + 1);

    bool inverted = d_options & Yfx;
    if ( d_options & Inverted )
        inverted = !inverted;

    int i,ip;
    for (i = from, ip = 0; i <= to; i++, ip += 2)
    {
        int xi = xMap.transform(x(i));
        int yi = yMap.transform(y(i));

        if ( ip > 0 )
        {
            if (inverted)
                polyline.setPoint(ip - 1, polyline[ip-2].x(), yi);
            else
                polyline.setPoint(ip - 1, xi, polyline[ip-2].y());
        }

        polyline.setPoint(ip, xi, yi);
    }

    QwtPainter::drawPolyline(painter, polyline);

    if ( painter->brush().style() != Qt::NoBrush )
    {
        closePolyline(xMap, yMap, polyline);
        painter->setPen(QPen(Qt::NoPen));
        QwtPainter::drawPolygon(painter, polyline);
    }
}
コード例 #3
0
/*!
  \brief Draw dots
  \param painter Painter
  \param xMap x map
  \param yMap y map
  \param from index of the first point to be painted
  \param to index of the last point to be painted
  \sa QwtCurve::drawPolyline, QwtCurve::drawLine, 
      QwtCurve::drawLines, QwtCurve::drawSpline, QwtCurve::drawSteps
      QwtCurve::drawPolyline, QwtCurve::drawPolygon
*/
void QwtCurve::drawDots(QPainter *painter,
    const QwtDiMap &xMap, const QwtDiMap &yMap, int from, int to)
{
    const bool doFill = painter->brush().style() != Qt::NoBrush;

    QPointArray polyline;
    if ( doFill )
        polyline.resize(to - from + 1);

    for (int i = from; i <= to; i++)
    {
        int xi = xMap.transform(x(i));
        int yi = yMap.transform(y(i));
        QwtPainter::drawPoint(painter, xi, yi);

        if ( doFill )
            polyline.setPoint(i - from, xi, yi);
    }

    if ( doFill )
    {
        closePolyline(xMap, yMap, polyline);
        painter->setPen(QPen(Qt::NoPen));
        QwtPainter::drawPolygon(painter, polyline);
    }
}
コード例 #4
0
/*! 
  Fill the area between the curve and the baseline with 
  the curve brush

  \param painter Painter
  \param xMap x map
  \param yMap y map
  \param pa Polygon

  \sa setBrush(), setBaseline(), setCurveType()
*/
void QwtPlotCurve::fillCurve(QPainter *painter,
    const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    QwtPolygon &pa) const
{
    if ( d_data->brush.style() == Qt::NoBrush )
        return;

    closePolyline(xMap, yMap, pa);
    if ( pa.count() <= 2 ) // a line can't be filled
        return;

    QBrush b = d_data->brush;
    if ( !b.color().isValid() )
        b.setColor(d_data->pen.color());

    painter->save();

    painter->setPen(QPen(Qt::NoPen));
    painter->setBrush(b);

    QwtPainter::drawPolygon(painter, pa);

    painter->restore();
}
コード例 #5
0
/*!
  \brief Draw a spline
  \param painter Painter
  \param xMap x map
  \param yMap y map
  \sa QwtCurve::draw, QwtCurve::drawCurve, QwtCurve::drawDots,
      QwtCurve::drawLines, QwtCurve::drawSteps, QwtCurve::drawSticks
*/
void QwtCurve::drawSpline(QPainter *painter,
    const QwtDiMap &xMap, const QwtDiMap &yMap)
{
    register int i;

    int size = dataSize();
    double *txval = new double[size];
    double *tyval = new double[size];


    if ( !txval || !tyval )
    {
        if (txval) delete[] txval;
        if (tyval) delete[] tyval;
        return;
    }

    QPointArray polyline(d_splineSize);

    //
    // Transform x and y values to window coordinates
    // to avoid a distinction between linear and
    // logarithmic scales.
    //
    for (i=0;i<size;i++)
    {
        txval[i] = xMap.xTransform(x(i));
        tyval[i] = yMap.xTransform(y(i));
    }

    int stype;
    if (! (d_options & (Yfx|Xfy|Parametric)))
    {
        if (qwtChkMono(txval, size))
        {
            stype = Yfx;
        }
        else
        {
            if(qwtChkMono(tyval, size))
            {
                stype = Xfy;
            }
            else
            {
                stype = Parametric;
                if ( (d_options & Periodic) ||
                    ( (x(0) == x(size-1))
                    && (y(0) == y(size-1))))
                {
                    stype |= Periodic;
                }
            }
        }
    }
    else
    {
        stype = d_options;
    }

    if (stype & Parametric)
    {
        double *param = new double[size];
        if (param)
        {
            //
            // setup parameter vector
            //
            param[0] = 0.0;
            for (i=1; i<size; i++)
            {
                double delta = sqrt( qwtSqr(txval[i] - txval[i-1])
                              + qwtSqr( tyval[i] - tyval[i-1]));
                param[i] = param[i-1] + qwtMax(delta, 1.0);
            }

            //
            // setup splines
            int rc = d_spx.recalc(param, txval, size, stype & Periodic);
            if (!rc)
                rc = d_spy.recalc(param, tyval, size, stype & Periodic);

            if (rc)
            {
                drawLines(painter, xMap, yMap, 0, size - 1);
            }
            else
            {
                // fill point array
                double delta = param[size - 1] / double(d_splineSize-1);
                for (i=0;i<d_splineSize;i++)
                {
                    double dtmp = delta * double(i);
                    polyline.setPoint(i, int(floor (d_spx.value(dtmp) + 0.5)),
                                  int(floor (d_spy.value(dtmp) + 0.5)));
                }
            }

            delete[] param;
        }
    }
    else if (stype & Xfy)
    {
        if (tyval[size-1] < tyval[0])
        {
            qwtTwistArray(txval, size);
            qwtTwistArray(tyval, size);
        }

        // 1. Calculate spline coefficients
        int rc = d_spx.recalc(tyval, txval, size, stype & Periodic);
        if (rc)                         // an error occurred
        {
            drawLines(painter, xMap, yMap, 0, size - 1);
        }
        else                            // Spline OK
        {
            double ymin = qwtGetMin(tyval, size);
            double ymax = qwtGetMax(tyval, size);
            double delta = (ymax - ymin) / double(d_splineSize - 1);

            for (i=0;i<d_splineSize;i++)
            {
                double dtmp = ymin + delta * double(i);
                polyline.setPoint(i, int(floor(d_spx.value(dtmp) + 0.5)),
                              int(floor(dtmp + 0.5)));
            }
        }
    }
    else
    {
        if (txval[size-1] < txval[0])
        {
            qwtTwistArray(tyval, size);
            qwtTwistArray(txval, size);
        }


        // 1. Calculate spline coefficients
        int rc = d_spy.recalc(txval, tyval, size, stype & Periodic);
        if (rc)                         // error
        {
            drawLines(painter, xMap, yMap, 0, size - 1);
        }
        else                            // Spline OK
        {
            double xmin = qwtGetMin(txval, size);
            double xmax = qwtGetMax(txval, size);
            double delta = (xmax - xmin) / double(d_splineSize - 1);

            for (i=0;i<d_splineSize;i++)
            {
                double dtmp = xmin + delta * double(i);
                polyline.setPoint(i, int(floor (dtmp + 0.5)),
                              int(floor(d_spy.value(dtmp) + 0.5)));
            }
        }
    }

    delete[] txval;
    delete[] tyval;

    QwtPainter::drawPolyline(painter, polyline);

    if ( painter->brush().style() != Qt::NoBrush )
    {
        closePolyline(xMap, yMap, polyline);
        painter->setPen(QPen(Qt::NoPen));
        QwtPainter::drawPolygon(painter, polyline);
    }
}