View Full Version : shifting curve up or down
oliver_mpt
23rd November 2012, 16:02
Hi,
I have plotted several curves (qwtPlotCurve) in the same plot (qwtPlot), and as they overlap a lot, I would like to shift some using a qwtCounter to increase an offset value that I would use to shift a selected curve up or down.
I was wondering what was the best way of doing it - is there any simple or build-in way to add a constant double to all the y values of my curve data ?
regards
Oliver
Uwe
24th November 2012, 09:37
Assuming that your points are stored in a QPolygonF:
class YourData: public QwtPointSeriesData
{
public:
YourData( const QVector<QPointF> &samples ):
QwtPointSeriesData( samples ):
m_offset( 0.0 )
{
}
void setOffset( double off )
{
m_offset = offset;
}
virtual QPointF sample( size_t index ) const
{
QPointF point = QwtPointSeriesData::sample( index );
return QPointF( point.x(), point.y() + m_offset );
}
virtual QRectF boundingRect() const
{
return QwtPointSeriesData::boundingRect().translated( 0.0, m_offset );
}
private:
double m_offset;
};
and:
curve->setData( new YourData( points ) );
Of course you have to replace QwtPointSeriesData by the type of series data object you were using so far ( QwtPlotCurve::setSamples does nothing else than creating such an data object internally - check the implementation ).
When you have many points it might be a good idea to use a different implementation for YourData::sample() that directly accesses your point container instead of calling the base class.
HTH,
Uwe
}
oliver_mpt
26th November 2012, 07:20
Hi Uwe,
Thanks for the detailed answer. I will experiment this approach today and report the results on the forum.
best regards
Oliver
oliver_mpt
26th November 2012, 11:17
Hello Uwe,
I pasted your code with almost no changes and it worled perfectly at once !
Thanks a lot for your support.
Oliver
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.