[Qt-interest] Qwt Error
Matthias Pospiech
matthias.pospiech at gmx.de
Tue May 5 13:57:29 CEST 2009
Srdjan Todorovic schrieb:
> Hi,
>
> 2009/5/5 Sujan Dasmahapatra <sdh at lmglasfiber.com>:
>
>> Still these are the errors I am getting Srdjian.I have included qwt_plot.h header.
>>
>>
What are you compiling? An example that ships with qwt? If so, then it
must work, otherwise you are doing something wrong.
If you are creating your own example take care that you include all
necessary header files. Typically you need more than just qwt_plot.h
Below is my CurvePlot class, based on qwt.
Matthias
#ifndef QCURVEPLOT_H_
#define QCURVEPLOT_H_
#include <QtGui/QAction>
#include <QtGui/QWidget>
#include <QtGui/QHBoxLayout>
#include <qwt_plot.h>
#include <qwt_plot_curve.h>
#include <qwt_legend.h>
#include <qwt_scale_engine.h>
#include <qwt_text.h>
#include <qwt_scale_widget.h>
#include <qwt_plot_zoomer.h>
#include <qwt_plot_panner.h>
#include <qwt_plot_layout.h>
#include "Zoomer.h"
#include <vector>
using std::vector;
class QCurvePlot : public QwtPlot
{
Q_OBJECT
public:
QCurvePlot(QWidget* parent = 0, Qt::WFlags flags = 0);
virtual ~QCurvePlot();
private:
void initZoomer();
void initWidget();
void clear();
Zoomer * zoomer;
public:
vector<QwtPlotCurve*> Curve;
QwtLegend legend;
QwtLinearScaleEngine * ylinearScaleEngine;
struct structDataXY{
double * x;
double * y;
};
vector<structDataXY> m_data;
public:
void addCurve();
void setData(const unsigned int number, vector<double> & xData,
vector<double> & yData, int start, int size);
void setData(const unsigned int number, vector<double> & xData,
vector<double> & yData);
void setData(const unsigned int number, const double * xData, const
double * yData, int size);
void setData(const unsigned int number, const double * xData, const
double * yData, int start, int size);
void insertLegend(QwtPlot::LegendPosition legendPosition);
};
#endif
#include "QCurvePlot.h"
QCurvePlot::QCurvePlot(QWidget* parent /*= 0*/, Qt::WFlags flags /*=
0*/) //: QWidget(parent, flags)
: QwtPlot(parent), zoomer(NULL), ylinearScaleEngine(new
QwtLinearScaleEngine())
{
QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
sizePolicy.setHorizontalStretch(20);
sizePolicy.setVerticalStretch(20);
this->setSizePolicy(sizePolicy);
initWidget();
}
QCurvePlot::~QCurvePlot()
{
for (int i = 0; i < (int)m_data.size(); i++)
{
if (m_data[i].x != NULL )
delete [] m_data[i].x;
if (m_data[i].y != NULL )
delete [] m_data[i].y;
if (Curve[i])
delete Curve[i];
}
}
void QCurvePlot::clear()
{
QwtPlot::clear();
Curve.clear();
}
void QCurvePlot::initWidget()
{
setFrameStyle(QFrame::NoFrame);
setLineWidth(0);
setCanvasBackground(QColor(255,255,255));
setCanvasLineWidth(1);
plotLayout()->setAlignCanvasToScales(true);
//QwtPlotGrid *grid = new QwtPlotGrid;
//grid->setMajPen(QPen(Qt::gray, 0, Qt::DotLine));
//grid->attach(this);
setAxisAutoScale(QwtPlot::xBottom);
setAxisAutoScale(QwtPlot::yLeft);
axisScaleEngine(QwtPlot::xBottom)->setAttributes(QwtScaleEngine::Floating);
axisScaleEngine(QwtPlot::yLeft)->setAttributes(QwtScaleEngine::Floating);
axisScaleEngine(QwtPlot::yRight)->setAttributes(QwtScaleEngine::Floating);
replot();
zoomer = new Zoomer(this);
}
void QCurvePlot::addCurve()
{
Curve.push_back(new QwtPlotCurve);
int newCurveNumber = Curve.size() - 1;
Curve[newCurveNumber]->setYAxis(QwtPlot::yLeft);
Curve[newCurveNumber]->setRenderHint(QwtPlotItem::RenderAntialiased);
Curve[newCurveNumber]->setStyle(QwtPlotCurve::Lines);
Curve[newCurveNumber]->setPen(QColor(Qt::blue));
Curve[newCurveNumber]->attach(this); // attach Curve to qwtPlot
structDataXY dataXY;
m_data.push_back(dataXY);
m_data[m_data.size() - 1 ].x = NULL;
m_data[m_data.size() - 1 ].y = NULL;
}
void QCurvePlot::insertLegend(QwtPlot::LegendPosition legendPosition)
{
QwtPlot::insertLegend(&legend, legendPosition);
}
void QCurvePlot::setData(const unsigned int number, vector<double> &
xData, vector<double> & yData, int start, int size)
{
setData(number, &xData[0], &yData[0], start, size);
}
void QCurvePlot::setData(const unsigned int number, vector<double> &
xData, vector<double> & yData)
{
setData(number, &xData[0], &yData[0], 0, xData.size());
}
void QCurvePlot::setData(const unsigned int number, const double *
xData, const double * yData, int size)
{
setData(number, xData, yData, 0, size);
//if (number <= m_data.size())
//{
// int arraynumber = number - 1;
// if (m_data[arraynumber].x != NULL )
// delete [] m_data[arraynumber].x;
// if (m_data[arraynumber].y != NULL )
// delete [] m_data[arraynumber].y;
// m_data[arraynumber].x = new double [size];
// m_data[arraynumber].y = new double [size];
// memcpy(m_data[arraynumber].x, xData, size * sizeof(double));
// memcpy(m_data[arraynumber].y, yData, size * sizeof(double));
// //Curve[number].setRawData(m_data[arraynumber].x,
m_data[arraynumber].y, size);
// Curve[number].setData(m_data[arraynumber].x,
m_data[arraynumber].y, size);
// zoomer->initScale();
// //initZoomer();
//}
}
void QCurvePlot::setData(const unsigned int number, const double *
xData, const double * yData, int start, int size)
{
if (number <= m_data.size())
{
int arraynumber = number;
if (m_data[arraynumber].x != NULL )
delete [] m_data[arraynumber].x;
if (m_data[arraynumber].y != NULL )
delete [] m_data[arraynumber].y;
m_data[arraynumber].x = new double [size];
m_data[arraynumber].y = new double [size];
memcpy(m_data[arraynumber].x, xData + start, size * sizeof(double));
memcpy(m_data[arraynumber].y, yData + start, size * sizeof(double));
Curve[number]->setRawData(m_data[arraynumber].x,
m_data[arraynumber].y, size);
}
}
More information about the Qt-interest-old
mailing list