Browse Source

优化页面流畅度

master
zhaohe 1 year ago
parent
commit
cb785a93c5
  1. 99
      mainwindow.cpp

99
mainwindow.cpp

@ -21,6 +21,8 @@ QTimer *timer1;
QTimer *timer2; QTimer *timer2;
QTimer *timer3; QTimer *timer3;
QTimer *checkConnectTimer0; QTimer *checkConnectTimer0;
ZQThread *m_zqthread;
#define TAG "MainWindow" #define TAG "MainWindow"
static const char *fmt(const char *fmt, ...) { static const char *fmt(const char *fmt, ...) {
@ -195,7 +197,9 @@ void MainWindow::refreshReadonlyPage0() {
{ {
float TriOutSignalFreq; float TriOutSignalFreq;
DO(m_clstc->InterClk_readTriOutSignalFreq(TriOutSignalFreq)); DO(m_clstc->InterClk_readTriOutSignalFreq(TriOutSignalFreq));
emit doinui_signal(QFunction([this, TriOutSignalFreq]() { //
ui->InterClk_TriOutSignalFreq_Text->setText(QString::number(TriOutSignalFreq, 'f', 2)); ui->InterClk_TriOutSignalFreq_Text->setText(QString::number(TriOutSignalFreq, 'f', 2));
}));
} }
} }
void MainWindow::refreshReadonlyPage1() { void MainWindow::refreshReadonlyPage1() {
@ -210,9 +214,12 @@ void MainWindow::refreshReadonlyPage1() {
#define UPDATE(index) \ #define UPDATE(index) \
DO(m_clstc->TriInX_readInSignalFreq(index, infreq)); \ DO(m_clstc->TriInX_readInSignalFreq(index, infreq)); \
DO(m_clstc->TriInX_readOutSignalFreq(index, outfreq)); \ DO(m_clstc->TriInX_readOutSignalFreq(index, outfreq)); \
{ \
emit doinui_signal(QFunction([this, infreq, outfreq]() { \
ui->TriInX_OutSignalFreq_Val_##index->setText(QString::number(outfreq, 'f', 2)); \ ui->TriInX_OutSignalFreq_Val_##index->setText(QString::number(outfreq, 'f', 2)); \
ui->TriInX_InSignalFreq_Val_##index->setText(QString::number(infreq, 'f', 2));
ui->TriInX_InSignalFreq_Val_##index->setText(QString::number(infreq, 'f', 2)); \
})); \
}
UPDATE(1); UPDATE(1);
UPDATE(2); UPDATE(2);
UPDATE(3); UPDATE(3);
@ -236,9 +243,13 @@ void MainWindow::refreshReadonlyPage2() {
DO(m_clstc->LightSrcX_readInSigFreqDetect(index, infreq)); \ DO(m_clstc->LightSrcX_readInSigFreqDetect(index, infreq)); \
DO(m_clstc->LightSrcX_readOutSigFreqDetect(index, outfreq)); \ DO(m_clstc->LightSrcX_readOutSigFreqDetect(index, outfreq)); \
DO(m_clstc->LightSrcX_readLightSrcErrorState(index, state)); \ DO(m_clstc->LightSrcX_readLightSrcErrorState(index, state)); \
{ \
emit doinui_signal(QFunction([this, infreq, outfreq, state]() { \
ui->LightSrcX_InSigFreqDetect_##index->setText(QString::number(infreq, 'f', 2)); \ ui->LightSrcX_InSigFreqDetect_##index->setText(QString::number(infreq, 'f', 2)); \
ui->LightSrcX_OutSigFreqDetect_##index->setText(QString::number(outfreq, 'f', 2)); \ ui->LightSrcX_OutSigFreqDetect_##index->setText(QString::number(outfreq, 'f', 2)); \
ui->LightSrcX_LightSrcErrorState_##index->setText(QString::number(state));
ui->LightSrcX_LightSrcErrorState_##index->setText(QString::number(state)); \
})); \
}
UPDATE(1); UPDATE(1);
UPDATE(2); UPDATE(2);
@ -246,7 +257,11 @@ void MainWindow::refreshReadonlyPage2() {
UPDATE(4); UPDATE(4);
} }
} }
void MainWindow::refreshReadonlyPage3() {
if (!G_QTDataChannel.isOpen()) {
return;
}
}
bool MainWindow::checkConnected() { bool MainWindow::checkConnected() {
if (!G_QTDataChannel.isOpen()) { if (!G_QTDataChannel.isOpen()) {
return false; return false;
@ -259,12 +274,6 @@ bool MainWindow::checkConnected() {
return true; return true;
} }
void MainWindow::refreshReadonlyPage3() {
if (!G_QTDataChannel.isOpen()) {
return;
}
}
void MainWindow::refreshPage() { void MainWindow::refreshPage() {
/******************************************************************************* /*******************************************************************************
* * * *
@ -663,6 +672,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
qRegisterMetaType<int32_t>("int32_t"); qRegisterMetaType<int32_t>("int32_t");
qRegisterMetaType<uint32_t>("uint32_t"); qRegisterMetaType<uint32_t>("uint32_t");
qRegisterMetaType<float>("float");
qRegisterMetaType<function<void()>>("function<void()>"); qRegisterMetaType<function<void()>>("function<void()>");
qRegisterMetaType<QFunction>("QFunction"); qRegisterMetaType<QFunction>("QFunction");
// qInstallMessageHandler(log_output); // qInstallMessageHandler(log_output);
@ -675,40 +685,73 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
timer2 = new QTimer(this); timer2 = new QTimer(this);
timer3 = new QTimer(this); timer3 = new QTimer(this);
checkConnectTimer0 = new QTimer(this); checkConnectTimer0 = new QTimer(this);
connect(timer0, &QTimer::timeout, this, [this]() { refreshReadonlyPage0(); });
connect(timer1, &QTimer::timeout, this, [this]() { refreshReadonlyPage1(); });
connect(timer2, &QTimer::timeout, this, [this]() { refreshReadonlyPage2(); });
connect(timer3, &QTimer::timeout, this, [this]() { refreshReadonlyPage3(); });
connect(checkConnectTimer0, &QTimer::timeout, this, [this]() { //
m_zqthread = new ZQThread("", [this]() {
while (true) {
static bool connected = false; static bool connected = false;
static bool first = true;
bool connect = checkConnected(); bool connect = checkConnected();
if (connected != connect || first) {
first = false;
connected = connect;
emit doinui_signal(QFunction([this, connect]() {
if (connect) { if (connect) {
ui->DeviceConnectStateTB->setText("已连接"); ui->DeviceConnectStateTB->setText("已连接");
ui->DeviceConnectStateTB->setStyleSheet("color: green"); ui->DeviceConnectStateTB->setStyleSheet("color: green");
} else { } else {
ui->DeviceConnectStateTB->setText("未连接"); ui->DeviceConnectStateTB->setText("未连接");
ui->DeviceConnectStateTB->setStyleSheet("color: red"); ui->DeviceConnectStateTB->setStyleSheet("color: red");
} }
if (connected != connect) {
connected = connect;
if (connected) { if (connected) {
refreshPage(); refreshPage();
} }
}));
} }
refreshReadonlyPage0();
refreshReadonlyPage1();
refreshReadonlyPage2();
refreshReadonlyPage3();
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
}
}); });
m_zqthread->start();
// connect(timer0, &QTimer::timeout, this, [this]() { refreshReadonlyPage0(); });
// connect(timer1, &QTimer::timeout, this, [this]() { refreshReadonlyPage1(); });
// connect(timer2, &QTimer::timeout, this, [this]() { refreshReadonlyPage2(); });
// connect(timer3, &QTimer::timeout, this, [this]() { refreshReadonlyPage3(); });
// connect(checkConnectTimer0, &QTimer::timeout, this, [this]() { //
// static bool connected = false;
// bool connect = checkConnected();
// if (connect) {
// ui->DeviceConnectStateTB->setText("已连接");
// ui->DeviceConnectStateTB->setStyleSheet("color: green");
// } else {
// ui->DeviceConnectStateTB->setText("未连接");
// ui->DeviceConnectStateTB->setStyleSheet("color: red");
// }
// if (connected != connect) {
// connected = connect;
// if (connected) {
// refreshPage();
// }
// }
// });
timer0->setInterval(1100); // 每隔一秒触发一次
timer1->setInterval(1200); // 每隔一秒触发一次
timer2->setInterval(900); // 每隔一秒触发一次
timer3->setInterval(1000); // 每隔一秒触发一次
checkConnectTimer0->setInterval(100);
timer0->start();
timer1->start();
timer2->start();
timer3->start();
checkConnectTimer0->start();
// timer0->setInterval(1100); // 每隔一秒触发一次
// timer1->setInterval(1200); // 每隔一秒触发一次
// timer2->setInterval(900); // 每隔一秒触发一次
// timer3->setInterval(1000); // 每隔一秒触发一次
// checkConnectTimer0->setInterval(100);
// timer0->start();
// timer1->start();
// timer2->start();
// timer3->start();
// checkConnectTimer0->start();
// m_clstc->regRawDataListener([this](uart_message_type_t type, uint8_t *data, size_t len) { // m_clstc->regRawDataListener([this](uart_message_type_t type, uint8_t *data, size_t len) {
// QString text; // QString text;

Loading…
Cancel
Save