From 13510306d85f119680145b006fc56af1f00753af Mon Sep 17 00:00:00 2001 From: zhangsheng Date: Thu, 9 Apr 2026 16:06:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8C=AF=E5=8A=A8=E6=9D=BF=E5=8D=A1=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E7=BB=A7=E7=94=B5=E5=99=A8=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config_mgr.cpp | 70 ++++++++++++++++++++++++++--- mainwindow.cpp | 5 ++- singlerelay.cpp | 117 +++++++++++++++++++++++++++++++----------------- singlerelay.h | 3 ++ vibrationdata.h | 2 + 5 files changed, 149 insertions(+), 48 deletions(-) diff --git a/config_mgr.cpp b/config_mgr.cpp index 738f259..b169371 100644 --- a/config_mgr.cpp +++ b/config_mgr.cpp @@ -558,13 +558,49 @@ int ConfigMgr::Save(QString & file_path) { channel_item.insert("fail",ptr->variables_[cid].fail); } - slot_item[QString::number(cid + 1)] = channel_item; - slot_item["dc_output"] = dc_output; - } - slot_item["version"] = 1; - slot_item["relative_number"] = base_ptr->relative_number; - slot_item["group"] = base_ptr->group; - }else{ + slot_item[QString::number(cid + 1)] = channel_item; + slot_item["dc_output"] = dc_output; + } + if (card_type_[i] == kCardVibSingle || + card_type_[i] == kCardVibTMRPrimary) { + std::shared_ptr ptr = std::dynamic_pointer_cast(base_ptr); + if (ptr != nullptr) { + QJsonObject relay_item; + for (int ch = 0; ch < RELAY_COUNT; ++ch) { + QJsonObject channel_item; + 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("active", ptr->single_relay[ch].active); + channel_item.insert("group",ptr->single_relay[ch].group); + channel_item.insert("logic_vote", array_logic); + channel_item.insert("vote",ptr->single_relay[ch].vote); + } + } + } else { + if (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()) { + relay_item[QString::number(ch + 1)] = channel_item; + } + } + if (!relay_item.isEmpty()) { + slot_item["relay"] = relay_item; + } + } + } + slot_item["version"] = 1; + slot_item["relative_number"] = base_ptr->relative_number; + slot_item["group"] = base_ptr->group; + }else{ for(int ch = 0;ch < RELAY_COUNT;++ch){ QJsonObject channel_item; if(card_type_[i] == kCardRelaySingle){ @@ -1051,6 +1087,26 @@ void ConfigMgr::Load(QString filename) { } } } + QJsonObject relay_obj = temp_obj["relay"].toObject(); + if (!relay_obj.isEmpty()) { + for (int j = 0; j < RELAY_COUNT; ++j) { + channel = relay_obj[QString::number(j + 1)].toObject(); + if(channel.isEmpty()) + continue; + if(channel["vote"].toBool()){ + vib_data->single_relay[j].count_vote = channel["count_vote"].toInt(); + vib_data->single_relay[j].vote = channel["vote"].toBool(); + QJsonArray array_logic = channel["logic_vote"].toArray(); + for(int var = 0;var < array_logic.size();++var){ + vib_data->single_relay[j].logic[var] = array_logic[var].toString(); + } + }else{ + vib_data->single_relay[j].logic_expression = channel["logic_expression"].toString(); + } + vib_data->single_relay[j].active = channel["active"].toBool(); + vib_data->single_relay[j].group = channel["group"].toInt(); + } + } cards_.push_back(vib_data); } else if (card_type_[i] == kCardSpeedSingle || card_type_[i] == kCardSpeedTMRPrimary) { diff --git a/mainwindow.cpp b/mainwindow.cpp index ac3ae4c..293da2c 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -1123,7 +1123,7 @@ void MainWindow::MoveSubCard(int slot){ void MainWindow::VibRealy(int slot){ slot_no = slot; std::shared_ptr base_ptr = ConfigMgr::Instance()->GetSlotPtr(slot_no); - if(base_ptr != nullptr){ + if(base_ptr == nullptr){ QMessageBox::warning(this, QStringLiteral("警告"), QStringLiteral("当前板卡为空板卡!")); return ; } @@ -1131,6 +1131,9 @@ void MainWindow::VibRealy(int slot){ QMessageBox::warning(this, QStringLiteral("警告"), QStringLiteral("请选择振动板卡进行配置!")); return ; } + SingleRelay *single_relay = new SingleRelay(slot_no, base_ptr->card_type_); + single_relay->setWindowModality(Qt::ApplicationModal); + single_relay->show(); } void MainWindow::readData(const QByteArray &data) { qDebug() << "Received from server:" << data; diff --git a/singlerelay.cpp b/singlerelay.cpp index 02eb19e..9533a41 100644 --- a/singlerelay.cpp +++ b/singlerelay.cpp @@ -14,6 +14,11 @@ SingleRelay::SingleRelay(int slot,CardType cardtype,QWidget *parent) car_type = cardtype; ui->label_slot_no->setText(QString::number(slot_no)); ui->comboBox_relay_ch->setView(new QListView()); + if (car_type == kCardVibSingle) { + for (int i = ui->comboBox_relay_ch->count() - 1; i >= 4; --i) { + ui->comboBox_relay_ch->removeItem(i); + } + } setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); QVBoxLayout *layout_available = new QVBoxLayout(ui->widget_available); list_widget_available = new QListWidget(); @@ -95,17 +100,33 @@ void SingleRelay::Init(){ } std::shared_ptr base_ptr = ConfigMgr::Instance()->GetSlotPtr(slot_no); if (base_ptr == nullptr) { - // do nothing or use template to init it. - relay_data = std::make_shared(); - relay_data->card_type_ = car_type; - relay_data->slot_ = slot_no; - ConfigMgr::Instance()->AddCard(relay_data); + if (car_type == kCardVibSingle) { + vib_data = std::make_shared(); + vib_data->card_type_ = car_type; + vib_data->slot_ = slot_no; + ConfigMgr::Instance()->AddCard(vib_data); + } else { + // do nothing or use template to init it. + relay_data = std::make_shared(); + relay_data->card_type_ = car_type; + relay_data->slot_ = slot_no; + ConfigMgr::Instance()->AddCard(relay_data); + } return; } - relay_data = std::dynamic_pointer_cast(base_ptr); + if (base_ptr->card_type_ == kCardVibSingle) { + vib_data = std::dynamic_pointer_cast(base_ptr); + } else { + relay_data = std::dynamic_pointer_cast(base_ptr); + } - qDebug() << "logic" <single_relay[current_index].logic_expression; - qDebug() << "active" <single_relay[current_index].active << "index" << current_index; + SingleRelayS *relay = relayArray(); + if (!relay) { + return; + } + + qDebug() << "logic" << relay[current_index].logic_expression; + qDebug() << "active" << relay[current_index].active << "index" << current_index; for(int i = 0 ; i < SLOT_NUM ; i++){ std::shared_ptr cardbase_ptr = ConfigMgr::Instance()->GetSlotPtr(i + 1); @@ -148,20 +169,27 @@ void SingleRelay::Init(){ cardbase_ptr->card_type_ == kCardSpeedSingle){ } } - if(!relay_data->single_relay[current_index].logic_expression.isEmpty()){ - setExpressionToTreeView(treeView_relay, relay_data->single_relay[current_index].logic_expression); + if(!relay[current_index].logic_expression.isEmpty()){ + setExpressionToTreeView(treeView_relay, relay[current_index].logic_expression); } - if(!relay_data->single_relay[current_index].logic[vote_current_index].isEmpty()){ - setExpressionToTreeView(treeView_relay, relay_data->single_relay[current_index].logic[vote_current_index]); + if(!relay[current_index].logic[vote_current_index].isEmpty()){ + setExpressionToTreeView(treeView_relay, relay[current_index].logic[vote_current_index]); } - qDebug() << "relay_data->single_relay[current_index].active" << relay_data->single_relay[current_index].active; - ui->checkBox_active->setChecked(relay_data->single_relay[current_index].active); - ui->comboBox_group->setCurrentIndex(relay_data->single_relay[current_index].group - 1); - ui->lineEdit_vote_count->setText(QString::number(relay_data->single_relay[current_index].count_vote)); - ui->checkBox_vote->setChecked(relay_data->single_relay[current_index].vote); - on_checkBox_vote_clicked(relay_data->single_relay[current_index].vote); + qDebug() << "relay_data->single_relay[current_index].active" << relay[current_index].active; + ui->checkBox_active->setChecked(relay[current_index].active); + ui->comboBox_group->setCurrentIndex(relay[current_index].group - 1); + ui->lineEdit_vote_count->setText(QString::number(relay[current_index].count_vote)); + ui->checkBox_vote->setChecked(relay[current_index].vote); + on_checkBox_vote_clicked(relay[current_index].vote); } + +SingleRelayS* SingleRelay::relayArray() { + if (vib_data) { + return vib_data->single_relay; + } + return relay_data ? relay_data->single_relay : nullptr; +} void SingleRelay::on_pushButton_cancel_clicked() { this->close(); } @@ -268,6 +296,9 @@ QString SingleRelay::buildLogicExpression(QStandardItem *item) { } void SingleRelay::on_pushButton_confirm_clicked() { + SingleRelayS *relay = relayArray(); + if (!relay) return; + QStandardItemModel *model = qobject_cast(treeView_relay->model()); if (!model) return; @@ -285,15 +316,15 @@ void SingleRelay::on_pushButton_confirm_clicked() return; } if(ui->checkBox_vote->isChecked()){ - relay_data->single_relay[current_index].logic[ui->comboBox_vote_group->currentIndex()] = finalExpr; - relay_data->single_relay[current_index].count_vote = ui->lineEdit_vote_count->text().toInt(); + relay[current_index].logic[ui->comboBox_vote_group->currentIndex()] = finalExpr; + relay[current_index].count_vote = ui->lineEdit_vote_count->text().toInt(); }else{ - relay_data->single_relay[current_index].logic_expression = finalExpr; + relay[current_index].logic_expression = finalExpr; } - relay_data->single_relay[current_index].active = ui->checkBox_active->isChecked(); - relay_data->single_relay[current_index].vote = ui->checkBox_vote->isChecked(); - relay_data->single_relay[current_index].group = ui->comboBox_group->currentIndex() + 1; - relay_data->single_relay[current_index].count_vote = ui->lineEdit_vote_count->text().toInt(); + relay[current_index].active = ui->checkBox_active->isChecked(); + relay[current_index].vote = ui->checkBox_vote->isChecked(); + relay[current_index].group = ui->comboBox_group->currentIndex() + 1; + relay[current_index].count_vote = ui->lineEdit_vote_count->text().toInt(); qDebug() << "逻辑表达式:" << finalExpr ; this->close(); } @@ -301,6 +332,9 @@ void SingleRelay::onComboBoxIndexChanged(int index){ qDebug()<< "[SingleRelay]:index " << index; + SingleRelayS *relay = relayArray(); + if (!relay) return; + QStandardItemModel *model = qobject_cast(treeView_relay->model()); if (!model) return; QStandardItem *root = model->invisibleRootItem(); @@ -318,25 +352,25 @@ void SingleRelay::onComboBoxIndexChanged(int index){ } qDebug() << "finalExpr" << finalExpr; if(ui->checkBox_vote->isChecked()){ - relay_data->single_relay[current_index].logic[vote_current_index] = finalExpr; - if(relay_data->single_relay[index].logic[0] != "") - setExpressionToTreeView(treeView_relay, relay_data->single_relay[index].logic[ui->comboBox_vote_group->currentIndex()]); + relay[current_index].logic[vote_current_index] = finalExpr; + if(relay[index].logic[0] != "") + setExpressionToTreeView(treeView_relay, 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); + relay[current_index].logic_expression = finalExpr; + if(relay[index].logic_expression != "") + setExpressionToTreeView(treeView_relay, relay[index].logic_expression); else model_Relay->clear(); } - relay_data->single_relay[current_index].vote = ui->checkBox_vote->isChecked(); - relay_data->single_relay[current_index].group = ui->comboBox_group->currentIndex() + 1; - relay_data->single_relay[current_index].count_vote = ui->lineEdit_vote_count->text().toInt(); + relay[current_index].vote = ui->checkBox_vote->isChecked(); + relay[current_index].group = ui->comboBox_group->currentIndex() + 1; + relay[current_index].count_vote = ui->lineEdit_vote_count->text().toInt(); current_index = index; - qDebug() << "active" << relay_data->single_relay[index].active; - ui->checkBox_active->setChecked(relay_data->single_relay[index].active); - ui->lineEdit_vote_count->setText(QString::number(relay_data->single_relay[index].count_vote)); + qDebug() << "active" << relay[index].active; + ui->checkBox_active->setChecked(relay[index].active); + ui->lineEdit_vote_count->setText(QString::number(relay[index].count_vote)); } ExprNode* SingleRelay::parseExpression(const QString& expr, int& pos) { @@ -522,6 +556,9 @@ void SingleRelay::on_checkBox_vote_clicked(bool checked) void SingleRelay::on_comboBox_vote_group_currentIndexChanged(int index) { + SingleRelayS *relay = relayArray(); + if (!relay) return; + QStandardItemModel *model = qobject_cast(treeView_relay->model()); if (!model) return; QStandardItem *root = model->invisibleRootItem(); @@ -538,9 +575,9 @@ void SingleRelay::on_comboBox_vote_group_currentIndexChanged(int index) return; } qDebug() << "finalExpr" << finalExpr << index; - 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]); + relay[current_index].logic[vote_current_index] = finalExpr; + if(relay[current_index].logic[index] != "") + setExpressionToTreeView(treeView_relay, relay[current_index].logic[index]); else model_Relay->clear(); vote_current_index = index; diff --git a/singlerelay.h b/singlerelay.h index f80a7a5..b593924 100644 --- a/singlerelay.h +++ b/singlerelay.h @@ -14,6 +14,7 @@ namespace Ui { class SingleRelay; } +class VibrationData; class SingleRelay : public QDialog { Q_OBJECT @@ -45,12 +46,14 @@ private: QTreeView *treeView_relay; QStandardItemModel *model_Relay; std::shared_ptr relay_data = nullptr; + std::shared_ptr vib_data = nullptr; int current_index; int vote_current_index; QMap channelNameMap; void Init(); void buildTreeFromExpression(QTreeView *treeView, const QString &expr); + SingleRelayS* relayArray(); ExprNode* parseExpression(const QString& expr, int& pos); QStandardItem* buildItemTree(ExprNode* node); void setExpressionToTreeView(QTreeView* treeView, const QString& expr); diff --git a/vibrationdata.h b/vibrationdata.h index 207662c..3dc2ab4 100644 --- a/vibrationdata.h +++ b/vibrationdata.h @@ -20,6 +20,8 @@ class VibrationData : public CardBase { VibAlertDanger alert_danger[CHANNEL_COUNT]; VibAlertDangerPress alert_danger_press[CHANNEL_COUNT]; DCOutput dc_output[CHANNEL_COUNT]; + + SingleRelayS single_relay[RELAY_COUNT]; }; #endif // VIBRATIONDATA_H