2016-06-11 8 views
1

同じグラフに3つのリアルタイム信号がありますが、重なり合うことがありますが、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.cppあるvoid MainWindow::deplasare()信号にスライドを接続するために、私は、この関数の内容を把握することはできません。

答えて

0

まず、QSliderの使い方を理解するために、thisを参照してください。あなたがあることをごconnectを変更する必要があることを理解すべきである。そこから

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

あなたのグラフのいずれかにオフセットのいくつかの種類を作成したい場合は今、あなたはこれを追加する必要がありますすべてのデータポイントへのオフセット再配置する。ここにあなたの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

ありがとうございます.1つのことを除いてうまくいきます:次のデータは古い値でプロットされています – Ana

+0

新しいポイントを追加するときにもトラックを保持する必要があります。あなたのクラスのメンバとして 'offset'を保持し、' deplasare'が呼び出されるたびに新しい値で更新してください。新しい値を追加するときには、 'value + offset'を付け加えてください。 –

関連する問題