QCustomPlot Discussion and Comments

problem with QCPLayerReturn to overview

hi, i want to plot a big and online data. the replot delay increase when plot Advanced in screen. for resolving this problem, i am trying to put each 10 ms data in a separate layer and only replot that layer.
i am trying this:

    QCPLayer *main_layer=new QCPLayer(ui->platform, "ms_0");
    QCPLayer *layer=new QCPLayer(ui->platform, "ms_1");
    layer->setMode(QCPLayer::lmBuffered);
    main_layer->setMode(QCPLayer::lmBuffered);
    ui->platform->addLayer("ms_1",main_layer,QCustomPlot::limAbove) ;
     ....
    ui->platform->setCurrentLayer("ms_0");
    ui->platform->graph(0)->addData(x2_pos,y2[i]);
    ui->platform->layer("ms_0")->replot();
    ....
    ui->platform->setCurrentLayer("ms_1");
    ui->platform->graph(0)->addData(x2_pos,y2[i]);
    ui->platform->layer("ms_1")->replot();

but the program crashes.
what is the problem?

2 things: 1 i dont see you creating the graph(0).
2. the layers dont exactly work that way. you add a graph to a specific layer, not add data to a layer on the same graph.

thanks Ian. your first note is noticed. but before your second notice, a problem existed:

    bool check=ui->platform->addLayer("ms_1",main_layer,QCustomPlot::limAbove) ;

i debug the program and see that the bool Check is false. it means:
http://www.qcustomplot.com/documentation/classQCustomPlot.html#ad5255393df078448bb6ac83fa5db5f52
i cant solve this and i cant find any good example of layering.

i forget to say that my program crashes when in line 13(replot). debugger stops at this line of qcustomplot.cpp:

  if (mMode == lmBuffered && !mParentPlot->hasInvalidatedPaintBuffers()){
...

As the documentation of QCPLayer says
http://www.qcustomplot.com/documentation/classQCPLayer.html#a5d0657fc86d624e5efbe930ef21af718
you must not create layers directly in this way.

You should use the correct interface of QCustomPlot::addLayer

Here's the full description how layers work:
http://www.qcustomplot.com/documentation/classQCPLayer.html#details

thanks Isso. the second link is very very helpful and illuminator. i change my test code in this way:

    QCPLayer *secon_layer=new QCPLayer(ui->platform, "ms_1");
    second_layer->setMode(QCPLayer::lmBuffered);
    bool mq1=ui->platform->addLayer("ms_1",0,QCustomPlot::limAbove) ;
   
    ui->platform->setCurrentLayer("main");
    ui->platform->graph(0)->addData(x2_pos_scope_ch1[0],y2[0]);
    ui->platform->graph(0)->addData(x2_pos_scope_ch1[1],y2[1]);
    ui->platform->setCurrentLayer("ms_1");
    double a1=0; double  b1=-10;
     ui->platform->graph(0)->addData(a1,b1);
     a1=1;b1=10;
     ui->platform->graph(0)->addData(a1,b1);
     ui->platform->layer("ms_1")->replot();

Due to the second Doc the code set "ms_1" above the other layers. it created successfully(mq1 is true) . with replot the lmBuffered layer (ms_1) only this layer should be replotted. but all of data is plot. why?
NOTE: is line 5 true? it should set the current layer to default main layer.

again, like i pointed out earlier, data isnt added to a specific layer... it is added to the graph. you set the current layer after creating the graph.

your code simplified is as follows:
create graph 0
create a second layer
add data to graph 0
add data to graph 0
add data to graph 0
add data to graph 0
replot layer ms_1.

the problem with this is that you have no data on layer ms_1... your only data is on the main layer, because that's the layer you created graph(0) on. you cant have data points from a graph on two separate layers, that's not how it works.

thanks, that's work. only pay attention that it should be replot platform once after creating graphs on different layers. otherwise it does not work.