From 95156105a31a61f3f1115f97c0018d6da91a95fa Mon Sep 17 00:00:00 2001 From: zhangsheng Date: Tue, 2 Sep 2025 19:32:01 +0800 Subject: [PATCH] add group,add vote relay --- config_mgr.cpp | 36 ++++-- data_config.h | 5 + keyphase.ui | 81 +++++++++---- seismic_monitor.ui | 105 ++++++++++++----- singlerelay.cpp | 66 ++++++++++- singlerelay.h | 5 + singlerelay.ui | 280 +++++++++++++++++++++++++++++++++++++++------ tachometer.ui | 62 ++++++++-- 8 files changed, 535 insertions(+), 105 deletions(-) diff --git a/config_mgr.cpp b/config_mgr.cpp index c7a3677..536a988 100644 --- a/config_mgr.cpp +++ b/config_mgr.cpp @@ -575,12 +575,25 @@ void ConfigMgr::Save(QString & file_path) { continue; } std::shared_ptr ptr = std::dynamic_pointer_cast(base_ptr); - if(ptr->single_relay[ch].logic_expression != ""){ - qDebug() << "ch" << ch << ptr->single_relay[ch].logic_expression; - channel_item.insert("logic_expression", ptr->single_relay[ch].logic_expression); - channel_item.insert("active", ptr->single_relay[ch].active); - } + if(ptr->single_relay[ch].vote){ + channel_item.insert("count_vote",ptr->single_relay[ch].count_vote); + QJsonArray array_logic; + for(int var = 0 ; var < 10;++var){ + if(ptr->single_relay[ch].logic[var] != ""){ + array_logic.append(ptr->single_relay[ch].logic[var]); + } + } + channel_item.insert("logic_vote", array_logic); + }else{ + if(ptr->single_relay[ch].logic_expression != ""){ + qDebug() << "ch" << ch << ptr->single_relay[ch].logic_expression; + channel_item.insert("logic_expression", ptr->single_relay[ch].logic_expression); + } + } + channel_item.insert("vote",ptr->single_relay[ch].vote); + channel_item.insert("active", ptr->single_relay[ch].active); + channel_item.insert("group",ptr->single_relay[ch].group); } if(!channel_item.isEmpty() ){ slot_item[QString::number(ch + 1)] = channel_item; @@ -1084,9 +1097,18 @@ void ConfigMgr::Load(QString filename) { singlerelay_data->version_ = temp_obj["version"].toInt(); for (int j = 0; j < RELAY_COUNT; ++j) { channel = temp_obj[QString::number(j + 1)].toObject(); - singlerelay_data->single_relay[j].logic_expression = channel["logic_expression"].toString(); + if(channel["vote"].toBool()){ + singlerelay_data->single_relay[j].count_vote = channel["count_vote"].toInt(); + singlerelay_data->single_relay[j].vote = channel["vote"].toBool(); + QJsonArray array_logic = channel["logic_vote"].toArray(); + for(int var = 0;var < array_logic.size();++var){ + singlerelay_data->single_relay[j].logic[var] = array_logic[var].toString(); + } + }else{ + singlerelay_data->single_relay[j].logic_expression = channel["logic_expression"].toString(); + } singlerelay_data->single_relay[j].active = channel["active"].toBool(); - + singlerelay_data->single_relay[j].group = channel["group"].toInt(); } cards_.push_back(singlerelay_data); } diff --git a/data_config.h b/data_config.h index 9fb400b..4cb878b 100644 --- a/data_config.h +++ b/data_config.h @@ -497,9 +497,14 @@ typedef struct SpeedAlert_{ typedef struct SingleRelayNOK_{ QString logic_expression; bool active; + int group; + bool vote; + QString logic[10]; + int count_vote; SingleRelayNOK_(){ logic_expression = ""; active = false; + vote = false; } } SingleRelayNOK; diff --git a/keyphase.ui b/keyphase.ui index 7ff29bc..5e7049a 100644 --- a/keyphase.ui +++ b/keyphase.ui @@ -34,9 +34,9 @@ - + - + @@ -51,19 +51,10 @@ - - - - Qt::Horizontal - - - - 40 - 20 - - - - + + + + @@ -78,21 +69,67 @@ + + + + - - - Qt::Horizontal + + + 分组: - + + + + + - 40 - 20 + 50 + 0 - + + + 1 + + + + + 2 + + + + + 3 + + + + + 4 + + + + + 5 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + diff --git a/seismic_monitor.ui b/seismic_monitor.ui index adec544..aabd2c0 100644 --- a/seismic_monitor.ui +++ b/seismic_monitor.ui @@ -46,32 +46,85 @@ 50 - - - - 10 - 20 - 113 - 21 - - - - - - - 槽位号: - - - - - - - 7 - - - - - + + + + + + + 槽位号: + + + + + + + 7 + + + + + + + + + + + 分组: + + + + + + + + 50 + 0 + + + + + 1 + + + + + 2 + + + + + 3 + + + + + 4 + + + + + 5 + + + + + + + + + + Qt::Horizontal + + + + 709 + 20 + + + + + diff --git a/singlerelay.cpp b/singlerelay.cpp index f414c43..bf145e4 100644 --- a/singlerelay.cpp +++ b/singlerelay.cpp @@ -52,6 +52,7 @@ SingleRelay::SingleRelay(int slot,int cardtype,QWidget *parent) treeView_relay->setContextMenuPolicy(Qt::CustomContextMenu); connect(treeView_relay,&QTreeView::customContextMenuRequested,this,&SingleRelay::on_treeView_Relay_customContextMenuRequested); current_index = ui->comboBox_relay_ch->currentIndex(); + vote_current_index = ui->comboBox_vote_group->currentIndex(); Init(); onComboBoxIndexChanged(current_index); @@ -149,6 +150,7 @@ void SingleRelay::Init(){ setExpressionToTreeView(treeView_relay, relay_data->single_relay[current_index].logic_expression); } ui->checkBox_active->setChecked(relay_data->single_relay[current_index].active); + ui->comboBox_group->setCurrentIndex(relay_data->single_relay[current_index].group - 1); } void SingleRelay::on_pushButton_cancel_clicked() { this->close(); @@ -272,8 +274,13 @@ void SingleRelay::on_pushButton_confirm_clicked() QString("错误位置:%1\n错误描述:%2").arg(result.errorPos).arg(result.errorMsg)); return; } - relay_data->single_relay[current_index].logic_expression = finalExpr; + if(ui->checkBox_vote->checkState()){ + relay_data->single_relay[current_index].logic[ui->comboBox_vote_group->currentIndex()] = finalExpr; + }else{ + relay_data->single_relay[current_index].logic_expression = finalExpr; + } relay_data->single_relay[current_index].active = ui->checkBox_active->isChecked(); + relay_data->single_relay[current_index].group = ui->comboBox_group->currentIndex() + 1; qDebug() << "逻辑表达式:" << finalExpr; this->close(); } @@ -297,15 +304,25 @@ void SingleRelay::onComboBoxIndexChanged(int index){ return; } qDebug() << "finalExpr" << finalExpr; - relay_data->single_relay[current_index].logic_expression = finalExpr; + if(ui->checkBox_vote->checkState()){ + relay_data->single_relay[current_index].logic[ui->comboBox_vote_group->currentIndex()] = finalExpr; + if(relay_data->single_relay[index].logic[ui->comboBox_vote_group->currentIndex()] != "") + setExpressionToTreeView(treeView_relay, relay_data->single_relay[index].logic[ui->comboBox_vote_group->currentIndex()]); + else + model_Relay->clear(); + }else{ + relay_data->single_relay[current_index].logic_expression = finalExpr; + if(relay_data->single_relay[index].logic_expression != "") + setExpressionToTreeView(treeView_relay, relay_data->single_relay[index].logic_expression); + else + model_Relay->clear(); + } relay_data->single_relay[current_index].active = ui->checkBox_active->isChecked(); + relay_data->single_relay[current_index].group = ui->comboBox_group->currentIndex() + 1; current_index = index; qDebug() << "active" << relay_data->single_relay[index].active; ui->checkBox_active->setChecked(relay_data->single_relay[index].active); - if(relay_data->single_relay[index].logic_expression != "") - setExpressionToTreeView(treeView_relay, relay_data->single_relay[index].logic_expression); - else - model_Relay->clear(); + } ExprNode* SingleRelay::parseExpression(const QString& expr, int& pos) { auto skipSpaces = [&]() { @@ -477,3 +494,40 @@ void SingleRelay::on_treeView_Relay_customContextMenuRequested(const QPoint &pos } menu.exec(QCursor::pos()); //显示菜单 } + +void SingleRelay::on_checkBox_vote_clicked(bool checked) +{ + if(checked){ + ui->comboBox_vote_group->setEnabled(true); + }else{ + ui->comboBox_vote_group->setEnabled(false); + } +} + + +void SingleRelay::on_comboBox_vote_group_currentIndexChanged(int index) +{ + QStandardItemModel *model = qobject_cast(treeView_relay->model()); + if (!model) return; + QStandardItem *root = model->invisibleRootItem(); + QString finalExpr; + for (int i = 0; i < root->rowCount(); ++i) { + QStandardItem *topItem = root->child(i); + QString expr = buildLogicExpression(topItem); + finalExpr += expr; + } + ExprValidationResult result = validateLogicExpression(finalExpr); + if (!result.isValid && !finalExpr.isEmpty()) { + QMessageBox::warning(this, "表达式错误", + QString("错误位置:%1\n错误描述:%2").arg(result.errorPos).arg(result.errorMsg)); + return; + } + qDebug() << "finalExpr" << finalExpr; + relay_data->single_relay[current_index].logic[vote_current_index] = finalExpr; + if(relay_data->single_relay[current_index].logic[index] != "") + setExpressionToTreeView(treeView_relay, relay_data->single_relay[current_index].logic[index]); + else + model_Relay->clear(); + vote_current_index = index; +} + diff --git a/singlerelay.h b/singlerelay.h index 34fd5ee..710e45d 100644 --- a/singlerelay.h +++ b/singlerelay.h @@ -34,6 +34,10 @@ class SingleRelay : public QDialog { void on_treeView_Relay_customContextMenuRequested(const QPoint &pos); + void on_checkBox_vote_clicked(bool checked); + + void on_comboBox_vote_group_currentIndexChanged(int index); + private: Ui::SingleRelay *ui; QButtonGroup * btnGroup_slot = nullptr; @@ -42,6 +46,7 @@ private: QStandardItemModel *model_Relay; std::shared_ptr relay_data = nullptr; int current_index; + int vote_current_index; QMap channelNameMap; void Init(); diff --git a/singlerelay.ui b/singlerelay.ui index 525147a..a01b999 100644 --- a/singlerelay.ui +++ b/singlerelay.ui @@ -17,7 +17,7 @@ 620 - 20 + 180 91 16 @@ -30,7 +30,7 @@ 230 - 350 + 340 111 16 @@ -43,7 +43,7 @@ 10 - 360 + 350 201 151 @@ -51,15 +51,113 @@ 继电器关联 - + 20 - 30 - 103 - 32 + 120 + 85 + 20 + + 激活 + + + + + + 10 + 70 + 42 + 16 + + + + 分组: + + + + + + 60 + 60 + 101 + 30 + + + + + 50 + 30 + + + + + 16777215 + 30 + + + + + 1 + + + + + 2 + + + + + 3 + + + + + 4 + + + + + 5 + + + + + + + 10 + 30 + 42 + 16 + + + + 通道: + + + + + + 60 + 20 + 103 + 30 + + + + + 50 + 30 + + + + + 16777215 + 30 + + 通道 1 @@ -141,32 +239,6 @@ - - - - 26 - 70 - 85 - 20 - - - - 激活 - - - - - - 140 - 40 - 71 - 16 - - - - 成组 - - @@ -824,7 +896,7 @@ 620 - 40 + 200 341 301 @@ -834,8 +906,8 @@ 230 - 370 - 391 + 360 + 381 141 @@ -926,6 +998,142 @@ + + + + 640 + 30 + 71 + 16 + + + + 是否投票 + + + + + + 630 + 70 + 100 + 32 + + + + + + + 逻辑: + + + + + + + false + + + + 50 + 30 + + + + + 16777215 + 30 + + + + + 1 + + + + + 2 + + + + + 3 + + + + + 4 + + + + + 5 + + + + + 6 + + + + + 7 + + + + + 8 + + + + + 9 + + + + + 10 + + + + + + + + + + 631 + 131 + 100 + 27 + + + + + + + 选择: + + + + + + + + 50 + 25 + + + + + 50 + 25 + + + + + + diff --git a/tachometer.ui b/tachometer.ui index 0ac1d8a..af953d6 100644 --- a/tachometer.ui +++ b/tachometer.ui @@ -19,7 +19,7 @@ - + @@ -36,21 +36,67 @@ + + + + - - - Qt::Horizontal + + + 分组: - + + + + + - 40 - 20 + 50 + 0 - + + + 1 + + + + + 2 + + + + + 3 + + + + + 4 + + + + + 5 + + + + + + + Qt::Horizontal + + + + 604 + 20 + + + +