2016-06-11 17 views
1

동일한 그래프에는 세 개의 실시간 신호가 있지만 때때로 겹치기도하고 y 축을 위아래로 움직이려면 슬라이드 단추가 필요합니다. 그 (것)들 잘. 슬라이드에 그래프를 연결하려면 어떻게해야합니까? 슬라이드 값이 변경 될 때와 마찬가지로 신호의 데이터가 real_y_values ​​+ slide_value의 그래프에 추가됩니까?신호를 y 축으로 위아래로 이동시키는 Qt의 슬라이드 추가

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 for EDA "); 
    statusBar()->clearMessage(); 
    ui->customPlot->replot(); 

} 

void MainWindow::grafic(QCustomPlot *customPlot) 
{ 
Graph_Name = "Real Time Data Graph for 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 to refresh as fast as 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; 
    } 

내가 MainWindow를 슬롯에했다 : 이것은 mainwindow.cpp void MainWindow::deplasare() 인 신호와 상기 슬라이드에 연결하기 위해,하지만,이 기능의 내용을 파악할 수 없다.

답변

0

우선 QSlider로 작업하는 방법을 이해하려면 this을 살펴보십시오. 거기에서
당신이 할 당신의 connect을 변경해야하는 것을 이해한다 : 당신이 당신의 그래프 중 하나에 오프셋의 어떤 종류를 확인하려는 경우 추가해야합니다

connect(ui->verticalSlider,SIGNAL(valueChanged(int)),this,SLOT(deplasare(int))); 

을 지금 이것은 모든 데이터 포인트 오프셋 (offset) 그리고 replot. 여기 ui->customPlot->graph(0)에 작업을 수행하는 예는 다음과 같습니다

void MainWindow::deplasare(int offset){ 
    QCPDataMap *dataMap = ui->customPlot->graph(0)->data(); 
    for (QMap<double,QCPData>::iterator it = dataMap->begin(); it != dataMap->end(); ++it){ 
     it.value().value += offset; 
    } 
    ui->customPlot->replot(); 
} 

우리가 위에서 무엇을보고에 대한 몇 가지 설명 :
데이터 QCPGraph 때문에 것은 실제로 QMap<double,QCPData>입니다 QCPDataMap에서 개최한다. 그래프의 모든 데이터 포인트에 offset을 추가하려면 QMap을 반복하고 QCPData::valueoffset을 추가하십시오.

+0

감사합니다. 한 가지를 제외하고는 잘 작동합니다. 그 다음 데이터는 이전 값으로 그려져 있습니다. – Ana

+0

그런 다음 새 포인트를 추가 할 때도 트랙을 유지해야합니다. 'offset'을 클래스의 멤버로 유지하고'deplasare'가 호출 될 때마다 새로운 값으로 업데이트하십시오. 그리고 새로운 값을 추가 할 때'value + offset'을 붙이면됩니다. –