Curve fill colored zones (QWT) 1/2

.. updated the QwtPlotCurve to fill using zones.

.. next commit to update user data curves in AllPlot
   to let the user set zones and colors.

.. added as part of updates for Humon collaboration.
This commit is contained in:
Mark Liversedge
2019-03-12 18:20:32 +00:00
parent cae7e0b6b6
commit 95901aa1e2
3 changed files with 54 additions and 0 deletions

View File

@@ -94,6 +94,8 @@ public:
QwtPlotCurve::PaintAttributes paintAttributes;
QwtPlotCurve::LegendAttributes legendAttributes;
QVector<QwtZone>zones;
};
/*!
@@ -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; i<d_data->zones.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<QwtZone> zones)
{
d_data->zones = zones;
}
QVector<QwtZone> &QwtPlotCurve::zones() {
return d_data->zones;
}
/*!
\return Value of the baseline
\sa setBaseline()

View File

@@ -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<QwtZone>);
QVector<QwtZone> &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
{

View File

@@ -525,6 +525,15 @@ AllPlotObject::setUserData(QList<UserData*>user)
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<QwtZone> 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);