add scroll for scalar

This commit is contained in:
Ryan Tang 2023-02-13 17:56:15 -05:00
parent 709f0553b4
commit 8a48d43e7e
4 changed files with 76 additions and 27 deletions

View File

@ -14,6 +14,7 @@
#include <QValueAxis> #include <QValueAxis>
#include <QStandardItemModel> #include <QStandardItemModel>
#include <QApplication> #include <QApplication>
#include <QDateTime>
#include <unistd.h> #include <unistd.h>
@ -37,8 +38,14 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){
scalar->setWindowTitle("Scalar"); scalar->setWindowTitle("Scalar");
scalar->setGeometry(0, 0, 1000, 800); scalar->setGeometry(0, 0, 1000, 800);
QScrollArea * scopeScroll = new QScrollArea(scalar);
scalar->setCentralWidget(scopeScroll);
scopeScroll->setWidgetResizable(true);
scopeScroll->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
QWidget * layoutWidget = new QWidget(scalar); QWidget * layoutWidget = new QWidget(scalar);
scalar->setCentralWidget(layoutWidget); scopeScroll->setWidget(layoutWidget);
scalarLayout = new QGridLayout(layoutWidget); scalarLayout = new QGridLayout(layoutWidget);
scalarLayout->setSpacing(0); scalarLayout->setSpacing(0);
@ -131,6 +138,24 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){
bnOpenScalar->setEnabled(false); bnOpenScalar->setEnabled(false);
connect(bnOpenScalar, &QPushButton::clicked, this, &MainWindow::OpenScaler); connect(bnOpenScalar, &QPushButton::clicked, this, &MainWindow::OpenScaler);
QLabel * lbRunID = new QLabel("Run ID : ", this);
lbRunID->setAlignment(Qt::AlignRight | Qt::AlignCenter);
leRunID = new QLineEdit(this);
leRunID->setAlignment(Qt::AlignHCenter);
leRunID->setReadOnly(true);
chkSaveRun = new QCheckBox("Save Run", this);
cbAutoRun = new QComboBox(this);
cbAutoRun->addItem("Single Run");
cbAutoRun->addItem("Auto 30 mins");
cbAutoRun->addItem("Auto 60 mins");
cbAutoRun->addItem("Auto 2 hrs");
cbAutoRun->addItem("Auto 3 hrs");
cbAutoRun->addItem("Auto 5 hrs");
cbAutoRun->setEnabled(false);
bnStartACQ = new QPushButton("Start ACQ", this); bnStartACQ = new QPushButton("Start ACQ", this);
bnStartACQ->setEnabled(false); bnStartACQ->setEnabled(false);
connect(bnStartACQ, &QPushButton::clicked, this, &MainWindow::StartACQ); connect(bnStartACQ, &QPushButton::clicked, this, &MainWindow::StartACQ);
@ -139,34 +164,31 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){
bnStopACQ->setEnabled(false); bnStopACQ->setEnabled(false);
connect(bnStopACQ, &QPushButton::clicked, this, &MainWindow::StopACQ); connect(bnStopACQ, &QPushButton::clicked, this, &MainWindow::StopACQ);
QLabel * lbRunID = new QLabel("Run ID : ", this);
lbRunID->setAlignment(Qt::AlignRight | Qt::AlignCenter);
leRunID = new QLineEdit(this);
leRunID->setAlignment(Qt::AlignHCenter);
leRunID->setReadOnly(true);
QLabel * lbRunComment = new QLabel("Run Comment : ", this); QLabel * lbRunComment = new QLabel("Run Comment : ", this);
lbRunComment->setAlignment(Qt::AlignRight | Qt::AlignCenter); lbRunComment->setAlignment(Qt::AlignRight | Qt::AlignCenter);
QLineEdit * runComment = new QLineEdit(this); QLineEdit * runComment = new QLineEdit(this);
runComment->setReadOnly(true); runComment->setReadOnly(true);
layout2->addWidget(lbRawDataPath, 0, 0); layout2->addWidget(lbRawDataPath, 0, 0);
layout2->addWidget(leRawDataPath, 0, 1, 1, 2); layout2->addWidget(leRawDataPath, 0, 1, 1, 4);
layout2->addWidget(bnOpenScalar, 0, 3); layout2->addWidget(bnOpenScalar, 0, 5);
layout2->addWidget(lbRunID, 1, 0); layout2->addWidget(lbRunID, 1, 0);
layout2->addWidget(leRunID, 1, 1); layout2->addWidget(leRunID, 1, 1);
layout2->addWidget(bnStartACQ, 1, 2); layout2->addWidget(chkSaveRun, 1, 2);
layout2->addWidget(bnStopACQ, 1, 3); layout2->addWidget(cbAutoRun, 1, 3);
layout2->addWidget(bnStartACQ, 1, 4);
layout2->addWidget(bnStopACQ, 1, 5);
layout2->addWidget(lbRunComment, 2, 0); layout2->addWidget(lbRunComment, 2, 0);
layout2->addWidget(runComment, 2, 1, 1, 3); layout2->addWidget(runComment, 2, 1, 1, 5);
layout2->setColumnStretch(0, 1); layout2->setColumnStretch(0, 2);
layout2->setColumnStretch(1, 1); layout2->setColumnStretch(1, 1);
layout2->setColumnStretch(2, 2); layout2->setColumnStretch(2, 1);
layout2->setColumnStretch(3, 2); layout2->setColumnStretch(3, 1);
layout2->setColumnStretch(4, 3);
layout2->setColumnStretch(5, 3);
} }
@ -234,7 +256,7 @@ void MainWindow::StartACQ(){
digi[i]->StartACQ(); digi[i]->StartACQ();
//TODO ========================== Sync start. //TODO ========================== Sync start.
readDataThread[i]->SetScopeRun(false); readDataThread[i]->SetScopeRun(!chkSaveRun->isChecked ());
readDataThread[i]->start(); readDataThread[i]->start();
} }
@ -269,9 +291,10 @@ void MainWindow::StopACQ(){
bnStopACQ->setEnabled(false); bnStopACQ->setEnabled(false);
bnOpenScope->setEnabled(true); bnOpenScope->setEnabled(true);
runID ++; if( chkSaveRun->isChecked() ){
leRunID->setText(QString::number(runID)); runID ++;
leRunID->setText(QString::number(runID));
}
//if( scalarThread->isRunning()) printf("Scalar Thread still running.\n"); //if( scalarThread->isRunning()) printf("Scalar Thread still running.\n");
//if( scalarThread->isFinished()) printf("Scalar Thread finsihed.\n"); //if( scalarThread->isFinished()) printf("Scalar Thread finsihed.\n");
@ -363,9 +386,9 @@ void MainWindow::OpenScope(){
if( digi ){ if( digi ){
if( !scope ){ if( !scope ){
scope = new Scope(digi, nDigi, readDataThread); scope = new Scope(digi, nDigi, readDataThread);
connect(scope, &Scope::CloseWindow, this, [=](){ connect(scope, &Scope::CloseWindow, this, [=](){ bnStartACQ->setEnabled(true); });
bnStartACQ->setEnabled(true); connect(scope, &Scope::UpdateScalar, this, &MainWindow::UpdateScalar);
}); connect(scope, &Scope::SendLogMsg, this, &MainWindow::LogMsg);
}else{ }else{
scope->show(); scope->show();
} }
@ -395,9 +418,14 @@ void MainWindow::OpenScaler(){
void MainWindow::SetUpScalar(){ void MainWindow::SetUpScalar(){
scalar->setGeometry(0, 0, 10 + nDigi * 200, 1000); scalar->setGeometry(0, 0, 10 + nDigi * 200, 800);
int rowID = 0; lbLastUpdateTime = new QLabel("Last update : ");
lbLastUpdateTime->setAlignment(Qt::AlignCenter);
scalarLayout->addWidget(lbLastUpdateTime, 0, 1, 1, 1 + nDigi);
///==== create the 1st row
int rowID = 2;
for( int ch = 0; ch < MaxNumberOfChannel; ch++){ for( int ch = 0; ch < MaxNumberOfChannel; ch++){
if( ch == 0 ){ if( ch == 0 ){
@ -410,10 +438,11 @@ void MainWindow::SetUpScalar(){
scalarLayout->addWidget(lbCH, rowID, 0); scalarLayout->addWidget(lbCH, rowID, 0);
} }
///===== create the trigger and accept
leTrigger = new QLineEdit**[nDigi]; leTrigger = new QLineEdit**[nDigi];
leAccept = new QLineEdit**[nDigi]; leAccept = new QLineEdit**[nDigi];
for( int iDigi = 0; iDigi < nDigi; iDigi++){ for( int iDigi = 0; iDigi < nDigi; iDigi++){
rowID = 0; rowID = 1;
leTrigger[iDigi] = new QLineEdit *[digi[iDigi]->GetNChannels()]; leTrigger[iDigi] = new QLineEdit *[digi[iDigi]->GetNChannels()];
leAccept[iDigi] = new QLineEdit *[digi[iDigi]->GetNChannels()]; leAccept[iDigi] = new QLineEdit *[digi[iDigi]->GetNChannels()];
for( int ch = 0; ch < MaxNumberOfChannel; ch++){ for( int ch = 0; ch < MaxNumberOfChannel; ch++){
@ -422,6 +451,15 @@ void MainWindow::SetUpScalar(){
QLabel * lbDigi = new QLabel("Digi-" + QString::number(digi[iDigi]->GetSerialNumber()), scalar); QLabel * lbDigi = new QLabel("Digi-" + QString::number(digi[iDigi]->GetSerialNumber()), scalar);
lbDigi->setAlignment(Qt::AlignCenter); lbDigi->setAlignment(Qt::AlignCenter);
scalarLayout->addWidget(lbDigi, rowID, 2*iDigi+1, 1, 2); scalarLayout->addWidget(lbDigi, rowID, 2*iDigi+1, 1, 2);
rowID ++;
QLabel * lbA = new QLabel("Trig. [Hz]", scalar);
lbA->setAlignment(Qt::AlignCenter);
scalarLayout->addWidget(lbA, rowID, 2*iDigi+1);
QLabel * lbB = new QLabel("Accp. [Hz]", scalar);
lbB->setAlignment(Qt::AlignCenter);
scalarLayout->addWidget(lbB, rowID, 2*iDigi+2);
} }
rowID ++; rowID ++;
@ -434,6 +472,7 @@ void MainWindow::SetUpScalar(){
leAccept[iDigi][ch] = new QLineEdit(); leAccept[iDigi][ch] = new QLineEdit();
leAccept[iDigi][ch]->setReadOnly(true); leAccept[iDigi][ch]->setReadOnly(true);
leAccept[iDigi][ch]->setAlignment(Qt::AlignRight); leAccept[iDigi][ch]->setAlignment(Qt::AlignRight);
leAccept[iDigi][ch]->setStyleSheet("background-color: #F0F0F0;");
scalarLayout->addWidget(leAccept[iDigi][ch], rowID, 2*iDigi+2); scalarLayout->addWidget(leAccept[iDigi][ch], rowID, 2*iDigi+2);
} }
} }
@ -461,6 +500,8 @@ void MainWindow::DeleteTriggerLineEdit(){
void MainWindow::UpdateScalar(){ void MainWindow::UpdateScalar(){
if( !digi ) return; if( !digi ) return;
lbLastUpdateTime->setText("Last update: " + QDateTime::currentDateTime().toString("MM.dd hh:mm:ss"));
///===== Get trigger for all channel ///===== Get trigger for all channel
for( int iDigi = 0; iDigi < nDigi; iDigi ++ ){ for( int iDigi = 0; iDigi < nDigi; iDigi ++ ){
if( digi[iDigi]->IsDummy() ) return; if( digi[iDigi]->IsDummy() ) return;

View File

@ -10,6 +10,7 @@
#include <QScrollBar> #include <QScrollBar>
#include <QPushButton> #include <QPushButton>
#include <QComboBox> #include <QComboBox>
#include <QLabel>
#include <QChart> #include <QChart>
#include <QLineSeries> #include <QLineSeries>
@ -91,10 +92,13 @@ private:
QLineEdit *** leAccept; // need to delete manually QLineEdit *** leAccept; // need to delete manually
QGridLayout * scalarLayout; QGridLayout * scalarLayout;
ScalarThread * scalarThread; ScalarThread * scalarThread;
QLabel * lbLastUpdateTime;
//@------ ACQ things //@------ ACQ things
QPushButton * bnStartACQ; QPushButton * bnStartACQ;
QPushButton * bnStopACQ; QPushButton * bnStopACQ;
QCheckBox * chkSaveRun;
QComboBox * cbAutoRun;
QLineEdit * leRunID; QLineEdit * leRunID;
QLineEdit * leRawDataPath; QLineEdit * leRawDataPath;
ReadDataThread ** readDataThread; ReadDataThread ** readDataThread;

View File

@ -49,7 +49,7 @@ Scope::Scope(Digitizer2Gen **digi, unsigned int nDigi, ReadDataThread ** readDat
updateTraceThread = new UpdateTraceThread(); updateTraceThread = new UpdateTraceThread();
connect(updateTraceThread, &UpdateTraceThread::updateTrace, this, &Scope::UpdateScope); connect(updateTraceThread, &UpdateTraceThread::updateTrace, this, &Scope::UpdateScope);
//*================ add Widgets //*================ add Widgets
int rowID = -1; int rowID = -1;
QWidget * layoutWidget = new QWidget(this); QWidget * layoutWidget = new QWidget(this);
@ -470,6 +470,8 @@ void Scope::UpdateScope(){
int ch = cbScopeCh->currentIndex(); int ch = cbScopeCh->currentIndex();
int sample2ns = DIGIPARA::TraceStep * (1 << cbWaveRes->currentIndex()); int sample2ns = DIGIPARA::TraceStep * (1 << cbWaveRes->currentIndex());
emit UpdateScalar();
if( digi ){ if( digi ){
//---- remove all points //---- remove all points
unsigned int dataLength = dataTrace[0]->count(); unsigned int dataLength = dataTrace[0]->count();

View File

@ -128,6 +128,8 @@ private slots:
signals: signals:
void CloseWindow(); void CloseWindow();
void SendLogMsg(const QString &msg);
void UpdateScalar();
private: private: