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

📄 qwt_plot_curve.cpp

📁 软件无线电的平台
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- ***************************** * Qwt Widget Library * Copyright (C) 1997   Josef Wilgen * Copyright (C) 2002   Uwe Rathmann *  * This library is free software; you can redistribute it and/or * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/#include "qwt_plot.h"#include "qwt_plot_dict.h"#include "qwt_math.h"#include "qwt_legend.h"//! Return an iterator for the plot curvesQwtPlotCurveIterator QwtPlot::curveIterator() const{    return QwtPlotCurveIterator(*d_curves);}/*!  Find the curve which is closest to a  specified point in the plotting area.  \param xpos  \param ypos position in the plotting region  \retval dist distance in points between (xpos, ypos) and the               closest data point  \return Key of the closest curve or 0 if no curve was found.*/long QwtPlot::closestCurve(int xpos, int ypos, int &dist) const{    double x,y;    int index;    return closestCurve(xpos, ypos, dist, x,y, index);}/*!  Find the curve which is closest to a point in the plotting area.    Determines the position and index of the closest data point.  \param xpos  \param ypos coordinates of a point in the plotting region  \retval xval   \retval yval values of the closest point in the curve's data array  \retval dist -- distance in points between (xpos, ypos) and the                  closest data point  \retval index -- index of the closest point in the curve's data array  \return Key of the closest curve or 0 if no curve was found.*/long QwtPlot::closestCurve(int xpos, int ypos, int &dist, double &xval,                           double &yval, int &index) const{    QwtDiMap map[axisCnt];    for ( int axis = 0; axis < axisCnt; axis++ )        map[axis] = canvasMap(axis);    long rv = 0;    double dmin = 1.0e10;    QwtPlotCurveIterator itc = curveIterator();    for (QwtPlotCurve *c = itc.toFirst(); c != 0; c = ++itc )    {        for (int i=0; i<c->dataSize(); i++)        {            double cx = map[c->xAxis()].xTransform(c->x(i)) - double(xpos);            double cy = map[c->yAxis()].xTransform(c->y(i)) - double(ypos);            double f = qwtSqr(cx) + qwtSqr(cy);            if (f < dmin)            {                dmin = f;                rv = itc.currentKey();                xval = c->x(i);                yval = c->y(i);                index = i;            }        }    }    dist = int(sqrt(dmin));    return rv;}/*!  \return the style of the curve indexed by key  \param key Key of the curve  \sa setCurveStyle()*/int QwtPlot::curveStyle(long key) const{    QwtPlotCurve *c = d_curves->find(key);    return c ? c->style() : 0;}/*!  \brief the symbol of the curve indexed by key  \param key Key of the curve  \return The symbol of the specified curve. If the key is invalid,          a symbol of type 'NoSymbol'.*/QwtSymbol QwtPlot::curveSymbol(long key) const{    QwtPlotCurve *c = d_curves->find(key);    return c ? c->symbol() : QwtSymbol();}/*!  \return the brush of the curve indexed by key  \param key Key of the curve*/QPen QwtPlot::curvePen(long key) const{    QwtPlotCurve *c = d_curves->find(key);    return c ? c->pen() : QPen();}/*!  \return the pen of the curve indexed by key  \param key Key of the curve  \sa QwtPlot::setCurveBrush(), QwtCurve::setBrush()*/QBrush QwtPlot::curveBrush(long key) const{    QwtPlotCurve *c = d_curves->find(key);    return c ? c->brush() : QBrush();}/*!  \return the drawing options of the curve indexed by key  \param key Key of the curve*/int QwtPlot::curveOptions(long key) const{    QwtPlotCurve *c = d_curves->find(key);    return c ? c->options() : 0;}/*!  \return the spline size of the curve indexed by key  \param key Key of the curve*/int QwtPlot::curveSplineSize(long key) const{    QwtPlotCurve *c = d_curves->find(key);    return c ? c->splineSize() : 0;}/*!  \return the title of the curve indexed by key  \param key Key of the curve*/QString QwtPlot::curveTitle(long key) const{    QwtPlotCurve *c = d_curves->find(key);    return c ? c->title() : QString::null;}/*!  \return an array containing the keys of all curves*/QwtArray<long> QwtPlot::curveKeys() const{    QwtArray<long> keys(d_curves->count());    int i = 0;    QwtPlotCurveIterator itc = curveIterator();    for (const QwtPlotCurve *c = itc.toFirst(); c != 0; c = ++itc, i++ )        keys[i] = itc.currentKey();    return keys;}/*!  \brief Return the index of the x axis to which a curve is mapped  \param key Key of the curve  \return x axis of the curve or -1 if the key is invalid.*/int QwtPlot::curveXAxis(long key) const{    QwtPlotCurve *c = d_curves->find(key);    return c ? c->xAxis() : -1;}/*!  \brief the index of the y axis to which a curve is mapped  \param key Key of the curve  \return y axis of the curve or -1 if the key is invalid.*/int QwtPlot::curveYAxis(long key) const{    QwtPlotCurve *c = d_curves->find(key);    return c ? c->yAxis() : -1;}/*!  \brief Generate a unique key for a new curve  \return new unique key or 0 if no key could be found.*/long QwtPlot::newCurveKey(){    long newkey = d_curves->count() + 1;    if (newkey > 1)                     // size > 0: check if key exists    {        if (d_curves->find(newkey))     // key size+1 exists => there must be a                                        // free key <= size        {            // find the first available key <= size            newkey = 1;            while (newkey <= long(d_curves->count()))            {                if (d_curves->find(newkey))                   newkey++;                else                   break;            }            // This can't happen. Just paranoia.            if (newkey > long(d_curves->count()))            {                while (!d_curves->find(newkey))                {                    newkey++;                    if (newkey > 10000) // prevent infinite loop                    {                        newkey = 0;                        break;                    }                }            }        }    }    return newkey;}/*!  \brief Insert a curve  \param curve Curve  \return The key of the new curve or 0 if no new key could be found          or if no new curve could be allocated.*/long QwtPlot::insertCurve(QwtPlotCurve *curve){    if (curve == 0)        return 0;    long key = newCurveKey();    if (key == 0)        return 0;    curve->reparent(this);    d_curves->insert(key, curve);    if (d_autoLegend)    {        insertLegendItem(key);        updateLayout();    }    return key;}/*!  \brief Insert a new curve and return a unique key  \param title title of the new curve  \param xAxis x axis to be attached. Defaults to xBottom.  \param yAxis y axis to be attached. Defaults to yLeft.  \return The key of the new curve or 0 if no new key could be found          or if no new curve could be allocated.*/long QwtPlot::insertCurve(const QString &title, int xAxis, int yAxis){    QwtPlotCurve *curve = new QwtPlotCurve(this);    if (!curve)        return 0;    curve->setAxis(xAxis, yAxis);    curve->setTitle(title);    long key = insertCurve(curve);    if ( key == 0 )        delete curve;    return key;}/*!  \brief Find and return an existing curve.  \param key Key of the curve  \return The curve for the given key or 0 if key is not valid.*/QwtPlotCurve *QwtPlot::curve(long key){    return d_curves->find(key);}/*!  \brief Find and return an existing curve.  \param key Key of the curve  \return The curve for the given key or 0 if key is not valid.*/const QwtPlotCurve *QwtPlot::curve(long key) const{    return d_curves->find(key);}/*!  \brief remove the curve indexed by key  \param key Key of the curve*/bool QwtPlot::removeCurve(long key){    bool ok = d_curves->remove(key);    if ( !ok )        return FALSE;    QWidget *item = d_legend->findItem(key);    if ( item )    {        delete item;        updateLayout();    }        autoRefresh();    return TRUE;}/*!  \brief Assign a pen to a curve indexed by key  \param key Key of the curve  \param pen new pen  \return \c TRUE if the curve exists*/bool QwtPlot::setCurvePen(long key, const QPen &pen){    QwtPlotCurve *c = d_curves->find(key);    if ( !c )        return FALSE;        c->setPen(pen);    updateLegendItem(key);    return TRUE;}/*!  \brief Assign a brush to a curve indexed by key         The brush will be used to fill the area between the          curve and the baseline.   \param key Key of the curve  \param brush new brush  \return \c TRUE if the curve exists  \sa QwtCurve::setBrush for further details.  \sa QwtPlot::brush(), QwtPlot::setCurveBaseline*/bool QwtPlot::setCurveBrush(long key, const QBrush &brush){    QwtPlotCurve *c = d_curves->find(key);    if ( !c )        return FALSE;        c->setBrush(brush);    updateLegendItem(key);    return TRUE;

⌨️ 快捷键说明

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