qcustomplot - Add a slide in Qt that moves a signal up and down the y axis -


i have 3 real time signals on same graph, overlap , need slide button move them , down y axis see them better. how can connect slide graph? when value of slide changes, datas of signal added on graph real_y_values+slide_value? mainwindow.cpp:

mainwindow::mainwindow(qserialport* s,qwidget *parent) : qmainwindow(parent), ui(new ui::mainwindow), reader(s) {   ui->setupui(this);   connect(ui->verticalslider,signal(valuechanged(int)),ui->customplot,slot(deplasare()));    setgeometry(400, 250, 542, 390);   grafic(ui->customplot);   setwindowtitle("real time data graph eda ");   statusbar()->clearmessage();   ui->customplot->replot();  }  void mainwindow::grafic(qcustomplot *customplot) {  graph_name = "real time data graph eda";  customplot->addgraph(); // blue line  customplot->graph(0)->setpen(qpen(qt::blue));  customplot->addgraph();  customplot->graph(1)->setpen(qpen(qt::blue));   customplot->addgraph(); // red line  customplot->graph(2)->setpen(qpen(qt::red));  customplot->addgraph();  customplot->graph(3)->setpen(qpen(qt::red));   customplot->addgraph(); // green line  customplot->graph(4)->setpen(qpen(qt::green));   customplot->axisrect()->setupfullaxesbox();   connect(&datatimer, signal(timeout()), this, slot(realtimedataslot()));  datatimer.start(100); // interval 0 means refresh fast possible  }   void mainwindow::realtimedataslot()  {  timecounter+=10; qbytearray data1; data1=reader._read_callback(); int sz = data1.size(); int value0; int value2=800; int ssz=0; for(int ii=0;ii<sz;ii++)    if((int)data1[ii] != 13 && (int)data1[ii] != 10)     {         value0=(int)data1[ii];         ssz++;         //fct add graph          ui->customplot->graph(0)->adddata(timecounter, value0);          buf.push(value0);          ui->customplot->graph(2)->adddata(timecounter, buf.get_scl());          cout<<value0<<"   "<<buf.get_scl()<<endl;      }     if(timecounter>=800)  {       timecounter = 0;        ui->customplot->graph(1)->cleardata();       ui->customplot->graph(1)->adddata(*(ui->customplot->graph(0)->data()));       ui->customplot->graph(0)->cleardata();        ui->customplot->graph(3)->cleardata();       ui->customplot->graph(3)->adddata(*(ui->customplot->graph(2)->data()));       ui->customplot->graph(2)->cleardata();  }   else {       ui->customplot->graph(4)->adddata(timecounter, value2);      ui->customplot->xaxis->setrange(0,800);     ui->customplot->yaxis->setrange(-300, 1024);   }     ui->customplot->graph(1)->removedata(timecounter, timecounter+50);     ui->customplot->graph(3)->removedata(timecounter, timecounter+50);      ui->customplot->replot();  }     void mainwindow::deplasare()      {         }      mainwindow::~mainwindow(){        delete ui;      } 

i made slot in mainwindow: void mainwindow::deplasare() in order connect slide signal, can't figure out content of function.

first, take @ this in order understand how work qslider.
there should understand need change connect be:

connect(ui->verticalslider,signal(valuechanged(int)),this,slot(deplasare(int))); 

now if want make kind of offset 1 of graphs have add offset data points , replot. here example doing on ui->customplot->graph(0):

void mainwindow::deplasare(int offset){     qcpdatamap *datamap = ui->customplot->graph(0)->data();     (qmap<double,qcpdata>::iterator = datamap->begin(); != datamap->end(); ++it){         it.value().value += offset;     }     ui->customplot->replot(); } 

some explanation see above:
since qcpgraph data hold in qcpdatamap qmap<double,qcpdata>. in order add offset every data point in graph iterate on qmap , adding offset every qcpdata::value.


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -