Hello, I'm new in this site, and I am not an expert programmer so, any help will be great for me

I am creating a GUI, where in one graph, 6 signals are plotted, and in another graph, 6 other signals. example.png

So these signals come from a serial port, and I need to graph them in real time and send them in real time.
For now, I worry about the plotting part

What I thought at first, was replot every time a new sample arrived, but I think this would be inefficient and I do not know if having 12 signals with approximately 2500 samples each, finish making the program slow.

I was reading here, and found similar questions, I read the oscilloscope and real_time examples, but some parts do not become very clear to me.

Probably you are already tired of responding to them, but I really still have doubts.

I understand that:

- I need to use a QVector for append new sample.
- I need to set this samples to a QwtPlotCurve.
- I need to use QwtPlotDirectPainter::drawSeries for draw only the las sample.

Also need to use a QRect, but I dont understand well how this work.

In the real_time example, I think the most important art is at incrementalplot.cpp rigth?

but in the MainWindow.cpp file, never create and object of this class, only a randomplot object. I see that randomplot use the incrementalplot class and the method appendPoint (I think this is what I need), but I do not see the order in which the instructions are executed.

In the oscilloscope example, something similar is used at plot.cpp specifically Plot::updateCurve().

this, use a CurveData, that use a signaldata for append samples i think. (I think use a QVector for this rigth?).
and after, the same of real_time: QwtScaleMap, QRect and QwtPlotDirectPainter::drawSeries. but this differs in that it verifies if it can write in the array before doing it, and if it is not possible, it saves in a buffer. Is this correct? I was never use QReadWriteLock so i dont know how it work.

I have the same doubts as in the other example, I do not see the order in which the instructions are executed.

But the principal question is how can I use the QwtPlotDirectPainter::drawSeries, why need to use a canvasMap and how use the QRect.

Maybe are so many questions and maybe are trivials but, for me is a little difficult to understand.

Any help will be greatly appreciated!

I try with little examples using a qwtplot and 1 button, When I press the button, a new sample should be added:

Qt Code:
  1. MainWindow::MainWindow(QWidget *parent) :
  2. QMainWindow(parent),
  3. ui(new Ui::MainWindow)
  4. {
  5. ui->setupUi(this);
  6. i=0; c = 0;
  7. ya = false;
  8. graf = new QwtPlotCurve("");
  9. graf->attach(ui->qwtPlot);
  10. d_directPainter = new QwtPlotDirectPainter();
  11.  
  12. }
  13.  
  14. void MainWindow::on_pushButton_clicked()
  15. {
  16. QPointF point = QPointF(c++,i);
  17. dat.append(point);
  18. graf->setSamples(dat);
  19.  
  20. xMap = ui->qwtPlot->canvasMap( graf->xAxis() );
  21. yMap = ui->qwtPlot->canvasMap( graf->yAxis() );
  22.  
  23. const QPointF center =
  24. QwtScaleMap::transform( xMap, yMap, point );
  25. r.moveCenter( center.toPoint() );
  26. clipRect += r;
  27.  
  28. d_directPainter->setClipRegion( clipRect );
  29.  
  30. d_directPainter->drawSeries( graf, dat.size() - 2, dat.size() - 1 );
  31.  
  32. if(!ya) {i++; if(i==10)ya=true;}
  33. else {i--; if(i==0)ya=false;}
  34. }
To copy to clipboard, switch view to plain text mode 

but this dont work. and try also:

Qt Code:
  1. void MainWindow::on_pushButton_clicked()
  2. {
  3. QPointF point = QPointF(c++,i);
  4. dat.append(point);
  5. graf->setSamples(dat);
  6.  
  7. xMap = ui->qwtPlot->canvasMap( graf->xAxis() );
  8. yMap = ui->qwtPlot->canvasMap( graf->yAxis() );
  9.  
  10. const QSize symbolSize = graf->symbol()->size();
  11. QRect r( 0, 0, symbolSize.width() + 2, symbolSize.height() + 2 );
  12.  
  13. clipRect = QwtScaleMap::transform( xMap, yMap, br ).toRect();
  14. d_directPainter->setClipRegion( clipRect );
  15.  
  16. d_directPainter->drawSeries( graf, dat.size() - 2, dat.size() - 1 );
  17.  
  18. if(!ya) {i++; if(i==10)ya=true;}
  19. else {i--; if(i==0)ya=false;}
  20. }
To copy to clipboard, switch view to plain text mode 

But doesn't work either.

Only with replot work for me

Qt Code:
  1. QPointF point = QPointF(c++,i);
  2. dat.append(point);
  3. graf->setSamples(dat);
  4.  
  5. datos << QPointF(c++,i);
  6. graf->setSamples(datos);
  7. if(!ya) {i++; if(i==10)ya=true;}
  8. else {i--; if(i==0)ya=false;}
  9.  
  10. ui->qwtPlot->replot();
To copy to clipboard, switch view to plain text mode 

Thanks in advance, I hope someone can help me

Here an image of how my interface is going, any comments or suggestions are also welcome

gui.jpg