Results 1 to 4 of 4

Thread: Drawing QwtPlotCurve without deleting old data

  1. #1
    Join Date
    Nov 2011
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Drawing QwtPlotCurve without deleting old data

    Hello,
    I am trying to plot (realtime) some lines for some sensor data without removing the older lines on the QwtPlot object from the past.

    Qt Code:
    1. m_Gui.guiQwtPlot->setTitle(title);
    2. m_Gui.guiQwtPlot->setCanvasBackground(* new QBrush(Qt::black));
    3. m_Gui.guiQwtPlot->setAxisScale(QwtPlot::yLeft, -30.0, 30.0);
    4. m_Gui.guiQwtPlot->insertLegend(new QwtLegend());
    5. m_Gui.guiQwtPlot->legend()->setFont(fontNormal);
    6. m_Gui.guiQwtPlot->setFont(fontNormal);
    7. m_Gui.guiQwtPlot->setAxisFont(QwtPlot::yLeft, fontNormal);
    8. m_Gui.guiQwtPlot->setAxisFont(QwtPlot::xBottom, fontNormal);
    9. m_Gui.guiQwtPlot->setAxisScaleDraw(QwtPlot::xBottom, new TimeScaleDraw(QTime::currentTime()));
    10. m_Gui.guiQwtPlot->setAxisLabelRotation(QwtPlot::xBottom, 0.0);
    11. m_Gui.guiQwtPlot->setAxisLabelAlignment(QwtPlot::xBottom,Qt::AlignLeft|Qt::AlignBottom);
    12. m_Gui.guiQwtPlot->setAxisTitle(QwtPlot::xBottom, axisTitleBottom);
    13. m_Gui.guiQwtPlot->setAxisTitle(QwtPlot::yLeft, axisTitleLeft);
    14.  
    15. QwtPlotMagnifier *plotM= new QwtPlotMagnifier(m_Gui.guiQwtPlot->canvas());
    16. plotM->setMouseButton(Qt::NoButton);
    17.  
    18. QwtPlotPanner *plotP= new QwtPlotPanner(m_Gui.guiQwtPlot->canvas());
    To copy to clipboard, switch view to plain text mode 

    In every 5 seconds I get new data from sensors and for each sensor I create a QwtPlotCurve then update my sensor-data with setSamples(points)

    Qt Code:
    1. void pcaPlotting::updateDataSlot(QString sensorId, QPolygonF points)
    2. {
    3. QMap<QString, QwtPlotCurve*> m_PlotC;
    4. QStringList m_SensorNameList
    5.  
    6. for(unsigned int i= 0; i< m_SensorNameList.count(); ++i)
    7. {
    8. m_PlotC[m_SensorNameList.at(i)]= new QwtPlotCurve();
    9. m_PlotC[m_SensorNameList.at(i)]->setRenderHint(QwtPlotItem::RenderAntialiased, true);
    10. m_PlotC[m_SensorNameList.at(i)]->setCurveAttribute(QwtPlotCurve::Fitted);
    11. }
    12. m_PlotC[sensorId]->setSamples(points);
    13.  
    14. emit updatePlotSignal(m_PlotC);
    15. }
    To copy to clipboard, switch view to plain text mode 

    Finally I update my plot over signal/slot

    Qt Code:
    1. void mainGui::updatePlotSlot(QMap<QString, QwtPlotCurve*> plotC)
    2. {
    3. for(QMap<QString, QwtPlotCurve*>::iterator it= plotC.begin(); it!= plotC.end(); ++it)
    4. {
    5. plotC[it.key()]->attach(m_Gui.guiQwtPlot);
    6. m_Gui.guiQwtPlot->replot();
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 

    My problem is: it plots only the data, those I got in 5 sec and then the lines are replaced with the new data after 5 sec. What should I do, so that the lines will not be replaced and increased until I stop drawing?
    May be second question: The drawn data is not centered to the QwtPlot-window, it overflows in +y-axis, if the data is higher then the set boundaries setAxisScale(QwtPlot::yLeft, -30.0, 30.0); How can I draw in the center of y-axis, so that the size of the QwtPlot does not matter.

    Thank you

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

    Default Re: Drawing QwtPlotCurve without deleting old data

    Quote Originally Posted by nasil122002 View Post
    What should I do, so that the lines will not be replaced and increased until I stop drawing?
    Have a look at QwtPlotDirectPainter.
    The realtime example shows how to use it. The oscilloscope is probably much closer to your use case, but the source code requires some time to understand how it works.
    Quote Originally Posted by nasil122002 View Post
    How can I draw in the center of y-axis, so that the size of the QwtPlot does not matter.
    Not sure if I understand this one.

    Uwe

  3. #3
    Join Date
    Nov 2011
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Drawing QwtPlotCurve without deleting old data

    Quote Originally Posted by Uwe View Post
    Not sure if I understand this one.
    Uwe
    Sorry for bad explanation. I found the solution by changing the yLeft- Axis scale from setAxisScale(QwtPlot::yLeft, -30.0, 30.0); to setAxisScale(QwtPlot::yLeft, -200.0, 200.0); Now the lines are aligned correctly
    Last edited by nasil122002; 24th November 2017 at 16:10.

  4. #4
    Join Date
    Nov 2011
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Drawing QwtPlotCurve without deleting old data

    Ok I have adapted my code above to the QwtPlotDirectPainter real-time example.

    By the initialization of QwtPlot I added additionally canvas()->setAttribute() and setAutoReplot() functions:

    Qt Code:
    1. void guiMain::createPlot(QStringList m_SensorNameList)
    2.  
    3. m_Gui.guiQwtPlot->setTitle(title);
    4. m_Gui.guiQwtPlot->setCanvasBackground(* new QBrush(Qt::black));
    5. m_Gui.guiQwtPlot->setAxisScale(QwtPlot::yLeft, -30.0, 30.0);
    6. m_Gui.guiQwtPlot->insertLegend(new QwtLegend());
    7. m_Gui.guiQwtPlot->legend()->setFont(fontNormal);
    8. m_Gui.guiQwtPlot->setFont(fontNormal);
    9. m_Gui.guiQwtPlot->setAxisFont(QwtPlot::yLeft, fontNormal);
    10. m_Gui.guiQwtPlot->setAxisFont(QwtPlot::xBottom, fontNormal);
    11. m_Gui.guiQwtPlot->setAxisScaleDraw(QwtPlot::xBottom, new TimeScaleDraw(QTime::currentTime()));
    12. m_Gui.guiQwtPlot->setAxisLabelRotation(QwtPlot::xBottom, 0.0);
    13. m_Gui.guiQwtPlot->setAxisLabelAlignment(QwtPlot::xBottom,Qt::AlignLeft|Qt::AlignBottom);
    14. m_Gui.guiQwtPlot->setAxisTitle(QwtPlot::xBottom, axisTitleBottom);
    15. m_Gui.guiQwtPlot->setAxisTitle(QwtPlot::yLeft, axisTitleLeft);
    16. m_Gui.guiQwtPlot->canvas()->setAttribute(Qt::WA_PaintOutsidePaintEvent, true);
    17. m_Gui.guiQwtPlot->setAutoReplot(false);
    18.  
    19. QwtPlotMagnifier *plotM= new QwtPlotMagnifier(m_Gui.guiQwtPlot->canvas());
    20. plotM->setMouseButton(Qt::NoButton);
    21.  
    22. QwtPlotPanner *plotP= new QwtPlotPanner(m_Gui.guiQwtPlot->canvas());
    To copy to clipboard, switch view to plain text mode 

    The initialization of QwtPlotCurve: For my each sensor, I create QwtPlotCurve, QwtPlotDirectPainter and add curveData to the QwtPlotCurve

    Qt Code:
    1. void plotting::createPlotCurve(QStringList m_SensorNameList)
    2. {
    3. QMap<QString, QwtPlotCurve*> m_PlotC;
    4. QMap<QString, QwtPlotDirectPainter*> m_DirectPainter;
    5.  
    6. if(!m_SensorNameList.isEmpty())
    7. {
    8. for(unsigned int i= 0; i< m_SensorNameList.count(); ++i)
    9. {
    10. m_PlotC[m_SensorNameList.at(i)]= new QwtPlotCurve();
    11. m_PlotC[m_SensorNameList.at(i)]->setPen(QPen(QColor(m_ColorList[i]), 1, Qt::SolidLine));
    12. m_PlotC[m_SensorNameList.at(i)]->setRenderHint(QwtPlotItem::RenderAntialiased, true);
    13. m_PlotC[m_SensorNameList.at(i)]->setCurveAttribute(QwtPlotCurve::Fitted);
    14.  
    15. m_DirectPainter[m_SensorNameList.at(i)]= new QwtPlotDirectPainter();
    16. m_PlotC[m_SensorNameList.at(i)]->setData(new curveData());
    17. }
    18. }
    19. }
    To copy to clipboard, switch view to plain text mode 

    After each 5 seconds, I get new data from sensors and for each sensor I append the QPolygonF points:

    Qt Code:
    1. void plotting::updateDataSlot(QString sensorId, QPolygonF points)
    2. {
    3. curveData *data= static_cast<curveData *>(m_PlotC[sensorId]->data());
    4. data->clear();
    5.  
    6. if(m_SensorNameList.contains(sensorId))
    7. {
    8. //m_PlotC[sensorId]->setSamples(points);
    9.  
    10. //curveData *data= static_cast<curveData *>(m_PlotC[sensorId]->data());
    11. data->append(points);
    12. m_DirectPainter[sensorId]->drawSeries(m_PlotC[sensorId], data->size()-100, data->size()-1);
    13.  
    14. emit updatePlotSignal(m_PlotC);
    15. }
    16. }
    To copy to clipboard, switch view to plain text mode 

    update plot:

    Qt Code:
    1. void guiMain::updatePlotSlot(QMap<QString, QwtPlotCurve*> plotC)
    2. {
    3. m_Gui.guiQwtPlot->repaint();
    4.  
    5. for(QMap<QString, QwtPlotCurve*>::iterator it= plotC.begin(); it!= plotC.end(); ++it)
    6. {
    7. plotC[it.key()]->attach(m_Gui.guiQwtPlot);
    8. m_Gui.guiQwtPlot->replot();
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 


    In curveData class I use QPolygonF insteat of QPointF in append function:

    Qt Code:
    1. class curveData: public QwtArraySeriesData<QPointF>
    2. {
    3. public:
    4. ...
    5. inline void append(const QPolygonF &point)
    6. {
    7. d_samples+= point;
    8. }
    9. ...
    10. };
    To copy to clipboard, switch view to plain text mode 

    But somehow ,there is no difference with the previous plot. The lines are not appended and deleted from the scene after 5 sec. each time. If I comment out the m_Gui.guiQwtPlot->repaint(); then the lines are not cleared from the current plot but overlapped.
    Last edited by nasil122002; 27th November 2017 at 18:31.

Similar Threads

  1. Replies: 0
    Last Post: 1st April 2016, 13:17
  2. Replies: 4
    Last Post: 16th January 2010, 11:08
  3. limits for drawing a QwtPlotCurve
    By rambo83 in forum Qwt
    Replies: 1
    Last Post: 1st December 2009, 11:02
  4. Replies: 2
    Last Post: 18th December 2008, 08:43
  5. help using QLists as data in QwtPlotCurve
    By esorensen in forum Qwt
    Replies: 1
    Last Post: 11th July 2008, 20:52

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.