Results 1 to 18 of 18

Thread: How to draw a cruve with increasing data?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2009
    Posts
    14
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Question How to draw a cruve with increasing data?

    Hi everyone. I have a problem of how to draw a cruve with growing data. In my application, i need to draw a curve which data is collected from AD channel. I found the "realtime_plot" example, it used the draw(from,to) method. So i use this code for reference. But in my code, it doesn't work. My code like this:
    d_data->append(x, y, size);
    d_curve->setRawData(d_data->x(), d_data->y(), d_data->count());
    canvas()->setPaintAttribute(QwtPlotCanvas::PaintCached, false);
    d_curve->draw(d_curve->dataSize() - size, d_curve->dataSize() - 1);

    used above code, the cruve desn't show, but used replot() method, the curve can display:
    d_data->append(x, y, size);
    d_curve->setRawData(d_data->x(), d_data->y(), d_data->count());
    canvas()->setPaintAttribute(QwtPlotCanvas::PaintCached, false);
    replot();

    so i want to ask , how to used draw(from,to) method? And i want to draw a curve as quickly as it can. QPaintEngine::PaintOutsidePaintEvent feathure is needed, but it is not supported by qt4, and how i can realize?

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,312
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to draw a cruve with increasing data?

    1) Which platform are you on ?
    2) Does the realtime example work ?

    Uwe

  3. #3
    Join Date
    Sep 2009
    Posts
    14
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: How to draw a cruve with increasing data?

    Quote Originally Posted by Uwe View Post
    1) Which platform are you on ?
    2) Does the realtime example work ?

    Uwe
    I use linux-2.6.13 kernel on arm9 board. Qt version is qt-core-4.3.2, and qwt is 5.20
    the realtime example can work, it can show a series points, but i want to display a curve not just points, so i edit this code and and debug it, the original code is
    if ( d_curve == NULL )
    {
    d_curve = new QwtPlotCurve("Test Curve");
    d_curve->setStyle(QwtPlotCurve::NoCurve);
    d_curve->setPaintAttribute(QwtPlotCurve::PaintFiltered);

    const QColor &c = Qt::white;
    d_curve->setSymbol(QwtSymbol(QwtSymbol::XCross,
    QBrush(c), QPen(c), QSize(5, 5)) );

    d_curve->attach(this);
    }

    and i delete "d_curve->setStyle(QwtPlotCurve::NoCurve)" and "d_curve->setSymbol(QwtSymbol(QwtSymbol::XCross, QBrush(c), QPen(c), QSize(5, 5)) )";
    it can't show any points, but when i left-click the mouse in the screen , it can show the curve. other more, when i just delete "d_curve->setStyle(QwtPlotCurve::NoCurve)" sentence, it can show points but no curve and when i left-click the mouse in the screen , the cruve is also showed.
    But in my code, no matter what i do , it can not show anything.

  4. #4
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,312
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to draw a cruve with increasing data?

    Quote Originally Posted by anson97209 View Post
    I use linux-2.6.13 kernel on arm9 board. Qt version is qt-core-4.3.2, and qwt is 5.20
    Qt has been renamed so often - I can't remember if qt-core was Qt Embedded or Qt X11. This is important as on X11 you can paint outside of paint events - while on Qt embedded ( and all platforms with the raster paint engine like Windows ) QwtPlotCurve::draw is implemented using internal dummy paint events.

    Also Qt 4.3 is pretty old - better upgrade if possible.
    the realtime example can work,...
    Then check all the flags that are temporarily enabled in IncrementalPlot::appendData.

    You could also have a look at the new spectrogram example in Qwt SVN trunk. Maybe this is closer to your use case ( but I'm not sure if it works with Qt 4.3 ).

    Uwe

  5. #5
    Join Date
    Sep 2009
    Posts
    14
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: How to draw a cruve with increasing data?

    Quote Originally Posted by Uwe View Post
    Qt has been renamed so often - I can't remember if qt-core was Qt Embedded or Qt X11. This is important as on X11 you can paint outside of paint events - while on Qt embedded ( and all platforms with the raster paint engine like Windows ) QwtPlotCurve::draw is implemented using internal dummy paint events.

    Also Qt 4.3 is pretty old - better upgrade if possible.

    Then check all the flags that are temporarily enabled in IncrementalPlot::appendData.

    You could also have a look at the new spectrogram example in Qwt SVN trunk. Maybe this is closer to your use case ( but I'm not sure if it works with Qt 4.3 ).

    Uwe
    Thank you for your answer, and i find something has change of the realtime plot example of the latest version of qwt. Maybe I should try to debug again to find a suitable way to solve the problem.

  6. #6
    Join Date
    Sep 2009
    Posts
    14
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: How to draw a cruve with increasing data?

    In the Incrememtalplot.cpp , the orginal code is this:
    void IncrementalPlot::appendData(double *x, double *y, int size)
    {
    if ( d_data == NULL )
    d_data = new CurveData;

    if ( d_curve == NULL )
    {
    d_curve = new QwtPlotCurve("Test Curve");
    d_curve->setStyle(QwtPlotCurve::NoCurve);
    d_curve->setPaintAttribute(QwtPlotCurve::PaintFiltered);

    const QColor &c = Qt::white;
    d_curve->setSymbol(QwtSymbol(QwtSymbol::XCross,
    QBrush(c), QPen(c), QSize(5, 5)) );

    d_curve->attach(this);
    }

    d_data->append(x, y, size);
    d_curve->setRawData(d_data->x(), d_data->y(), d_data->count());
    #ifdef __GNUC__
    #endif

    const bool cacheMode =
    canvas()->testPaintAttribute(QwtPlotCanvas::PaintCached);

    #if QT_VERSION >= 0x040000 && defined(Q_WS_X11)
    // Even if not recommended by TrollTech, Qt::WA_PaintOutsidePaintEvent
    // works on X11. This has an tremendous effect on the performance..

    canvas()->setAttribute(Qt::WA_PaintOutsidePaintEvent, true);
    #endif

    canvas()->setPaintAttribute(QwtPlotCanvas::PaintCached, false);
    d_curve->draw(d_curve->dataSize() - size, d_curve->dataSize() - 1);
    canvas()->setPaintAttribute(QwtPlotCanvas::PaintCached, cacheMode);

    #if QT_VERSION >= 0x040000 && defined(Q_WS_X11)
    canvas()->setAttribute(Qt::WA_PaintOutsidePaintEvent, false);
    #endif
    }

    and I delete all the flag, and the code like this:

    void IncrementalPlot::appendData(double *x, double *y, int size)
    {
    if ( d_data == NULL )
    d_data = new CurveData;

    if ( d_curve == NULL )
    {
    d_curve = new QwtPlotCurve("Test Curve");
    d_curve->setStyle(QwtPlotCurve::NoCurve);
    d_curve->setPaintAttribute(QwtPlotCurve::PaintFiltered);

    const QColor &c = Qt::white;
    d_curve->setSymbol(QwtSymbol(QwtSymbol::XCross,
    QBrush(c), QPen(c), QSize(5, 5)) );

    d_curve->attach(this);
    }

    d_data->append(x, y, size);
    d_curve->setRawData(d_data->x(), d_data->y(), d_data->count());

    canvas()->setPaintAttribute(QwtPlotCanvas::PaintCached, false);
    d_curve->draw(d_curve->dataSize() - size, d_curve->dataSize() - 1);
    canvas()->setPaintAttribute(QwtPlotCanvas::PaintCached, cacheMode);

    }
    the example also can work. But in my own code , it cannot show anything except using the replot() method. I guess other files (such as Randomplot.cpp) impacted the plot?

  7. #7
    Join Date
    Sep 2009
    Posts
    14
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: How to draw a cruve with increasing data?

    I have find the problem. when I add zoomer class in my code, use draw() method can work. But I have another two problems:
    1 the points can display in the realtime, but the curve can not display unless I left-clicked the mouse in the canvas.
    2 when I enble the Qt::WA_PaintOutsidePaintEvent and disable QwtPlotCanvas::PaintCached, it can plot very fast, but it will print the debug information
    "QWidget:aintEngine:should no nolonger be called"
    "QPainter:begin:Paint device returned engine == 0, type:1"
    "QPainter::setClipping:Painter not active, state will be reset by begin"
    "QPainter::save:Painter not active"
    "QPainter::store:Unbalanced save/restore"

  8. #8
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,312
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to draw a cruve with increasing data?

    Qwt 5.2.0 doesn't call any QWidget::paintEngine() anymore. If you are really using it try to find out, where QWidget::paintEngine() is called ( f.e setting a breakpoint in qWarning() ).

    Uwe

  9. #9
    Join Date
    Sep 2009
    Posts
    14
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: How to draw a cruve with increasing data?

    Thank you!
    I want to ask the frist question, why the points can display in the realtime, but the curve can't.

  10. #10
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,312
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to draw a cruve with increasing data?

    If you want to see connecting lines between the points you need to pass the start and endpoint for these lines - not only a single point. So if you want to paint point by point you always have to add the previous point to QwtPlotCurve::draw().

    Uwe

  11. #11
    Join Date
    Sep 2009
    Posts
    14
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: How to draw a cruve with increasing data?

    Uwe, Thank you very much, you really help me a lot!
    Follow you tips, I just changed the code like that
    d_curve->draw(d_curve->dataSize() - 2, d_curve->dataSize() - 1);
    and the curve can display in the realtime.
    But it must disable Qt::WA_PaintOutsidePaintEvent. As a result, it plot very slowly, Can i have a method to let it plot faster ?

Similar Threads

  1. data rate transfer is decreasing in TCP connection
    By navi1084 in forum Qt Programming
    Replies: 3
    Last Post: 19th June 2009, 16:15
  2. Draw New data, without erasing old ones
    By linuxdev in forum Newbie
    Replies: 11
    Last Post: 7th January 2009, 08:34
  3. Best way to display lots of data fast
    By New2QT in forum Newbie
    Replies: 4
    Last Post: 16th October 2008, 22:46
  4. Replies: 4
    Last Post: 19th October 2007, 19:47
  5. speed of setdata - lots of items in treeview
    By Big Duck in forum Qt Programming
    Replies: 4
    Last Post: 6th July 2006, 12:53

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.