Here's the code if someone else is interested also. If there's better/more efficient way, let me know !!
header:
#include <qwt_plot_curve.h>
class CustomQwtCurveData: public QwtSeriesData<QPointF>
{
public:
CustomQwtCurveData();
QPointF realSample
( size_t index
) const;
virtual QPointF sample
( size_t index
) const;
virtual size_t size() const;
virtual QRectF boundingRect
() const;
void appendPoint(qreal x, qreal y);
quint64 pointsCount();
quint64 getLastX() const;
void setLastX(const quint64 &value);
qreal getFactorY() const;
void setFactorY(const qreal &value);
qreal getMaxYValue() const;
void setMaxYValue(const qreal &value);
qreal getMinYValue() const;
void setMinYValue(const qreal &value);
void clear();
QVector<double>& pointsX();
QVector<double>& pointsY();
protected:
QVector<double> points_x;
QVector<double> points_y;
qreal factorY;
qreal maxYValue;
qreal minYValue;
quint64 lastX;
};
#include <qwt_plot_curve.h>
class CustomQwtCurveData: public QwtSeriesData<QPointF>
{
public:
CustomQwtCurveData();
QPointF realSample( size_t index ) const;
virtual QPointF sample( size_t index ) const;
virtual size_t size() const;
virtual QRectF boundingRect() const;
void appendPoint(qreal x, qreal y);
quint64 pointsCount();
quint64 getLastX() const;
void setLastX(const quint64 &value);
qreal getFactorY() const;
void setFactorY(const qreal &value);
qreal getMaxYValue() const;
void setMaxYValue(const qreal &value);
qreal getMinYValue() const;
void setMinYValue(const qreal &value);
void clear();
QVector<double>& pointsX();
QVector<double>& pointsY();
QRectF _boundingRect;
protected:
QVector<double> points_x;
QVector<double> points_y;
qreal factorY;
qreal maxYValue;
qreal minYValue;
quint64 lastX;
};
To copy to clipboard, switch view to plain text mode
cpp:
#include "customqwtcurve.h"
#include <qwt_scale_map.h>
#include <qwt_point_data.h>
qreal CustomQwtCurveData::getMaxYValue() const
{
return maxYValue;
}
void CustomQwtCurveData::setMaxYValue(const qreal &value)
{
maxYValue = value;
}
QPointF CustomQwtCurveData
::realSample(size_t index
) const {
QPointF p
(points_x.
value(index
), points_y.
value(index
));
return p;
}
QPointF CustomQwtCurveData
::sample(size_t index
) const {
QPointF p
(points_x.
value(index
), points_y.
value(index
));
p.setY(factorY*p.y());
return p;
}
size_t CustomQwtCurveData::size() const
{
return points_x.size();
}
QRectF CustomQwtCurveData
::boundingRect() const {
// adjust the bounding rectangle
return _boundingRect;
}
qreal CustomQwtCurveData::getFactorY() const
{
return factorY;
}
void CustomQwtCurveData::setFactorY(const qreal &value)
{
factorY = value;
}
void CustomQwtCurveData::appendPoint(qreal x, qreal y)
{
if (y>maxYValue) {
maxYValue=y;
}
if (y<minYValue) {
minYValue=y;
}
points_x.append(x);
points_y.append(y);
if ( _boundingRect.width() < 0 || _boundingRect.height() < 0 )
{
_boundingRect.setRect( sample.x(), sample.y(), 0.0, 0.0 );
}
else
{
_boundingRect.setRight( sample.x() );
if ( sample.y() > _boundingRect.bottom() )
_boundingRect.setBottom( sample.y() );
qreal top=_boundingRect.top();
qreal bottom=_boundingRect.bottom();
if ( sample.y() < _boundingRect.top() )
_boundingRect.setTop( sample.y() );
}
}
quint64 CustomQwtCurveData::pointsCount() {
return points_x.size();
}
void CustomQwtCurveData::clear() {
points_x.clear();
points_y.clear();
}
QVector<double> &CustomQwtCurveData::pointsX()
{
return points_x;
}
QVector<double> &CustomQwtCurveData::pointsY()
{
return points_y;
}
qreal CustomQwtCurveData::getMinYValue() const
{
return minYValue;
}
void CustomQwtCurveData::setMinYValue(const qreal &value)
{
minYValue = value;
}
CustomQwtCurveData::CustomQwtCurveData()
{
factorY=1;
maxYValue=0;
minYValue=0;
points_x.reserve(5000);
points_y.reserve(5000);
}
quint64 CustomQwtCurveData::getLastX() const
{
return lastX;
}
void CustomQwtCurveData::setLastX(const quint64 &value)
{
lastX = value;
}
#include "customqwtcurve.h"
#include <qwt_scale_map.h>
#include <qwt_point_data.h>
qreal CustomQwtCurveData::getMaxYValue() const
{
return maxYValue;
}
void CustomQwtCurveData::setMaxYValue(const qreal &value)
{
maxYValue = value;
}
QPointF CustomQwtCurveData::realSample(size_t index) const
{
QPointF p(points_x.value(index), points_y.value(index));
return p;
}
QPointF CustomQwtCurveData::sample(size_t index) const
{
QPointF p(points_x.value(index), points_y.value(index));
p.setY(factorY*p.y());
return p;
}
size_t CustomQwtCurveData::size() const
{
return points_x.size();
}
QRectF CustomQwtCurveData::boundingRect() const
{
// adjust the bounding rectangle
return _boundingRect;
}
qreal CustomQwtCurveData::getFactorY() const
{
return factorY;
}
void CustomQwtCurveData::setFactorY(const qreal &value)
{
factorY = value;
}
void CustomQwtCurveData::appendPoint(qreal x, qreal y)
{
if (y>maxYValue) {
maxYValue=y;
}
if (y<minYValue) {
minYValue=y;
}
points_x.append(x);
points_y.append(y);
QPointF sample=QPointF(x,y);
if ( _boundingRect.width() < 0 || _boundingRect.height() < 0 )
{
_boundingRect.setRect( sample.x(), sample.y(), 0.0, 0.0 );
}
else
{
_boundingRect.setRight( sample.x() );
if ( sample.y() > _boundingRect.bottom() )
_boundingRect.setBottom( sample.y() );
qreal top=_boundingRect.top();
qreal bottom=_boundingRect.bottom();
if ( sample.y() < _boundingRect.top() )
_boundingRect.setTop( sample.y() );
}
}
quint64 CustomQwtCurveData::pointsCount() {
return points_x.size();
}
void CustomQwtCurveData::clear() {
points_x.clear();
points_y.clear();
}
QVector<double> &CustomQwtCurveData::pointsX()
{
return points_x;
}
QVector<double> &CustomQwtCurveData::pointsY()
{
return points_y;
}
qreal CustomQwtCurveData::getMinYValue() const
{
return minYValue;
}
void CustomQwtCurveData::setMinYValue(const qreal &value)
{
minYValue = value;
}
CustomQwtCurveData::CustomQwtCurveData()
{
factorY=1;
maxYValue=0;
minYValue=0;
points_x.reserve(5000);
points_y.reserve(5000);
}
quint64 CustomQwtCurveData::getLastX() const
{
return lastX;
}
void CustomQwtCurveData::setLastX(const quint64 &value)
{
lastX = value;
}
To copy to clipboard, switch view to plain text mode
Bookmarks