⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qwt_curve.cpp

📁 软件无线电的平台
💻 CPP
📖 第 1 页 / 共 2 页
字号:
  \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::drawSteps*/void QwtCurve::drawSticks(QPainter *painter,    const QwtDiMap &xMap, const QwtDiMap &yMap, int from, int to){    int x0 = xMap.transform(d_ref);    int y0 = yMap.transform(d_ref);    for (int i = from; i <= to; i++)    {        int xi = xMap.transform(x(i));        int yi = yMap.transform(y(i));        if (d_options & Xfy)            QwtPainter::drawLine(painter, x0, yi, xi, yi);        else            QwtPainter::drawLine(painter, xi, y0, xi, yi);    }}/*!  \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(QPen::NoPen));        QwtPainter::drawPolygon(painter, polyline);    }}/*!  \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(QPen::NoPen));        QwtPainter::drawPolygon(painter, polyline);    }}/*!  \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(QPen::NoPen));        QwtPainter::drawPolygon(painter, polyline);    }}/*!  \brief Specify options for the drawing style    The options can be used to modify the drawing style.  Options can be or-combined.  The following options are defined:<dl>  <dt>QwtCurve::Auto</dt>  <dd>The default setting. For QwtCurve::spline,      this means that the type of the spline is      determined automatically, depending on the data.      For all other styles, this means that y is      regarded as a function of x.</dd>  <dt>QwtCurve::Yfx</dt>  <dd>Draws y as a function of x (the default). The      baseline is interpreted as a horizontal line      with y = baseline().</dd>  <dt>QwtCurve::Xfy</dt>  <dd>Draws x as a function of y. The baseline is      interpreted as a vertical line with x = baseline().</dd>  <dt>QwtCurve::Parametric</dt>  <dd>For QwtCurve::Spline only. Draws a parametric spline.</dd>  <dt>QwtCurve::Periodic</dt>  <dd>For QwtCurve::Spline only. Draws a periodic spline.</dd>  <dt>QwtCurve::Inverted</dt>  <dd>For QwtCurve::Steps only. Draws a step function      from the right to the left.</dd></dl>  \param opt new options  /sa QwtCurve::options()*/void QwtCurve::setOptions(int opt){    d_options = opt;    curveChanged();}/*!    \brief Return the current style options    \sa QwtCurve::setOptions*/int QwtCurve::options() const {     return d_options; }/*!  \brief Change the number of interpolated points  \param s new size  \warning The default is 250 points.*/void QwtCurve::setSplineSize(int s){    d_splineSize = qwtMax(s, 10);    curveChanged();}/*!    \fn int QwtCurve::splineSize() const    \brief Return the spline size    \sa QwtCurve::setSplineSize*/int QwtCurve::splineSize() const {     return d_splineSize; }/*!  \brief Complete a polygon to be a closed polygon          including the area between the original polygon         and the baseline.  \param xMap X map  \param yMap Y map  \param pa Polygon to be completed*/void QwtCurve::closePolyline(const QwtDiMap &xMap, const QwtDiMap &yMap,    QPointArray &pa) const{    const int sz = pa.size();    if ( sz < 2 )        return;    pa.resize(sz + 2);    if ( d_options & QwtCurve::Xfy )    {        pa.setPoint(sz,            xMap.transform(d_ref), pa.point(sz - 1).y());        pa.setPoint(sz + 1,            xMap.transform(d_ref), pa.point(0).y());    }    else    {        pa.setPoint(sz,            pa.point(sz - 1).x(), yMap.transform(d_ref));        pa.setPoint(pa.size() - 1,            pa.point(0).x(), yMap.transform(d_ref));    }}/*!  \brief Draw symbols  \param painter Painter  \param symbol Curve symbol  \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*/void QwtCurve::drawSymbols(QPainter *painter, QwtSymbol &symbol,    const QwtDiMap &xMap, const QwtDiMap &yMap, int from, int to){    painter->setBrush(symbol.brush());    painter->setPen(symbol.pen());    QRect rect;    rect.setSize(QwtPainter::metricsMap().screenToLayout(symbol.size()));    for (int i = from; i <= to; i++)    {        const int xi = xMap.transform(x(i));        const int yi = yMap.transform(y(i));        rect.moveCenter(QPoint(xi, yi));        symbol.draw(painter, rect);    }}/*!  \brief Set the value of the baseline  The baseline is needed for filling the curve with a brush or  the QwtCurve::Sticks drawing style.   The default value is 0.0. The interpretation  of the baseline depends on the style options. With QwtCurve::Yfx,  the baseline is interpreted as a horizontal line at y = baseline(),  with QwtCurve::Yfy, it is interpreted as a vertical line at  x = baseline().  \param ref baseline  \sa QwtCurve::setBrush(), QwtCurve::setStyle(), QwtCurve::setOptions()*/void QwtCurve::setBaseline(double ref){    d_ref = ref;    curveChanged();}/*!    \brief Return the value of the baseline    \sa QwtCurve::setBaseline*/double QwtCurve::baseline() const {     return d_ref; }/*!  Return the size of the data arrays*/int QwtCurve::dataSize() const{    return d_data->size();}/*!    \brief Notify a change of attributes.    This virtual function is called when an attribute of the curve    has changed. It can be redefined by derived classes.    The default implementation does nothing.*/void QwtCurve::curveChanged() {}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -