PDA

View Full Version : Different Units for a Scale?



HappyCoder
23rd July 2015, 12:00
Hi,

actually my measurement values are a pair of time and pressure.
The pressure value is stored in [mbar].

What is the best way in Qwt to change the unit eg. [Torr] or [Pa] and other.

It it necessary to recalculate all values of a curve ( which is not good) or
is it possible to change the axis only?

Stefan

Uwe
24th July 2015, 06:25
You could derive from QwtSeriesData<QPointF>. Store the samples as they are and do the translation in QwtSeriesData<QPointF>::sample() and QwtSeriesData<QPointF>::boundingRect().

Uwe

HappyCoder
28th July 2015, 09:05
Hello Uwe,

just an idea, but can this be done also using QwtTransform if i add a new one like this (not tried):



mbarToTorrTransform::mbarToTorrTransform():
QwtTransform()
{
}
mbarToTorrTransform::~mbarToTorrTransform()
{
}

double mbarToTorrTransform::transform( double value ) const
{
return value*0.75006;
}
double mbarToTorrTransform::invTransform( double value ) const
{
return value/0.75006;
}


Thx
Stefan

HappyCoder
7th October 2015, 08:10
With the grateful help of phenoboy and some modifications i was able to create a subclass of QwtSeriesData.
But now application crashes on close with this message in Debugger

can't find linker symbol for virtual table for `QwtSeriesStore<QPointF>' value
found `construction vtable for QwtSeriesStore<QPointF>-in-PlotCurve' instead

What is going wrong here? (clean Project, qmake, rebuild all done)

It looks like the app crahes here:


template <typename T>
QwtSeriesStore<T>::~QwtSeriesStore()
{
delete d_series; // CRASH
}


Thx
Stefan

My code:

plotcurve.h


#include "qwt/subclass/seriesdata.h"
...
SeriesData curveData;


plotcurve.cpp


void PlotCurve::newCurveData()
{
if( isPointerValid() )
{
// with subclass from QwtSeriesData
curveData.setMinYValue( d_data->pmdata.data()->valueMin );
curveData.setMaxYValue( d_data->pmdata.data()->valueMax );
curveData.setSamples(d_data->pmdata.data()->timestamps,
d_data->pmdata.data()->values);
curveData.setFactorY( d_data->unitPressureFactor );

setSamples( &curveData );
}



seriesdata.h


#include "qwt_series_data.h"
#include <QObject>

class SeriesData : public QwtSeriesData<QPointF>
{
public:
SeriesData();

virtual QPointF sample( size_t index ) const;
virtual size_t size() const;
virtual QRectF boundingRect() const;

double getFactorY() const;
void setFactorY(const double &value);

void setMaxYValue(const double &value);
void setMinYValue(const double &value);

void clear();

void setSamples( const QVector<double> &xData, const QVector<double> &yData );
QVector<double> &pointsX();
QVector<double> &pointsY();
QRectF _boundingRect;

protected:
QVector<double> points_x;
QVector<double> points_y;
double factorY;
double maxYValue;
double minYValue;
};




#include "seriesdata.h"

#include "qwt_series_data.h"

SeriesData::SeriesData()
{
qDebug() << Q_FUNC_INFO;

factorY = 1;
points_x.reserve(1000);
points_y.reserve(1000);
}

QPointF SeriesData::sample(size_t index) const
{
QPointF p(points_x.value(index), points_y.value(index));
p.setY(factorY*p.y());
return p;
}

size_t SeriesData::size() const
{
return points_x.size();
}

QRectF SeriesData::boundingRect() const
{
return _boundingRect;
}

QVector<double> &SeriesData::pointsX()
{
return points_x;
}

QVector<double> &SeriesData::pointsY()
{
return points_y;
}

double SeriesData::getFactorY() const
{
return factorY;
}

void SeriesData::setFactorY(const double &value)
{
factorY = value;
}

void SeriesData::setMaxYValue(const double &value)
{
maxYValue = value;
}

void SeriesData::setMinYValue(const double &value)
{
minYValue = value;
}

void SeriesData::clear()
{
points_x.clear();
points_y.clear();
}

void SeriesData::setSamples(const QVector<double> &xData, const QVector<double> &yData)
{
points_x = xData;
points_y = yData;

_boundingRect.setLeft( (qreal)(xData.first()) );
_boundingRect.setRight( (qreal)(xData.last()) );
_boundingRect.setTop( maxYValue );
_boundingRect.setBottom( minYValue );
}