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;
};
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;
};
To copy to clipboard, switch view to plain text mode
and:
curve->setData( new YourData( points ) );
curve->setData( new YourData( points ) );
To copy to clipboard, switch view to plain text mode
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
}
Bookmarks