PDA

View Full Version : Problem with QwtPlotCurve::drawLines() function



vinothrajendran
5th February 2015, 12:40
I have a scenario where i have to plot a curve with different color based on time....I am using QwtPlotCurve::drawLines() to acheive this color segments.... The problem is "from" and "to" argument variable(marked in bold) in drawLines() takes only int type but i need to pass float type....

virtual void drawLines (QPainter *p, const QwtScaleMap &xMap,const QwtScaleMap &yMap, const QRectF &canvasRect, int from, int to) const;

any suggestions please.......

Uwe
8th February 2015, 10:46
from/to are indexes no coordinates !

Guess what you want to do is to overload QwtPlotCurve::drawLines(), where you split your index intervals according to your coordinates. As your points are ordered by time are you can use qwtUpperSampleIndex() to calculate the indexes corresponding to your time intervals.

Something like this:


class YourCurve: public QwtPlotCurve
{
public:
virtual void drawLines( QPainter *painter,
const QwtScaleMap &xMap, const QwtScaleMap &yMap,
const QRectF &canvasRect, int from, int to ) const
{
for_all_your_intervals()
{
int idx1 = indexOf( interval.min() );
int idx2 = indexOf( interval.max() );

painter->setPen( ... );
QwtPlotCurve::drawLines( painter, xMap, yMap, canvasRect, idx1 idx2 );
}
};

Uwe