Results 1 to 2 of 2

Thread: qwt6, trouble with QwtPlotDirectPainter and simple example

  1. #1
    Join Date
    Oct 2009
    Posts
    33
    Thanks
    2

    Default qwt6, trouble with QwtPlotDirectPainter and simple example

    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:

    Qt Code:
    1. /********** CURVEDATA CLASS DEFN *****************/
    2.  
    3. CurveData::CurveData():d_count(0)
    4. {}
    5.  
    6. void CurveData::append(double *x, double *y, int count)
    7. {
    8. //std::cerr << *x << " " << *y << std::endl;
    9. int newSize = ( (d_count + count) / 1000 + 1 ) * 1000;
    10. if ( newSize > size() )
    11. {
    12. d_x.resize(newSize);
    13. d_y.resize(newSize);
    14. }
    15.  
    16. for ( register int i = 0; i < count; i++ )
    17. {
    18. d_x[d_count + i] = x[i];
    19. d_y[d_count + i] = y[i];
    20. }
    21. d_count += count;
    22. }
    23.  
    24. int CurveData::count() const
    25. { return d_count; }
    26.  
    27. int CurveData::size() const
    28. { return d_x.size(); }
    29.  
    30. const double *CurveData::x() const
    31. { return d_x.data(); }
    32.  
    33. const double *CurveData::y() const
    34. { return d_y.data(); }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. /********** DEVICEDISPLAY CLASS DEFN *************/
    2.  
    3. DeviceDisplay::DeviceDisplay(QWidget* parent):QwtPlot(parent)
    4. {
    5. _dataPainter = new QwtPlotDirectPainter();
    6. _dataInterval = new QwtDoubleInterval(0.0, 10.0);
    7.  
    8. setAutoReplot(false);
    9.  
    10. /* Improve Drawing Performance */
    11. canvas()->setPaintAttribute(QwtPlotCanvas::PaintCached, false);
    12. canvas()->setAttribute(Qt::WA_PaintOutsidePaintEvent, true);
    13. canvas()->setAttribute(Qt::WA_PaintOnScreen, true);
    14.  
    15. /* Draw the plot */
    16. // plot setup
    17. plotLayout()->setAlignCanvasToScales(true);
    18. setAxisTitle(QwtPlot::xBottom, "Time [s]");
    19. setAxisScale(QwtPlot::xBottom, _dataInterval->minValue(), _dataInterval->maxValue());
    20. setAxisScale(QwtPlot::yLeft, -720.0, 720.0);
    21.  
    22. // grid setup
    23. _displayGrid = new QwtPlotGrid();
    24. _displayGrid->enableX(true); // major vertical gridlines
    25. _displayGrid->enableXMin(true); // minor vertical gridlines
    26. _displayGrid->enableY(true); // major vertical gridlines
    27. _displayGrid->enableYMin(true); // minor vertical gridlines
    28. _displayGrid->attach(this);
    29.  
    30. // curve and data setup
    31. _dataPoints = new CurveData();
    32. _dataCurve = new QwtPlotCurve();
    33. _dataCurve->setStyle(QwtPlotCurve::Lines);
    34.  
    35. const QColor &c = Qt::black;
    36. _dataCurve->setSymbol(new QwtSymbol(QwtSymbol::XCross,
    37. QBrush(c), QPen(c), QSize(10, 10)) );
    38.  
    39. _dataCurve->setRenderHint(QwtPlotItem::RenderAntialiased, true);
    40. _dataCurve->setPaintAttribute(QwtPlotCurve::ClipPolygons, false);
    41. _dataCurve->attach(this);
    42.  
    43. replot();
    44. }
    45.  
    46. DeviceDisplay::~DeviceDisplay()
    47. {
    48. delete _dataPainter;
    49. }
    50.  
    51. void DeviceDisplay::RefreshDisplay(double xNew, double yNew)
    52. {
    53. /* Redraw the display to incorporate any new points */
    54. _dataPoints->append(&xNew,&yNew,1);
    55.  
    56. _dataCurve->setRawSamples( _dataPoints->x(),
    57. _dataPoints->y(),
    58. _dataPoints->count());
    59.  
    60.  
    61. _dataPainter->drawSeries( _dataCurve,
    62. _dataCurve->dataSize()-1,
    63. _dataCurve->dataSize()-1);
    64.  
    65. }
    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:

    Qt Code:
    1. Diag::Diag(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui(new Ui::Diag)
    4. {
    5. ui->setupUi(this);
    6.  
    7. // add display to the gui
    8. _display = new DeviceDisplay(ui->horizontalLayoutWidget);
    9. ui->horizontalLayout->addWidget(_display);
    10.  
    11. // try plotting something
    12. _display->RefreshDisplay(2,360);
    13. _display->RefreshDisplay(3,260);
    14. _display->RefreshDisplay(4,160);
    15. _display->RefreshDisplay(5,60);
    16. _display->RefreshDisplay(6,130);
    17. _display->RefreshDisplay(7,240);
    18.  
    19. }
    20.  
    21. Diag::~RCNSDiag()
    22. {
    23. delete ui;
    24. }
    To copy to clipboard, switch view to plain text mode 


    Here are the X Server errors if it helps:
    Qt Code:
    1. X Error: BadDrawable (invalid Pixmap or Window parameter) 9
    2. Major opcode: 55 (X_CreateGC)
    3. Resource id: 0x0
    4. X Error: BadDrawable (invalid Pixmap or Window parameter) 9
    5. Major opcode: 55 (X_CreateGC)
    6. Resource id: 0x0
    7. X Error: BadGC (invalid GC parameter) 13
    8. Major opcode: 56 (X_ChangeGC)
    9. Resource id: 0x0
    10. X Error: BadGC (invalid GC parameter) 13
    11. Major opcode: 56 (X_ChangeGC)
    12. Resource id: 0x0
    13. X Error: BadGC (invalid GC parameter) 13
    14. Major opcode: 59 (X_SetClipRectangles)
    15. Resource id: 0x0
    16. X Error: BadGC (invalid GC parameter) 13
    17. Major opcode: 59 (X_SetClipRectangles)
    18. Resource id: 0x0
    19. X Error: BadGC (invalid GC parameter) 13
    20. Major opcode: 59 (X_SetClipRectangles)
    21. Resource id: 0x0
    22. X Error: BadGC (invalid GC parameter) 13
    23. Major opcode: 59 (X_SetClipRectangles)
    24. Resource id: 0x0
    25. X Error: BadGC (invalid GC parameter) 13
    26. Major opcode: 56 (X_ChangeGC)
    27. Resource id: 0x0
    28. X Error: BadDrawable (invalid Pixmap or Window parameter) 9
    29. Major opcode: 69 (X_FillPoly)
    30. Resource id: 0x0
    31. X Error: BadGC (invalid GC parameter) 13
    32. Major opcode: 56 (X_ChangeGC)
    33. Resource id: 0x0
    34. X Error: BadDrawable (invalid Pixmap or Window parameter) 9
    35. Major opcode: 69 (X_FillPoly)
    36. Resource id: 0x0
    37. X Error: BadGC (invalid GC parameter) 13
    38. Major opcode: 56 (X_ChangeGC)
    39. Resource id: 0x0
    40. .... 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

  2. #2
    Join Date
    Oct 2009
    Posts
    33
    Thanks
    2

    Default Re: qwt6, trouble with QwtPlotDirectPainter and simple example

    Hey,

    After a bit more experimentation,

    The line
    Qt Code:
    1. canvas()->setAttribute(Qt::WA_PaintOutsidePaintEvent, true)
    To copy to clipboard, switch view to plain text mode 

    Is responsible for spitting out the X server errors. If I comment it out, the errors go away.

    I still can't figure out what's up with the graph plotting without explicitly calling
    Qt Code:
    1. QwtPlotDirectPainter->drawSeries
    To copy to clipboard, switch view to plain text mode 
    . All I do is call
    Qt Code:
    1. QwtPlotCurve->setRawSamples(...)
    To copy to clipboard, switch view to plain text mode 
    and the data still plots. I've made sure that autoReplot() is false. Could anyone explain this behaviour?

Similar Threads

  1. QMainWindow how to know when focus lost?
    By arkaha in forum Newbie
    Replies: 1
    Last Post: 12th February 2010, 07:26
  2. Focus lost
    By franco.amato in forum Qt Programming
    Replies: 1
    Last Post: 25th January 2010, 23:07
  3. Completely lost!!!
    By Zuks in forum Newbie
    Replies: 4
    Last Post: 2nd December 2009, 10:58
  4. lost signals ?
    By deepinlife in forum Qt Programming
    Replies: 3
    Last Post: 17th June 2008, 11:11
  5. Lost widget
    By anli in forum Qt Programming
    Replies: 6
    Last Post: 29th July 2006, 20:02

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.