Skip to content
Permalink
Browse files

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.
  • Loading branch information...
liversedge committed Mar 12, 2019
1 parent cae7e0b commit 95901aa1e2b70db41bd421b7b60e8d3d8375e674
Showing with 54 additions and 0 deletions.
  1. +33 −0 qwt/src/qwt_plot_curve.cpp
  2. +12 −0 qwt/src/qwt_plot_curve.h
  3. +9 −0 src/Charts/AllPlot.cpp
@@ -94,6 +94,8 @@ class QwtPlotCurve::PrivateData
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()
@@ -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 @@ class QWT_EXPORT QwtPlotCurve:
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 @@ class QWT_EXPORT QwtPlotCurve:
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
{
@@ -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);

0 comments on commit 95901aa

Please sign in to comment.
You can’t perform that action at this time.