Hello,
I have created a qwtPlotCurve and attached it to a QwtPlot, but I cannot see any curve there. Please help me to get it visible.
In this function I create the curves:
void OscillationGRN::plotCurves(){
for(int j = 0; j < ListOfPlots.size(); ++j){
//create new Curve
newCurve
->setPen
(QColor(Qt
::red));
double range[] ={0,20};
double step = 0.1;
// copy the data into the curves
newCurve->setData(CurveData(range, step));
newCurve->attach(ListOfPlots[j]);
}
}
void OscillationGRN::plotCurves(){
for(int j = 0; j < ListOfPlots.size(); ++j){
//create new Curve
QwtPlotCurve *newCurve = new QwtPlotCurve();
newCurve->setPen(QColor(Qt::red));
newCurve->setStyle(QwtPlotCurve::Lines);
newCurve->setCurveAttribute(QwtPlotCurve::Fitted);
double range[] ={0,20};
double step = 0.1;
// copy the data into the curves
newCurve->setData(CurveData(range, step));
newCurve->attach(ListOfPlots[j]);
}
}
To copy to clipboard, switch view to plain text mode
whereby
QVector<QwtPlot*> ListOfPlots;
QVector<QwtPlot*> ListOfPlots;
To copy to clipboard, switch view to plain text mode
is and CurveData is a class inherited from QwtData:
{
// The x values depend on its index and the y values
// can be calculated from the corresponding x value.
// So we don't need to store the values.
// Such an implementation is slower because every point
// has to be recalculated for every replot, but it demonstrates how
// QwtData can be used.
public:
CurveData( double rang1[2], double step)
{
rangeX[0]= rang1[0]; rangeX[1] = rang1[1];
range = (rangeX[1] - rangeX[0])/step;
if(range<0){
range = range *(-1);
}
d_size = size_t(range);
cout << "range = "<< range << " , d_size= " << d_size<< endl; // <<<<<<<< this output IS seen in console
}
{
return new CurveData(*this);
}
virtual size_t size() const
{
return d_size;
}
virtual double x(size_t i) const
{
cout << "x = " << rangeX[0] + i*((rangeX[1]- rangeX[0])/range) << endl; // <<<<<<<< this output is NOT seen in console
// here the array with x values will be produced
return rangeX[0] + i*((rangeX[1]- rangeX[0])/range);
}
virtual double y(size_t i) const
{
cout << "y = " << sin(2*3.1415926*x(i)/T)+1.0 << endl; // <<<<<<<< this output is NOT seen in console
return sin(2*3.1415926*x(i)/T)+1.0;
}
private:
size_t d_size;
double range;
double rangeX[2];
};
class CurveData: public QwtData
{
// The x values depend on its index and the y values
// can be calculated from the corresponding x value.
// So we don't need to store the values.
// Such an implementation is slower because every point
// has to be recalculated for every replot, but it demonstrates how
// QwtData can be used.
public:
CurveData( double rang1[2], double step)
{
rangeX[0]= rang1[0]; rangeX[1] = rang1[1];
range = (rangeX[1] - rangeX[0])/step;
if(range<0){
range = range *(-1);
}
d_size = size_t(range);
cout << "range = "<< range << " , d_size= " << d_size<< endl; // <<<<<<<< this output IS seen in console
}
virtual QwtData *copy() const
{
return new CurveData(*this);
}
virtual size_t size() const
{
return d_size;
}
virtual double x(size_t i) const
{
cout << "x = " << rangeX[0] + i*((rangeX[1]- rangeX[0])/range) << endl; // <<<<<<<< this output is NOT seen in console
// here the array with x values will be produced
return rangeX[0] + i*((rangeX[1]- rangeX[0])/range);
}
virtual double y(size_t i) const
{
cout << "y = " << sin(2*3.1415926*x(i)/T)+1.0 << endl; // <<<<<<<< this output is NOT seen in console
return sin(2*3.1415926*x(i)/T)+1.0;
}
private:
size_t d_size;
double range;
double rangeX[2];
};
To copy to clipboard, switch view to plain text mode
Bookmarks