From e1541a5da53b7f81042d685b06e527ea7652750d Mon Sep 17 00:00:00 2001 From: pandx Date: Thu, 27 Mar 2025 10:16:01 +0800 Subject: [PATCH] refine codes. --- keyphase.cpp | 77 ++++++++++++----------- keyphase.h | 12 ++-- keyphase.ui | 121 +++++++++++++++++++++++++++++++----- relaysetting.cpp | 111 ++++++++++++++++----------------- seismic_monitor.ui | 51 +++++++++++++++ singlerelay.cpp | 11 ++-- singlerelay.h | 10 +-- singlerelay.ui | 30 +++------ tachometer.cpp | 114 ++++++++++++++++++---------------- tachometer.h | 12 ++-- tachometer.ui | 138 +++++++++++++++++++++++++++++++++++------ tmrrelayassociation.ui | 23 +++---- 12 files changed, 468 insertions(+), 242 deletions(-) diff --git a/keyphase.cpp b/keyphase.cpp index f015f94..74b1b5b 100644 --- a/keyphase.cpp +++ b/keyphase.cpp @@ -6,12 +6,12 @@ #include #include -KeyPhase::KeyPhase(int slot_no_,QWidget *parent) +KeyPhase::KeyPhase(int slot_no_, QWidget *parent) : QDialog(parent) - , ui(new Ui::KeyPhase) -{ + , ui(new Ui::KeyPhase) { ui->setupUi(this); ui->widget_body->setProperty("flag", "body"); + setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); slot_no = slot_no_; QString slot = QString("%1").arg(slot_no); ui->label_slot->setText(slot); @@ -20,12 +20,15 @@ KeyPhase::KeyPhase(int slot_no_,QWidget *parent) Init(); } -KeyPhase::~KeyPhase() -{ +KeyPhase::~KeyPhase() { delete ui; } -void KeyPhase::readJsonFile(const QString &filePath) -{ + +void KeyPhase::on_pushButton_cancel_clicked() { + this->close(); +} + +void KeyPhase::readJsonFile(const QString &filePath) { QFile file(filePath); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { qDebug() << "Cannot open file for reading:" << filePath; @@ -45,7 +48,7 @@ void KeyPhase::readJsonFile(const QString &filePath) } QJsonObject json_obj = jsonDoc.object(); QJsonArray chan_array = json_obj["chan"].toArray(); - for(int i = 0; i < chan_array.size(); i++){ + for (int i = 0; i < chan_array.size(); i++) { QJsonObject temp_obj = chan_array[i].toObject(); keyphase_variables[i].id = temp_obj["id"].toInt(); keyphase_variables[i].active = temp_obj["active"].toBool(); @@ -62,67 +65,65 @@ void KeyPhase::readJsonFile(const QString &filePath) keyphase_variables[i].normal_latching = temp_obj["normal_latching"].toBool(); } } -void KeyPhase::Init() -{ +void KeyPhase::Init() { for (int i = 0; i < CHANNLE_COUNT; i++) { - if(keyphase_variables[i].id == 1){ + if (keyphase_variables[i].id == 1) { ui->checkBox_enable_1->setChecked(keyphase_variables[i].active); ui->doubleSpinBox_high_1->setValue(keyphase_variables[i].normal_voltage_high); ui->doubleSpinBox_low_1->setValue(keyphase_variables[i].normal_voltage_low); - if(keyphase_variables[i].automatic_threshold) + if (keyphase_variables[i].automatic_threshold) { ui->radioButton_automatic_threshold_1->setChecked(true); - else + } else { ui->radioButton_manual_threshold_1->setChecked(true); + } ui->doubleSpinBox_threshold_1->setValue(keyphase_variables[i].threshold); ui->doubleSpinBox_hysteresis_1->setValue(keyphase_variables[i].hysteresis); ui->spinBox_events_per_revolution_1->setValue(keyphase_variables[i].events_per_revolution); - } - if(keyphase_variables[i].id == 2) - { + if (keyphase_variables[i].id == 2) { ui->checkBox_enable_2->setChecked(keyphase_variables[i].active); ui->doubleSpinBox_high_2->setValue(keyphase_variables[i].normal_voltage_high); ui->doubleSpinBox_low_2->setValue(keyphase_variables[i].normal_voltage_low); - if(keyphase_variables[i].automatic_threshold) + if (keyphase_variables[i].automatic_threshold) { ui->radioButton_automatic_threshold_2->setChecked(true); - else + } else { ui->radioButton_manual_threshold_2->setChecked(true); + } ui->doubleSpinBox_threshold_2->setValue(keyphase_variables[i].threshold); ui->doubleSpinBox_hysteresis_2->setValue(keyphase_variables[i].hysteresis); ui->spinBox_events_per_revolution_2->setValue(keyphase_variables[i].events_per_revolution); - } - if(keyphase_variables[i].id == 3){ + if (keyphase_variables[i].id == 3) { ui->checkBox_enable_3->setChecked(keyphase_variables[i].active); ui->doubleSpinBox_high_3->setValue(keyphase_variables[i].normal_voltage_high); ui->doubleSpinBox_low_3->setValue(keyphase_variables[i].normal_voltage_low); - if(keyphase_variables[i].automatic_threshold) + if (keyphase_variables[i].automatic_threshold) { ui->radioButton_automatic_threshold_3->setChecked(true); - else + } else { ui->radioButton_manual_threshold_3->setChecked(true); + } ui->doubleSpinBox_threshold_3->setValue(keyphase_variables[i].threshold); ui->doubleSpinBox_hysteresis_3->setValue(keyphase_variables[i].hysteresis); ui->spinBox_events_per_revolution_3->setValue(keyphase_variables[i].events_per_revolution); } - if(keyphase_variables[i].id == 4){ + if (keyphase_variables[i].id == 4) { ui->checkBox_enable_4->setChecked(keyphase_variables[i].active); ui->doubleSpinBox_high_4->setValue(keyphase_variables[i].normal_voltage_high); ui->doubleSpinBox_low_4->setValue(keyphase_variables[i].normal_voltage_low); - if(keyphase_variables[i].automatic_threshold) + if (keyphase_variables[i].automatic_threshold) { ui->radioButton_automatic_threshold_4->setChecked(true); - else + } else { ui->radioButton_manual_threshold_4->setChecked(true); + } ui->doubleSpinBox_threshold_4->setValue(keyphase_variables[i].threshold); ui->doubleSpinBox_hysteresis_4->setValue(keyphase_variables[i].hysteresis); ui->spinBox_events_per_revolution_4->setValue(keyphase_variables[i].events_per_revolution); - } } } -void KeyPhase::on_pushButton_confirm_clicked() -{ +void KeyPhase::on_pushButton_confirm_clicked() { for (int i = 0; i < CHANNLE_COUNT; i++) { - if(keyphase_variables[i].id == 1){ + if (keyphase_variables[i].id == 1) { keyphase_variables[i].active = ui->checkBox_enable_1->isChecked(); keyphase_variables[i].normal_voltage_high = ui->doubleSpinBox_high_1->value(); keyphase_variables[i].normal_voltage_low = ui->doubleSpinBox_low_1->value(); @@ -131,7 +132,7 @@ void KeyPhase::on_pushButton_confirm_clicked() keyphase_variables[i].hysteresis = ui->doubleSpinBox_hysteresis_1->value(); keyphase_variables[i].events_per_revolution = ui->spinBox_events_per_revolution_1->value(); } - if(keyphase_variables[i].id == 2){ + if (keyphase_variables[i].id == 2) { keyphase_variables[i].active = ui->checkBox_enable_2->isChecked(); keyphase_variables[i].normal_voltage_high = ui->doubleSpinBox_high_2->value(); keyphase_variables[i].normal_voltage_low = ui->doubleSpinBox_low_2->value(); @@ -140,7 +141,7 @@ void KeyPhase::on_pushButton_confirm_clicked() keyphase_variables[i].hysteresis = ui->doubleSpinBox_hysteresis_2->value(); keyphase_variables[i].events_per_revolution = ui->spinBox_events_per_revolution_2->value(); } - if(keyphase_variables[i].id == 3){ + if (keyphase_variables[i].id == 3) { keyphase_variables[i].active = ui->checkBox_enable_3->isChecked(); keyphase_variables[i].normal_voltage_high = ui->doubleSpinBox_high_3->value(); keyphase_variables[i].normal_voltage_low = ui->doubleSpinBox_low_3->value(); @@ -149,7 +150,7 @@ void KeyPhase::on_pushButton_confirm_clicked() keyphase_variables[i].hysteresis = ui->doubleSpinBox_hysteresis_3->value(); keyphase_variables[i].events_per_revolution = ui->spinBox_events_per_revolution_3->value(); } - if(keyphase_variables[i].id == 4){ + if (keyphase_variables[i].id == 4) { keyphase_variables[i].active = ui->checkBox_enable_4->isChecked(); keyphase_variables[i].normal_voltage_high = ui->doubleSpinBox_high_4->value(); keyphase_variables[i].normal_voltage_low = ui->doubleSpinBox_low_4->value(); @@ -162,8 +163,7 @@ void KeyPhase::on_pushButton_confirm_clicked() QString slot = QString("%1").arg(slot_no); QString filePath_keyphase = QCoreApplication::applicationDirPath() + QString("\\config\\%1\\keyphase.json").arg(slot_no); QFile file(filePath_keyphase); - if(!file.open(QIODevice::WriteOnly)) - { + if (!file.open(QIODevice::WriteOnly)) { qDebug() << "Could not open file for writing"; return; } @@ -180,18 +180,17 @@ void KeyPhase::on_pushButton_confirm_clicked() temp_obj.insert("threshold", keyphase_variables[i].threshold); temp_obj.insert("hysteresis", keyphase_variables[i].hysteresis); temp_obj.insert("events_per_revolution", keyphase_variables[i].events_per_revolution); - temp_obj.insert("automatic_threshold",keyphase_variables[i].automatic_threshold); + temp_obj.insert("automatic_threshold", keyphase_variables[i].automatic_threshold); chan_array.append(temp_obj); } json_obj.insert("chan", chan_array); - json_obj.insert("version",1); - json_obj.insert("slot",slot_no); - json_obj.insert("card_type",2); + json_obj.insert("version", 1); + json_obj.insert("slot", slot_no); + json_obj.insert("card_type", 2); QJsonDocument json_doc; json_doc.setObject(json_obj); QByteArray byte_array = json_doc.toJson(); file.write(byte_array); file.close(); - } diff --git a/keyphase.h b/keyphase.h index 069081b..5862c73 100644 --- a/keyphase.h +++ b/keyphase.h @@ -7,19 +7,19 @@ namespace Ui { class KeyPhase; } -class KeyPhase : public QDialog -{ +class KeyPhase : public QDialog { Q_OBJECT -public: - explicit KeyPhase(int slot_no_,QWidget *parent = nullptr); + public: + explicit KeyPhase(int slot_no_, QWidget *parent = nullptr); ~KeyPhase(); int slot_no; -private slots: + private slots: void on_pushButton_confirm_clicked(); + void on_pushButton_cancel_clicked(); -private: + private: Ui::KeyPhase *ui; Tachometer_Variables keyphase_variables[4]; void readJsonFile(const QString &filePath); diff --git a/keyphase.ui b/keyphase.ui index 8bf45df..4dc6a3a 100644 --- a/keyphase.ui +++ b/keyphase.ui @@ -31,7 +31,7 @@ - + 200 @@ -45,9 +45,12 @@ + + false + - 490 + 480 530 81 32 @@ -83,19 +86,6 @@ === - - - - 300 - 530 - 81 - 32 - - - - 测点名称 - - @@ -197,6 +187,18 @@ 16777215 + + 1 + + + -50.000000000000000 + + + 50.000000000000000 + + + -25.000000000000000 + @@ -219,6 +221,18 @@ 16777215 + + 1 + + + -50.000000000000000 + + + 50.000000000000000 + + + 25.000000000000000 + @@ -552,6 +566,18 @@ 16777215 + + 1 + + + -50.000000000000000 + + + 50.000000000000000 + + + -25.000000000000000 + @@ -574,6 +600,18 @@ 16777215 + + 1 + + + -50.000000000000000 + + + 50.000000000000000 + + + 25.000000000000000 + @@ -846,9 +884,12 @@ + + false + - 400 + 390 530 71 32 @@ -946,6 +987,18 @@ 16777215 + + 1 + + + -50.000000000000000 + + + 50.000000000000000 + + + -25.000000000000000 + @@ -968,6 +1021,18 @@ 16777215 + + 1 + + + -50.000000000000000 + + + 50.000000000000000 + + + 25.000000000000000 + @@ -1301,6 +1366,18 @@ 16777215 + + 1 + + + -50.000000000000000 + + + 50.000000000000000 + + + -25.000000000000000 + @@ -1323,6 +1400,18 @@ 16777215 + + 1 + + + -50.000000000000000 + + + 50.000000000000000 + + + 25.000000000000000 + diff --git a/relaysetting.cpp b/relaysetting.cpp index b820a34..da499d5 100644 --- a/relaysetting.cpp +++ b/relaysetting.cpp @@ -10,14 +10,13 @@ RelaySetting::RelaySetting(QWidget *parent) : QWidget(parent) - , ui(new Ui::RelaySetting) -{ + , ui(new Ui::RelaySetting) { ui->setupUi(this); ui->widget_body->setProperty("flag", "body"); + setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); readJsonFile(QCoreApplication::applicationDirPath() + "\\config\\main.json"); - for (int var = 0; var < map_slot_config.size(); ++var) { - if(map_slot_config[var].slot_type == 30){ + if (map_slot_config[var].slot_type == 30) { ui->comboBox_slot->addItem(QString::number(map_slot_config[var].slot)); } } @@ -61,15 +60,12 @@ RelaySetting::RelaySetting(QWidget *parent) this, &RelaySetting::onRadioButtonClicked); connect(ui->buttonGroup_STATUS, QOverload::of(&QButtonGroup::buttonClicked), this, &RelaySetting::onRadioButtonClicked); - } -RelaySetting::~RelaySetting() -{ +RelaySetting::~RelaySetting() { delete ui; } -void RelaySetting::readJsonFile(const QString &filePath) -{ +void RelaySetting::readJsonFile(const QString &filePath) { // 创建文件对象 QFile file(filePath); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { @@ -78,9 +74,7 @@ void RelaySetting::readJsonFile(const QString &filePath) } QString content = file.readAll(); file.close(); - QByteArray jsonData = content.toUtf8(); - QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonData); if (jsonDoc.isNull()) { qDebug() << "Cannot parse JSON document"; @@ -100,17 +94,17 @@ void RelaySetting::readJsonFile(const QString &filePath) slot_config.slot_type = obj["slot_type"].toInt(); slot_config.chan_display = obj["chan_display"].toString(); slot_config.rack_type = obj["rack_type"].toString(); - map_slot_config.insert(slot_id,slot_config); + map_slot_config.insert(slot_id, slot_config); slot_id ++; } } } -void RelaySetting::onRadioButtonClicked(QAbstractButton *button) -{ +void RelaySetting::onRadioButtonClicked(QAbstractButton *button) { QButtonGroup *group = qobject_cast(sender()); - if (!group || !button) return; - + if (!group || !button) { + return; + } qDebug() << "Group:" << group << ", Selected button text:" << button->text(); QTcpSocket socket; // 连接到服务器 @@ -119,52 +113,53 @@ void RelaySetting::onRadioButtonClicked(QAbstractButton *button) qDebug() << "Connection failed!"; return; } - PackageHead header = { {0xAA, 0x55, 0xAA}, kRelaySetting, sizeof(RelaySettingReq),0,{} }; - + PackageHead header = { {0xAA, 0x55, 0xAA}, kRelaySetting, sizeof(RelaySettingReq), 0, {} }; int slot = ui->comboBox_slot->currentText().toInt(); - qDebug() << "slot" << slot <objectName().mid(12); - qDebug() << "led_id" << led_id <text() == "OFF") + } + if (button->text() == "OFF") { relay_setting_req.led_operate = 0; - else if(button->text() == "ON") + } else if (button->text() == "ON") { relay_setting_req.led_operate = 1; - else if(button->text() == "红色") + } else if (button->text() == "红色") { relay_setting_req.led_operate = 2; - else if(button->text() == "绿色") + } else if (button->text() == "绿色") { relay_setting_req.led_operate = 3; - else if(button->text() == "红色1Hz闪烁" || button->text() == "红色闪烁") + } else if (button->text() == "红色1Hz闪烁" || button->text() == "红色闪烁") { relay_setting_req.led_operate = 4; - else if(button->text() == "红色2Hz闪烁") + } else if (button->text() == "红色2Hz闪烁") { relay_setting_req.led_operate = 5; - else if(button->text() == "绿色闪烁") + } else if (button->text() == "绿色闪烁") { relay_setting_req.led_operate = 6; - else if(button->text() == "测试") + } else if (button->text() == "测试") { relay_setting_req.led_operate = 7; - else if(button->text() == "手动") + } else if (button->text() == "手动") { relay_setting_req.led_operate = 8; - else if(button->text() == "工作") + } else if (button->text() == "工作") { relay_setting_req.led_operate = 9; + } qDebug() << "relay_setting_req.led_operate " << relay_setting_req.led_operate; - char send_buf[20] ={0}; - memcpy(send_buf, (char*)&header, sizeof(PackageHead)); - memcpy(send_buf + sizeof(PackageHead), (char*)&relay_setting_req, sizeof(RelaySettingReq)); + char send_buf[20] = {0}; + memcpy(send_buf, (char *)&header, sizeof(PackageHead)); + memcpy(send_buf + sizeof(PackageHead), (char *)&relay_setting_req, sizeof(RelaySettingReq)); int length = sizeof(PackageHead) + sizeof(RelaySettingReq); qint64 bytesWritten = socket.write(send_buf, length); qDebug() << "Server response: " << bytesWritten; @@ -172,15 +167,14 @@ void RelaySetting::onRadioButtonClicked(QAbstractButton *button) QByteArray response = socket.readAll(); PackageHead header; RelaySettingRsp relay_setting_rsp; - memcpy(&header,response.data(),sizeof(PackageHead)); + memcpy(&header, response.data(), sizeof(PackageHead)); qDebug() << "header len" << header.len << endl; - memcpy(&relay_setting_rsp,response.data() + sizeof(PackageHead),sizeof(RelaySettingRsp)); + memcpy(&relay_setting_rsp, response.data() + sizeof(PackageHead), sizeof(RelaySettingRsp)); qDebug() << "relay_setting_rsp code" << relay_setting_rsp.code << endl; } } -void RelaySetting::on_pushButton_status_clicked() -{ +void RelaySetting::on_pushButton_status_clicked() { QTcpSocket socket; // 连接到服务器 socket.connectToHost(g_strServerIp, 10000); @@ -188,18 +182,18 @@ void RelaySetting::on_pushButton_status_clicked() qDebug() << "Connection failed!"; return; } - PackageHead header = { {0xAA, 0x55, 0xAA}, kRelayStatus, sizeof(RelaySettingReq),0,{} }; - + PackageHead header = { {0xAA, 0x55, 0xAA}, kRelayStatus, sizeof(RelaySettingReq), 0, {} }; int slot = ui->comboBox_slot->currentText().toInt(); - qDebug() << "slot" << slot <label_status->setText("测试"); - else if(relay_status_rsp.status == 8) + } else if (relay_status_rsp.status == 8) { ui->label_status->setText("手动"); - else if(relay_status_rsp.status == 9) + } else if (relay_status_rsp.status == 9) { ui->label_status->setText("工作"); + } } } diff --git a/seismic_monitor.ui b/seismic_monitor.ui index cca9162..6f0f3f4 100644 --- a/seismic_monitor.ui +++ b/seismic_monitor.ui @@ -435,6 +435,9 @@ 16777215 + + + @@ -593,9 +596,15 @@ 16777215 + + 1 + -100.000000000000000 + + 25.000000000000000 + @@ -639,9 +648,15 @@ 16777215 + + 1 + -100.000000000000000 + + -25.000000000000000 + @@ -936,9 +951,15 @@ 16777215 + + 1 + -100.000000000000000 + + 25.000000000000000 + @@ -988,9 +1009,15 @@ 16777215 + + 1 + -100.000000000000000 + + -25.000000000000000 + @@ -1467,9 +1494,15 @@ 16777215 + + 1 + -100.000000000000000 + + 25.000000000000000 + @@ -1513,9 +1546,15 @@ 16777215 + + 1 + -100.000000000000000 + + -25.000000000000000 + @@ -1804,9 +1843,15 @@ 16777215 + + 1 + -100.000000000000000 + + 25.000000000000000 + @@ -1850,9 +1895,15 @@ 16777215 + + 1 + -100.000000000000000 + + -25.000000000000000 + diff --git a/singlerelay.cpp b/singlerelay.cpp index bcd8db5..5f34285 100644 --- a/singlerelay.cpp +++ b/singlerelay.cpp @@ -3,12 +3,15 @@ SingleRelay::SingleRelay(QWidget *parent) : QDialog(parent) - , ui(new Ui::SingleRelay) -{ + , ui(new Ui::SingleRelay) { ui->setupUi(this); + setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); } -SingleRelay::~SingleRelay() -{ +SingleRelay::~SingleRelay() { delete ui; } + +void SingleRelay::on_pushButton_cancel_clicked() { + this->close(); +} diff --git a/singlerelay.h b/singlerelay.h index 0f280cc..a5f9a49 100644 --- a/singlerelay.h +++ b/singlerelay.h @@ -7,15 +7,17 @@ namespace Ui { class SingleRelay; } -class SingleRelay : public QDialog -{ +class SingleRelay : public QDialog { Q_OBJECT -public: + public: explicit SingleRelay(QWidget *parent = nullptr); ~SingleRelay(); -private: + private slots: + void on_pushButton_cancel_clicked(); + + private: Ui::SingleRelay *ui; }; diff --git a/singlerelay.ui b/singlerelay.ui index 94a7707..9fd8699 100644 --- a/singlerelay.ui +++ b/singlerelay.ui @@ -76,12 +76,9 @@ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> -<html><head><meta name="qrichtext" content="1" /><meta charset="utf-8" /><style type="text/css"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } -hr { height: 1px; border-width: 0; } -li.unchecked::marker { content: "\2610"; } -li.checked::marker { content: "\2612"; } -</style></head><body style=" font-family:'Microsoft YaHei UI'; font-size:9pt; font-weight:400; font-style:normal;"> +</style></head><body style=" font-family:'SimSun'; font-size:9pt; font-weight:400; font-style:normal;"> <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'.AppleSystemUIFont'; font-size:13pt;">S02C01P##NO</span></p></body></html> @@ -99,6 +96,9 @@ li.checked::marker { content: "\2612"; } + + false + 510 @@ -349,6 +349,9 @@ li.checked::marker { content: "\2612"; } + + false + 600 @@ -387,23 +390,10 @@ li.checked::marker { content: "\2612"; } <--- - + - 320 - 530 - 81 - 32 - - - - 测点名称... - - - - - - 420 + 410 530 71 32 diff --git a/tachometer.cpp b/tachometer.cpp index 09b4ff8..9f8c7b5 100644 --- a/tachometer.cpp +++ b/tachometer.cpp @@ -7,12 +7,12 @@ #include #include -Tachometer::Tachometer(int slot_no_,QWidget *parent) +Tachometer::Tachometer(int slot_no_, QWidget *parent) : QDialog(parent) - , ui(new Ui::Tachometer) -{ + , ui(new Ui::Tachometer) { ui->setupUi(this); ui->widget_body->setProperty("flag", "body"); + setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); slot_no = slot_no_; QString slot = QString("%1").arg(slot_no); ui->label_slot->setText(slot); @@ -21,13 +21,10 @@ Tachometer::Tachometer(int slot_no_,QWidget *parent) Init(); } -Tachometer::~Tachometer() -{ - +Tachometer::~Tachometer() { delete ui; } -void Tachometer::readJsonFile(const QString &filePath) -{ +void Tachometer::readJsonFile(const QString &filePath) { QFile file(filePath); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { qDebug() << "Cannot open file for reading:" << filePath; @@ -47,7 +44,7 @@ void Tachometer::readJsonFile(const QString &filePath) } QJsonObject json_obj = jsonDoc.object(); QJsonArray chan_array = json_obj["chan"].toArray(); - for(int i = 0; i < chan_array.size(); i++){ + for (int i = 0; i < chan_array.size(); i++) { QJsonObject temp_obj = chan_array[i].toObject(); tachometer_variables[i].id = temp_obj["id"].toInt(); tachometer_variables[i].active = temp_obj["active"].toBool(); @@ -65,109 +62,115 @@ void Tachometer::readJsonFile(const QString &filePath) tachometer_variables[i].alert_response_time = temp_obj["alert_response_time"].toInt(); tachometer_variables[i].danger_response_time = temp_obj["danger_response_time"].toInt(); } - } -void Tachometer::Init() -{ +void Tachometer::Init() { for (int i = 0; i < CHANNLE_COUNT; i++) { - if(tachometer_variables[i].id == 1){ + if (tachometer_variables[i].id == 1) { ui->checkBox_chan_1->setChecked(tachometer_variables[i].active); ui->doubleSpinBox_high_1->setValue(tachometer_variables[i].normal_voltage_high); ui->doubleSpinBox_low_1->setValue(tachometer_variables[i].normal_voltage_low); - if(tachometer_variables[i].automatic_threshold) + if (tachometer_variables[i].automatic_threshold) { ui->radioButton_automatic_threshold_1->setChecked(true); - else + } else { ui->radioButton_manual_threshold_1->setChecked(true); + } ui->doubleSpinBox_threshold_1->setValue(tachometer_variables[i].threshold); ui->doubleSpinBox_hysteresis_1->setValue(tachometer_variables[i].hysteresis); ui->spinBox_events_per_revolution_1->setValue(tachometer_variables[i].events_per_revolution); ui->comboBox_record_output_1->setCurrentText(tachometer_variables[i].record_output); ui->checkBox_two_ma_clamp_1->setChecked(tachometer_variables[i].two_ma_clamp); - if(tachometer_variables[i].alert_latching) + if (tachometer_variables[i].alert_latching) { ui->radioButton_alert_latching_1->setCheckable(true); - else + } else { ui->radioButton_alert_latching_1->setCheckable(false); - if(tachometer_variables[i].overspeed_latching) + } + if (tachometer_variables[i].overspeed_latching) { ui->radioButton_overspeed_latching_1->setCheckable(true); - else + } else { ui->radioButton_overspeed_latching_1->setCheckable(false); + } } - if(tachometer_variables[i].id == 2){ + if (tachometer_variables[i].id == 2) { ui->checkBox_chan_2->setChecked(tachometer_variables[i].active); ui->doubleSpinBox_high_2->setValue(tachometer_variables[i].normal_voltage_high); ui->doubleSpinBox_low_2->setValue(tachometer_variables[i].normal_voltage_low); - if(tachometer_variables[i].automatic_threshold) + if (tachometer_variables[i].automatic_threshold) { ui->radioButton_automatic_threshold_2->setChecked(true); - else + } else { ui->radioButton_manual_threshold_2->setChecked(true); + } ui->doubleSpinBox_threshold_2->setValue(tachometer_variables[i].threshold); ui->doubleSpinBox_hysteresis_2->setValue(tachometer_variables[i].hysteresis); ui->spinBox_events_per_revolution_2->setValue(tachometer_variables[i].events_per_revolution); ui->comboBox_record_output_2->setCurrentText(tachometer_variables[i].record_output); ui->checkBox_two_ma_clamp_2->setChecked(tachometer_variables[i].two_ma_clamp); - if(tachometer_variables[i].alert_latching) + if (tachometer_variables[i].alert_latching) { ui->radioButton_alert_latching_2->setCheckable(true); - else + } else { ui->radioButton_alert_latching_2->setCheckable(false); - if(tachometer_variables[i].overspeed_latching) + } + if (tachometer_variables[i].overspeed_latching) { ui->radioButton_overspeed_latching_2->setCheckable(true); - else + } else { ui->radioButton_overspeed_latching_2->setCheckable(false); - + } } - if(tachometer_variables[i].id == 3){ + if (tachometer_variables[i].id == 3) { ui->checkBox_chan_3->setChecked(tachometer_variables[i].active); ui->doubleSpinBox_high_3->setValue(tachometer_variables[i].normal_voltage_high); ui->doubleSpinBox_low_3->setValue(tachometer_variables[i].normal_voltage_low); - if(tachometer_variables[i].automatic_threshold) + if (tachometer_variables[i].automatic_threshold) { ui->radioButton_automatic_threshold_3->setChecked(true); - else + } else { ui->radioButton_manual_threshold_3->setChecked(true); + } ui->doubleSpinBox_threshold_3->setValue(tachometer_variables[i].threshold); ui->doubleSpinBox_hysteresis_3->setValue(tachometer_variables[i].hysteresis); ui->spinBox_events_per_revolution_3->setValue(tachometer_variables[i].events_per_revolution); ui->comboBox_record_output_3->setCurrentText(tachometer_variables[i].record_output); ui->checkBox_two_ma_clamp_3->setChecked(tachometer_variables[i].two_ma_clamp); - if(tachometer_variables[i].alert_latching) + if (tachometer_variables[i].alert_latching) { ui->radioButton_alert_latching_3->setCheckable(true); - else + } else { ui->radioButton_alert_latching_3->setCheckable(false); - if(tachometer_variables[i].overspeed_latching) + } + if (tachometer_variables[i].overspeed_latching) { ui->radioButton_overspeed_latching_3->setCheckable(true); - else + } else { ui->radioButton_overspeed_latching_3->setCheckable(false); - + } } - if(tachometer_variables[i].id == 4){ + if (tachometer_variables[i].id == 4) { ui->checkBox_chan_4->setChecked(tachometer_variables[i].active); ui->doubleSpinBox_high_4->setValue(tachometer_variables[i].normal_voltage_high); ui->doubleSpinBox_low_4->setValue(tachometer_variables[i].normal_voltage_low); - if(tachometer_variables[i].automatic_threshold) + if (tachometer_variables[i].automatic_threshold) { ui->radioButton_automatic_threshold_4->setChecked(true); - else + } else { ui->radioButton_manual_threshold_4->setChecked(true); + } ui->doubleSpinBox_threshold_4->setValue(tachometer_variables[i].threshold); ui->doubleSpinBox_hysteresis_4->setValue(tachometer_variables[i].hysteresis); ui->spinBox_events_per_revolution_4->setValue(tachometer_variables[i].events_per_revolution); ui->comboBox_record_output_4->setCurrentText(tachometer_variables[i].record_output); ui->checkBox_two_ma_clamp_4->setChecked(tachometer_variables[i].two_ma_clamp); - if(tachometer_variables[i].alert_latching) + if (tachometer_variables[i].alert_latching) { ui->radioButton_alert_latching_4->setCheckable(true); - else + } else { ui->radioButton_alert_latching_4->setCheckable(false); - if(tachometer_variables[i].overspeed_latching) + } + if (tachometer_variables[i].overspeed_latching) { ui->radioButton_overspeed_latching_4->setCheckable(true); - else + } else { ui->radioButton_overspeed_latching_4->setCheckable(false); - + } } } } -void Tachometer::on_pushButton_confirm_clicked() -{ +void Tachometer::on_pushButton_confirm_clicked() { for (int i = 0; i < CHANNLE_COUNT; i++) { - if(tachometer_variables[i].id == 1){ + if (tachometer_variables[i].id == 1) { tachometer_variables[i].active = ui->checkBox_chan_1->isChecked(); tachometer_variables[i].normal_voltage_high = ui->doubleSpinBox_high_1->value(); tachometer_variables[i].normal_voltage_low = ui->doubleSpinBox_low_1->value(); @@ -180,7 +183,7 @@ void Tachometer::on_pushButton_confirm_clicked() tachometer_variables[i].alert_latching = ui->radioButton_alert_latching_1->isChecked(); tachometer_variables[i].overspeed_latching = ui->radioButton_overspeed_latching_1->isChecked(); } - if(tachometer_variables[i].id == 2){ + if (tachometer_variables[i].id == 2) { tachometer_variables[i].active = ui->checkBox_chan_2->isChecked(); tachometer_variables[i].normal_voltage_high = ui->doubleSpinBox_high_2->value(); tachometer_variables[i].normal_voltage_low = ui->doubleSpinBox_low_2->value(); @@ -193,7 +196,7 @@ void Tachometer::on_pushButton_confirm_clicked() tachometer_variables[i].alert_latching = ui->radioButton_alert_latching_2->isChecked(); tachometer_variables[i].overspeed_latching = ui->radioButton_overspeed_latching_2->isChecked(); } - if(tachometer_variables[i].id == 3){ + if (tachometer_variables[i].id == 3) { tachometer_variables[i].active = ui->checkBox_chan_3->isChecked(); tachometer_variables[i].normal_voltage_high = ui->doubleSpinBox_high_3->value(); tachometer_variables[i].normal_voltage_low = ui->doubleSpinBox_low_3->value(); @@ -206,7 +209,7 @@ void Tachometer::on_pushButton_confirm_clicked() tachometer_variables[i].alert_latching = ui->radioButton_alert_latching_3->isChecked(); tachometer_variables[i].overspeed_latching = ui->radioButton_overspeed_latching_3->isChecked(); } - if(tachometer_variables[i].id == 4){ + if (tachometer_variables[i].id == 4) { tachometer_variables[i].active = ui->checkBox_chan_4->isChecked(); tachometer_variables[i].normal_voltage_high = ui->doubleSpinBox_high_4->value(); tachometer_variables[i].normal_voltage_low = ui->doubleSpinBox_low_4->value(); @@ -223,8 +226,7 @@ void Tachometer::on_pushButton_confirm_clicked() QString slot = QString("%1").arg(slot_no); QString filePath_tachometer = QCoreApplication::applicationDirPath() + QString("\\config\\%1\\tachometer.json").arg(slot_no); QFile file(filePath_tachometer); - if(!file.open(QIODevice::WriteOnly)) - { + if (!file.open(QIODevice::WriteOnly)) { qDebug() << "Could not open file for writing"; return; } @@ -251,9 +253,9 @@ void Tachometer::on_pushButton_confirm_clicked() chan_array.append(temp_obj); } json_obj.insert("chan", chan_array); - json_obj.insert("version",1); - json_obj.insert("slot",slot_no); - json_obj.insert("card_type",2); + json_obj.insert("version", 1); + json_obj.insert("slot", slot_no); + json_obj.insert("card_type", 2); QJsonDocument json_doc; json_doc.setObject(json_obj); QByteArray byte_array = json_doc.toJson(); @@ -261,3 +263,7 @@ void Tachometer::on_pushButton_confirm_clicked() file.close(); } +void Tachometer::on_pushButton_cancel_clicked() { + this->close(); +} + diff --git a/tachometer.h b/tachometer.h index 9df2cec..e705cec 100644 --- a/tachometer.h +++ b/tachometer.h @@ -7,18 +7,18 @@ namespace Ui { class Tachometer; } -class Tachometer : public QDialog -{ +class Tachometer : public QDialog { Q_OBJECT -public: - explicit Tachometer(int slot_no_,QWidget *parent = nullptr); + public: + explicit Tachometer(int slot_no_, QWidget *parent = nullptr); ~Tachometer(); int slot_no; -private slots: + private slots: void on_pushButton_confirm_clicked(); + void on_pushButton_cancel_clicked(); -private: + private: Ui::Tachometer *ui; Tachometer_Variables tachometer_variables[4]; diff --git a/tachometer.ui b/tachometer.ui index 7af30c2..2790757 100644 --- a/tachometer.ui +++ b/tachometer.ui @@ -23,9 +23,12 @@ + + false + - 440 + 420 550 71 32 @@ -51,10 +54,10 @@ true - + - 350 + 260 550 71 32 @@ -80,7 +83,7 @@ - 630 + 610 550 91 32 @@ -107,9 +110,12 @@ + + false + - 530 + 510 550 81 32 @@ -122,7 +128,7 @@ - 120 + 130 550 101 32 @@ -197,6 +203,18 @@ 16777215 + + 1 + + + -50.000000000000000 + + + 50.000000000000000 + + + -25.000000000000000 + @@ -219,6 +237,18 @@ 16777215 + + 1 + + + -50.000000000000000 + + + 50.000000000000000 + + + 25.000000000000000 + @@ -675,6 +705,9 @@ + + false + 180 @@ -691,6 +724,9 @@ + + false + 180 @@ -745,6 +781,18 @@ 16777215 + + 1 + + + -50.000000000000000 + + + 50.000000000000000 + + + -25.000000000000000 + @@ -767,6 +815,18 @@ 16777215 + + 1 + + + -50.000000000000000 + + + 50.000000000000000 + + + 25.000000000000000 + @@ -1275,6 +1335,18 @@ 16777215 + + 1 + + + -50.000000000000000 + + + 50.000000000000000 + + + -25.000000000000000 + @@ -1297,6 +1369,18 @@ 16777215 + + 1 + + + -50.000000000000000 + + + 50.000000000000000 + + + 25.000000000000000 + @@ -1805,6 +1889,18 @@ 16777215 + + 1 + + + -50.000000000000000 + + + 50.000000000000000 + + + -25.000000000000000 + @@ -1827,6 +1923,21 @@ 16777215 + + 1 + + + -50.000000000000000 + + + 50.000000000000000 + + + 1.000000000000000 + + + 25.000000000000000 + @@ -2315,19 +2426,6 @@ true - - - - 240 - 550 - 81 - 32 - - - - 测点名称 - - @@ -2372,8 +2470,8 @@ + - diff --git a/tmrrelayassociation.ui b/tmrrelayassociation.ui index 5063c58..c3c571b 100644 --- a/tmrrelayassociation.ui +++ b/tmrrelayassociation.ui @@ -592,20 +592,10 @@ - - - - 330 - 540 - 81 - 32 - - - - 测点名称... - - + + false + 520 @@ -632,6 +622,9 @@ + + false + 610 @@ -644,10 +637,10 @@ 帮 助 - + - 430 + 410 540 71 32