PDA

View Full Version : qwt plots & inheritance



fatecasino
14th December 2010, 02:04
well, I am doing something definitely wrong, but I can't find it..

I followed the steps of "bode" example and created a class called my2dplot
In the constructor of the class I implemented everything, like axis titles, how to get data, attach curves, etc.


class my2dPlot : public QwtPlot
{
Q_OBJECT

public:
my2dPlot(QWidget *parent = 0);
// int value() const;
public Q_SLOTS:
void setDamp(double damping);
public slots:
//general purpose functions
void gridOn(); //sets the grid on-off
double** getCurveData();//returns the data from file

//main spectroscopy curve functions
void attachData2Curve(double**);//attach data to main curve
void attachCurve2Plot();//attach main curve to plot widget
void plotMainCurve(const QString &fileName );//function to call when you want to plot the main curve
//it includes the call of the three previous functions
//getCurveData, attachData2Curve, attachCurve2Plot
int getDataSize(); //returns the size of the data
void setDataSize(int);//sets the data size

//Continuum Curve functions
void attachData2Continuum(double**);//attach data to Continuum curve
void attachContinuum2Plot();//attach Continuum curve to plot widget
void plotContinuumCurve(QString &fileName);//function to call when you want to plot the Continuum curve

//set the data file name to read
void setDataFile (QString);
//get the data file name to read
QString getDataFile ();
private slots:


signals:

private:
QwtPlot *myPlot;
QwtPlotGrid *grid;

QwtPlotCurve *mainCurve;
QwtPlotMarker *mainCurveMarker;

QwtPlotCurve *continuumCurve;
QwtPlotMarker *continuumCurveMarker;
QString dataFile;
int dataSize;

};


Then I created a central widget including a member of my2dplot




class QwtPlotZoomer;
class QwtPlotPicker;
class QwtPlotPanner;
class my2dPlot;
class QPolygon;


class MyWidget : public QWidget
{
public:
MyWidget(QWidget *parent = 0);
my2dPlot *mainPlot;

protected:

private slots:

private Q_SLOTS:
void moved(const QPoint &);
void selected(const QPolygon &);

#ifndef QT_NO_PRINTER
void print();
#endif
void exportDocument();
void enableZoomMode(bool);

signals:


private:
//my2dPlot *mainPlot;
QPushButton *quitButton;

void showInfo(QString text = QString::null);
QwtPlotZoomer *d_zoomer[2];
QwtPlotPicker *d_picker;
QwtPlotPanner *d_panner;
};

and then I set this widget as the mainWidget in the mainwindow.h

The problem is that in the main window a plot area appears (with no background color-grey) and it does not show ANYTHING of what is described in the constructor of my2dclass. How is this possible? I mean, how is it possible that the widget creates a qwt plot (actually a my2dplot plot) and it does not take into consideration the rest of the my2dclass constructor?

It must be something obvious, but I cannot really see it!

fatecasino
14th December 2010, 14:35
what is the difference between:


my2dPlot::my2dPlot(QWidget *parent)
: QwtPlot(parent)
{

and


my2dPlot::my2dPlot(QWidget *parent)
: QWidget(parent)
{

the first appears as the screenshot of the first post
and the second appears as the screenshot f this post. It seems strange but there's something definitely wrong. The bode mouse tracker works only in grey area just above the green plot. The green plot is the one that is constructed in the my2dplot class. I can load a data file and see the plot, BUT I cannot use the zoomer of the bode example! Although I have declared:


class MyWidget : public QWidget
{
public:
MyWidget(QWidget *parent = 0);
my2dPlot *mainPlot;

which means that mainPlot is a my2dPlot type and not just QwtPlot type. Somehow 2 different plot objects(my2dPlot,QwtPlot) are constructed at the same exactly position(see attachment)!
Any ideas?!