diff --git a/qwt/src/qwt_plot_curve.cpp b/qwt/src/qwt_plot_curve.cpp index 140cc5996..dcb6935e4 100644 --- a/qwt/src/qwt_plot_curve.cpp +++ b/qwt/src/qwt_plot_curve.cpp @@ -94,6 +94,8 @@ public: QwtPlotCurve::PaintAttributes paintAttributes; QwtPlotCurve::LegendAttributes legendAttributes; + + QVectorzones; }; /*! @@ -845,6 +847,7 @@ void QwtPlotCurve::fillCurve( QPainter *painter, if ( d_data->brush.style() == Qt::NoBrush ) return; + double avg=(yMap.invTransform(polygon[0].y())+yMap.invTransform(polygon[1].y())) / 2.00; closePolyline( painter, xMap, yMap, polygon ); if ( polygon.count() <= 2 ) // a line can't be filled return; @@ -861,6 +864,27 @@ void QwtPlotCurve::fillCurve( QPainter *painter, painter->setPen( Qt::NoPen ); painter->setBrush( brush ); + // if we have zones we need to process the polygon point by point... + if (d_data->zones.count()>0 && polygon.count() == 4) { + + // we need to set color based upon zone + double alpha = d_data->brush.color().alphaF(); + QColor color = d_data->brush.color(); + + if (avg < 1) color=Qt::black; + else{ + for(int i=0; izones.count(); i++) { + if (avg < d_data->zones[i].lim) { + color = d_data->zones[i].color; + color.setAlphaF(alpha); + break; + } + } + } + brush.setColor(color); + painter->setBrush(brush); + } + QwtPainter::drawPolygon( painter, polygon ); painter->restore(); @@ -975,6 +999,15 @@ void QwtPlotCurve::setBaseline( double value ) } } +void QwtPlotCurve::setZones(QVector zones) +{ + d_data->zones = zones; +} + +QVector &QwtPlotCurve::zones() { + return d_data->zones; +} + /*! \return Value of the baseline \sa setBaseline() diff --git a/qwt/src/qwt_plot_curve.h b/qwt/src/qwt_plot_curve.h index 3421abf81..0556738a5 100644 --- a/qwt/src/qwt_plot_curve.h +++ b/qwt/src/qwt_plot_curve.h @@ -22,6 +22,7 @@ class QPolygonF; class QwtScaleMap; class QwtSymbol; class QwtCurveFitter; +class QwtZone; /*! \brief A plot item, that represents a series of points @@ -248,6 +249,9 @@ public: void setBrush( const QBrush & ); const QBrush &brush() const; + void setZones(QVector); + QVector &zones(); + void setBaseline( double ); double baseline() const; @@ -306,6 +310,14 @@ private: PrivateData *d_data; }; +class QwtZone { +public: + QwtZone(double l, QColor c) : lim(l), color(c) {} + QwtZone() : lim(0), color(QColor(Qt::black)) {} + double lim; // less than this? + QColor color; // make it this color then +}; + //! boundingRect().left() inline double QwtPlotCurve::minXValue() const { diff --git a/src/Charts/AllPlot.cpp b/src/Charts/AllPlot.cpp index d574c2d30..f55346212 100644 --- a/src/Charts/AllPlot.cpp +++ b/src/Charts/AllPlot.cpp @@ -525,6 +525,15 @@ AllPlotObject::setUserData(QListuser) add.color = userdata->color; add.color.setAlpha(200); +#if 0 // just for testing zones, will be deleted shortly XXX + // set zones - just for testing during development of zone curve + QVector zones; + zones << QwtZone(210, Qt::green); + zones << QwtZone(300, Qt::yellow); + zones << QwtZone(9999, Qt::red); + add.curve->setZones(zones); +#endif + QPen pen; pen.setWidth(1.0); pen.setColor(userdata->color);