can update plot
This commit is contained in:
parent
19a637f366
commit
42a4a5f0b0
|
@ -8,9 +8,9 @@
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
|
#include <QRandomGenerator>
|
||||||
|
|
||||||
#include <QChartView>
|
#include <QChartView>
|
||||||
#include <QLineSeries>
|
|
||||||
#include <QValueAxis>
|
#include <QValueAxis>
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
@ -30,7 +30,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){
|
||||||
digiSetting = NULL;
|
digiSetting = NULL;
|
||||||
readDataThread = NULL;
|
readDataThread = NULL;
|
||||||
|
|
||||||
plot = new QChart();
|
SetUpPlot();
|
||||||
|
|
||||||
QWidget * mainLayoutWidget = new QWidget(this);
|
QWidget * mainLayoutWidget = new QWidget(this);
|
||||||
setCentralWidget(mainLayoutWidget);
|
setCentralWidget(mainLayoutWidget);
|
||||||
|
@ -183,7 +183,8 @@ MainWindow::~MainWindow(){
|
||||||
//delete bnNewExp;
|
//delete bnNewExp;
|
||||||
//delete logInfo;
|
//delete logInfo;
|
||||||
|
|
||||||
if( plot != NULL )delete plot;
|
delete dataTrace; /// dataTrace must be deleted before plot
|
||||||
|
delete plot;
|
||||||
|
|
||||||
//---- need manually delete
|
//---- need manually delete
|
||||||
if( digiSetting != NULL ) delete digiSetting;
|
if( digiSetting != NULL ) delete digiSetting;
|
||||||
|
@ -328,36 +329,41 @@ void MainWindow::OpenScope(){
|
||||||
QGridLayout * layout = new QGridLayout(layoutWidget);
|
QGridLayout * layout = new QGridLayout(layoutWidget);
|
||||||
layoutWidget->setLayout(layout);
|
layoutWidget->setLayout(layout);
|
||||||
|
|
||||||
|
|
||||||
plot->removeAllSeries();
|
|
||||||
|
|
||||||
QLineSeries * data = new QLineSeries(this);
|
|
||||||
data->setName("data");
|
|
||||||
|
|
||||||
//--------- add data
|
|
||||||
data->append(1, 2);
|
|
||||||
data->append(2, 2);
|
|
||||||
data->append(3, 5);
|
|
||||||
data->append(4, 2);
|
|
||||||
|
|
||||||
plot->addSeries(data);
|
|
||||||
|
|
||||||
|
|
||||||
plot->createDefaultAxes(); /// this must be after addSeries();
|
|
||||||
plot->axes(Qt::Vertical).first()->setRange(0, 10); /// this must be after createDefaultAxes();
|
|
||||||
plot->axes(Qt::Horizontal).first()->setRange(0, 5);
|
|
||||||
|
|
||||||
QChartView * plotView = new QChartView(plot);
|
QChartView * plotView = new QChartView(plot);
|
||||||
plotView->setRenderHints(QPainter::Antialiasing);
|
plotView->setRenderHints(QPainter::Antialiasing);
|
||||||
|
|
||||||
//scope->setCentralWidget(plotView);
|
//scope->setCentralWidget(plotView);
|
||||||
layout->addWidget(plotView);
|
layout->addWidget(plotView, 0, 0);
|
||||||
|
|
||||||
|
QPushButton * bnUpdate = new QPushButton("Random", scope);
|
||||||
|
layout->addWidget(bnUpdate, 1, 0);
|
||||||
|
connect(bnUpdate, &QPushButton::clicked, this, &MainWindow::UpdateScope);
|
||||||
|
|
||||||
scope->show();
|
scope->show();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::SetUpPlot(){
|
||||||
|
plot = new QChart();
|
||||||
|
dataTrace = new QLineSeries();
|
||||||
|
dataTrace->setName("data");
|
||||||
|
for(int i = 0; i < 100; i ++) dataTrace->append(i, QRandomGenerator::global()->bounded(10));
|
||||||
|
plot->addSeries(dataTrace);
|
||||||
|
plot->createDefaultAxes(); /// this must be after addSeries();
|
||||||
|
plot->axes(Qt::Vertical).first()->setRange(-1, 11); /// this must be after createDefaultAxes();
|
||||||
|
plot->axes(Qt::Horizontal).first()->setRange(-1, 101);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::UpdateScope(){
|
||||||
|
|
||||||
|
//int nDataPoint = dataTrace->count();
|
||||||
|
//dataTrace->removePoints(0, 4);
|
||||||
|
for( int i = 0 ; i < dataTrace->count(); i++){
|
||||||
|
dataTrace->replace(i, i, QRandomGenerator::global()->bounded(10));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
//^###################################################################### Open digitizer setting panel
|
//^###################################################################### Open digitizer setting panel
|
||||||
void MainWindow::OpenDigitizersSettings(){
|
void MainWindow::OpenDigitizersSettings(){
|
||||||
LogMsg("Open digitizers Settings Panel");
|
LogMsg("Open digitizers Settings Panel");
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
#include <QChart>
|
#include <QChart>
|
||||||
|
#include <QLineSeries>
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <time.h> // time in nano-sec
|
#include <time.h> // time in nano-sec
|
||||||
|
@ -99,10 +100,11 @@ private slots:
|
||||||
void CloseDigitizers();
|
void CloseDigitizers();
|
||||||
|
|
||||||
void OpenScope();
|
void OpenScope();
|
||||||
|
void SetUpPlot();
|
||||||
|
void UpdateScope();
|
||||||
|
|
||||||
void OpenDigitizersSettings();
|
void OpenDigitizersSettings();
|
||||||
|
|
||||||
|
|
||||||
void ProgramSettings();
|
void ProgramSettings();
|
||||||
bool OpenProgramSettings();
|
bool OpenProgramSettings();
|
||||||
void SaveProgramSettings();
|
void SaveProgramSettings();
|
||||||
|
@ -131,6 +133,7 @@ private:
|
||||||
|
|
||||||
QPushButton * bnOpenScope;
|
QPushButton * bnOpenScope;
|
||||||
QChart * plot;
|
QChart * plot;
|
||||||
|
QLineSeries * dataTrace;
|
||||||
|
|
||||||
QPushButton * bnStartACQ;
|
QPushButton * bnStartACQ;
|
||||||
QPushButton * bnStopACQ;
|
QPushButton * bnStopACQ;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user