edit: Sorry for starting a new topic! I meant to reply to my original thread!
Hey,
After spending a few more hours on this, I just copied the "CurveData" class included with one of the examples to use as my object to store data points. Now I've run into another issue -- I don't get what function actually 'draws' the data, and whats the point of the QwtPlotDirectPainter class. Please take a look at my source:
/********** CURVEDATA CLASS DEFN *****************/
CurveData::CurveData():d_count(0)
{}
void CurveData::append(double *x, double *y, int count)
{
//std::cerr << *x << " " << *y << std::endl;
int newSize = ( (d_count + count) / 1000 + 1 ) * 1000;
if ( newSize > size() )
{
d_x.resize(newSize);
d_y.resize(newSize);
}
for ( register int i = 0; i < count; i++ )
{
d_x[d_count + i] = x[i];
d_y[d_count + i] = y[i];
}
d_count += count;
}
int CurveData::count() const
{ return d_count; }
int CurveData::size() const
{ return d_x.size(); }
const double *CurveData::x() const
{ return d_x.data(); }
const double *CurveData::y() const
{ return d_y.data(); }
/********** CURVEDATA CLASS DEFN *****************/
CurveData::CurveData():d_count(0)
{}
void CurveData::append(double *x, double *y, int count)
{
//std::cerr << *x << " " << *y << std::endl;
int newSize = ( (d_count + count) / 1000 + 1 ) * 1000;
if ( newSize > size() )
{
d_x.resize(newSize);
d_y.resize(newSize);
}
for ( register int i = 0; i < count; i++ )
{
d_x[d_count + i] = x[i];
d_y[d_count + i] = y[i];
}
d_count += count;
}
int CurveData::count() const
{ return d_count; }
int CurveData::size() const
{ return d_x.size(); }
const double *CurveData::x() const
{ return d_x.data(); }
const double *CurveData::y() const
{ return d_y.data(); }
To copy to clipboard, switch view to plain text mode
/********** DEVICEDISPLAY CLASS DEFN *************/
{
_dataPainter = new QwtPlotDirectPainter();
setAutoReplot(false);
/* Improve Drawing Performance */
canvas()->setAttribute(Qt::WA_PaintOutsidePaintEvent, true);
canvas()->setAttribute(Qt::WA_PaintOnScreen, true);
/* Draw the plot */
// plot setup
plotLayout()->setAlignCanvasToScales(true);
setAxisTitle
(QwtPlot::xBottom,
"Time [s]");
setAxisScale
(QwtPlot::xBottom, _dataInterval
->minValue
(), _dataInterval
->maxValue
());
setAxisScale
(QwtPlot::yLeft,
-720.0,
720.0);
// grid setup
_displayGrid->enableX(true); // major vertical gridlines
_displayGrid->enableXMin(true); // minor vertical gridlines
_displayGrid->enableY(true); // major vertical gridlines
_displayGrid->enableYMin(true); // minor vertical gridlines
_displayGrid->attach(this);
// curve and data setup
_dataPoints = new CurveData();
_dataCurve
->setRenderHint
(QwtPlotItem::RenderAntialiased,
true);
_dataCurve
->setPaintAttribute
(QwtPlotCurve::ClipPolygons,
false);
_dataCurve->attach(this);
replot();
}
DeviceDisplay::~DeviceDisplay()
{
delete _dataPainter;
}
void DeviceDisplay::RefreshDisplay(double xNew, double yNew)
{
/* Redraw the display to incorporate any new points */
_dataPoints->append(&xNew,&yNew,1);
_dataCurve->setRawSamples( _dataPoints->x(),
_dataPoints->y(),
_dataPoints->count());
_dataPainter->drawSeries( _dataCurve,
_dataCurve->dataSize()-1,
_dataCurve->dataSize()-1);
}
/********** DEVICEDISPLAY CLASS DEFN *************/
DeviceDisplay::DeviceDisplay(QWidget* parent):QwtPlot(parent)
{
_dataPainter = new QwtPlotDirectPainter();
_dataInterval = new QwtDoubleInterval(0.0, 10.0);
setAutoReplot(false);
/* Improve Drawing Performance */
canvas()->setPaintAttribute(QwtPlotCanvas::PaintCached, false);
canvas()->setAttribute(Qt::WA_PaintOutsidePaintEvent, true);
canvas()->setAttribute(Qt::WA_PaintOnScreen, true);
/* Draw the plot */
// plot setup
plotLayout()->setAlignCanvasToScales(true);
setAxisTitle(QwtPlot::xBottom, "Time [s]");
setAxisScale(QwtPlot::xBottom, _dataInterval->minValue(), _dataInterval->maxValue());
setAxisScale(QwtPlot::yLeft, -720.0, 720.0);
// grid setup
_displayGrid = new QwtPlotGrid();
_displayGrid->enableX(true); // major vertical gridlines
_displayGrid->enableXMin(true); // minor vertical gridlines
_displayGrid->enableY(true); // major vertical gridlines
_displayGrid->enableYMin(true); // minor vertical gridlines
_displayGrid->attach(this);
// curve and data setup
_dataPoints = new CurveData();
_dataCurve = new QwtPlotCurve();
_dataCurve->setStyle(QwtPlotCurve::Lines);
const QColor &c = Qt::black;
_dataCurve->setSymbol(new QwtSymbol(QwtSymbol::XCross,
QBrush(c), QPen(c), QSize(10, 10)) );
_dataCurve->setRenderHint(QwtPlotItem::RenderAntialiased, true);
_dataCurve->setPaintAttribute(QwtPlotCurve::ClipPolygons, false);
_dataCurve->attach(this);
replot();
}
DeviceDisplay::~DeviceDisplay()
{
delete _dataPainter;
}
void DeviceDisplay::RefreshDisplay(double xNew, double yNew)
{
/* Redraw the display to incorporate any new points */
_dataPoints->append(&xNew,&yNew,1);
_dataCurve->setRawSamples( _dataPoints->x(),
_dataPoints->y(),
_dataPoints->count());
_dataPainter->drawSeries( _dataCurve,
_dataCurve->dataSize()-1,
_dataCurve->dataSize()-1);
}
To copy to clipboard, switch view to plain text mode
The last part of the above code, the call to "drawSeries" -- doesn't do anything that I can notice except for give me a whole bunch of XServer errors (to be clear I can comment the call out and I'll still get the exact same plot with the lines drawn). So...
* I don't get when the points and lines are drawn if I comment the function out,
* What the "drawSeries" function is doing,
* Why am I getting X Server Errors?
And here's where I'm trying to draw stuff:
ui(new Ui::Diag)
{
ui->setupUi(this);
// add display to the gui
_display = new DeviceDisplay(ui->horizontalLayoutWidget);
ui->horizontalLayout->addWidget(_display);
// try plotting something
_display->RefreshDisplay(2,360);
_display->RefreshDisplay(3,260);
_display->RefreshDisplay(4,160);
_display->RefreshDisplay(5,60);
_display->RefreshDisplay(6,130);
_display->RefreshDisplay(7,240);
}
Diag::~RCNSDiag()
{
delete ui;
}
Diag::Diag(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::Diag)
{
ui->setupUi(this);
// add display to the gui
_display = new DeviceDisplay(ui->horizontalLayoutWidget);
ui->horizontalLayout->addWidget(_display);
// try plotting something
_display->RefreshDisplay(2,360);
_display->RefreshDisplay(3,260);
_display->RefreshDisplay(4,160);
_display->RefreshDisplay(5,60);
_display->RefreshDisplay(6,130);
_display->RefreshDisplay(7,240);
}
Diag::~RCNSDiag()
{
delete ui;
}
To copy to clipboard, switch view to plain text mode
Here are the X Server errors if it helps:
X Error: BadDrawable (invalid Pixmap or Window parameter) 9
Major opcode: 55 (X_CreateGC)
Resource id: 0x0
X Error: BadDrawable (invalid Pixmap or Window parameter) 9
Major opcode: 55 (X_CreateGC)
Resource id: 0x0
X Error: BadGC (invalid GC parameter) 13
Major opcode: 56 (X_ChangeGC)
Resource id: 0x0
X Error: BadGC (invalid GC parameter) 13
Major opcode: 56 (X_ChangeGC)
Resource id: 0x0
X Error: BadGC (invalid GC parameter) 13
Major opcode: 59 (X_SetClipRectangles)
Resource id: 0x0
X Error: BadGC (invalid GC parameter) 13
Major opcode: 59 (X_SetClipRectangles)
Resource id: 0x0
X Error: BadGC (invalid GC parameter) 13
Major opcode: 59 (X_SetClipRectangles)
Resource id: 0x0
X Error: BadGC (invalid GC parameter) 13
Major opcode: 59 (X_SetClipRectangles)
Resource id: 0x0
X Error: BadGC (invalid GC parameter) 13
Major opcode: 56 (X_ChangeGC)
Resource id: 0x0
X Error: BadDrawable (invalid Pixmap or Window parameter) 9
Major opcode: 69 (X_FillPoly)
Resource id: 0x0
X Error: BadGC (invalid GC parameter) 13
Major opcode: 56 (X_ChangeGC)
Resource id: 0x0
X Error: BadDrawable (invalid Pixmap or Window parameter) 9
Major opcode: 69 (X_FillPoly)
Resource id: 0x0
X Error: BadGC (invalid GC parameter) 13
Major opcode: 56 (X_ChangeGC)
Resource id: 0x0
.... these errors continue for awhile
X Error: BadDrawable (invalid Pixmap or Window parameter) 9
Major opcode: 55 (X_CreateGC)
Resource id: 0x0
X Error: BadDrawable (invalid Pixmap or Window parameter) 9
Major opcode: 55 (X_CreateGC)
Resource id: 0x0
X Error: BadGC (invalid GC parameter) 13
Major opcode: 56 (X_ChangeGC)
Resource id: 0x0
X Error: BadGC (invalid GC parameter) 13
Major opcode: 56 (X_ChangeGC)
Resource id: 0x0
X Error: BadGC (invalid GC parameter) 13
Major opcode: 59 (X_SetClipRectangles)
Resource id: 0x0
X Error: BadGC (invalid GC parameter) 13
Major opcode: 59 (X_SetClipRectangles)
Resource id: 0x0
X Error: BadGC (invalid GC parameter) 13
Major opcode: 59 (X_SetClipRectangles)
Resource id: 0x0
X Error: BadGC (invalid GC parameter) 13
Major opcode: 59 (X_SetClipRectangles)
Resource id: 0x0
X Error: BadGC (invalid GC parameter) 13
Major opcode: 56 (X_ChangeGC)
Resource id: 0x0
X Error: BadDrawable (invalid Pixmap or Window parameter) 9
Major opcode: 69 (X_FillPoly)
Resource id: 0x0
X Error: BadGC (invalid GC parameter) 13
Major opcode: 56 (X_ChangeGC)
Resource id: 0x0
X Error: BadDrawable (invalid Pixmap or Window parameter) 9
Major opcode: 69 (X_FillPoly)
Resource id: 0x0
X Error: BadGC (invalid GC parameter) 13
Major opcode: 56 (X_ChangeGC)
Resource id: 0x0
.... these errors continue for awhile
To copy to clipboard, switch view to plain text mode
And the same output regardless of whether I comment the drawSeries call out or not:

I'd really appreciate any insight or advice... I'm having a lot of trouble figuring out what I'm doing wrong.
Regards,
kif
Bookmarks