[Qt-interest] unresolved Symbol (QMetaObject const QwtPlot::staticMetaObject) in qwtplot derived Class

Matthias Pospiech matthias.pospiech at gmx.de
Thu Dec 11 14:00:43 CET 2008


Ian Thomson schrieb:
> Hi,
>
> Could you post a small piece of code which demonstrates the problem?
>
>   
In the following is the code of the complete class. It is based on Qt 
and the qwt libary.


#ifndef QSCATTERPLOT_H_
#define QSCATTERPLOT_H_

#include <QtGui/QWidget>

#include <qwt_plot.h>
#include <qwt_plot_curve.h>
#include <qwt_plot_grid.h>
#include <qwt_plot_curve.h>
#include <qwt_plot_layout.h>
#include <qwt_symbol.h>
#include <qwt_plot_zoomer.h>
#include <qwt_plot_panner.h>
#include <qwt_scale_widget.h>


class QScatterPlot : public QwtPlot
{
    Q_OBJECT
public:
    QScatterPlot(QWidget* parent = 0);
    virtual ~QScatterPlot();

    void initWidget();
    void setSymbol(QwtSymbol::Style symbol, QColor c, QSize size);
    void setData(const double * xData, const double * yData, int size);
    void setData(const double * xData, const double * yData, int start, 
int size);

public:
    QwtPlotCurve * Curve;
    QwtPlotZoomer * zoomer;

private:
    struct structDataXY{
        structDataXY(): x(NULL), y(NULL) {}
        double * x;
        double * y;
    };
    structDataXY m_data;

//private slots:
//    void OnZoomed()
//    {
//        if (zoomer->zoomRectIndex() == 0)
//        {
//            this->setAxisAutoScale(QwtPlot::xBottom);
//            this->setAxisAutoScale(QwtPlot::yLeft);
//            this->setAxisAutoScale(QwtPlot::yRight);       
//        }
//    }
};
#endif

#include "QScatterPlot.h"


class Zoomer: public QwtPlotZoomer
{
public:
    Zoomer(QwtPlot * qwtplot): QwtPlotZoomer(qwtplot->canvas()), 
plot(qwtplot)
    {
        setTrackerMode(QwtPicker::AlwaysOn);
        init();
    }

private:
    void init()
    {
        // LeftButton for the zooming
        // MidButton for the panning
        // RightButton: zoom out by 1
        // Ctrl+RighButton: zoom out to full size
       
        this->setMousePattern(QwtEventPattern::MouseSelect2,
            Qt::RightButton, Qt::ControlModifier);
        this->setMousePattern(QwtEventPattern::MouseSelect3,
            Qt::RightButton);

        QwtPlotPanner *panner = new QwtPlotPanner(plot->canvas());
        panner->setAxisEnabled(QwtPlot::yRight, false);
        panner->setMouseButton(Qt::MidButton);

        // Avoid jumping when labels with more/less digits
        // appear/disappear when scrolling vertically

        const QFontMetrics fm(plot->axisWidget(QwtPlot::yLeft)->font());
        QwtScaleDraw *sd = plot->axisScaleDraw(QwtPlot::yLeft);
        sd->setMinimumExtent( fm.width("100.00") );

        const QColor c(Qt::darkBlue);
        this->setRubberBandPen(c);
        this->setTrackerPen(c);
    }

protected:
    virtual QwtText trackerText( const QwtDoublePoint& p ) const
    {
        QwtText t( QwtPlotPicker::trackerText( p ));

        QColor c(Qt::white);
        c.setAlpha(180);
        t.setBackgroundBrush( QBrush(c) );

        return t;
    }

private:
    QwtPlot * plot;
};



QScatterPlot::QScatterPlot(QWidget* parent /*= 0*/) : QwtPlot(parent), 
Curve(NULL)
{
    Curve = new QwtPlotCurve();

    QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    sizePolicy.setHorizontalStretch(20);
    sizePolicy.setVerticalStretch(20);
    //sizePolicy.setHeightForWidth(sizePolicy().hasHeightForWidth());
    this->setSizePolicy(sizePolicy);

    initWidget();

    //connect(zoomer, SIGNAL(zoomed(const QwtDoubleRect &)), this, 
SLOT(OnZoomed()));
}


QScatterPlot::~QScatterPlot()
{
}


void QScatterPlot::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);

    Curve->setStyle(QwtPlotCurve::NoCurve);
    Curve->setPaintAttribute(QwtPlotCurve::PaintFiltered);

    setSymbol(QwtSymbol::Ellipse, Qt::blue, QSize(4,4));
 
    Curve->attach(this);

    replot();

    zoomer = new Zoomer(this);
   
}

void QScatterPlot::setSymbol(QwtSymbol::Style symbol, QColor c, QSize size)
{
    Curve->setSymbol(QwtSymbol(symbol, QBrush(c), QPen(c), size));
}


void QScatterPlot::setData(const double * xData, const double * yData, 
int size)
{
    setData(xData, yData, 0, size);
}

void QScatterPlot::setData(const double * xData, const double * yData, 
int start, int size)
{
    if (m_data.x != NULL )
        delete [] m_data.x;
    if (m_data.y != NULL )
        delete [] m_data.y;
    m_data.x = new double [size];
    m_data.y = new double [size];
    memcpy(m_data.x, xData + start, size * sizeof(double));
    memcpy(m_data.y, yData + start, size * sizeof(double));
    Curve->setRawData(m_data.x, m_data.y, size);
}



More information about the Qt-interest-old mailing list