add group,add vote relay

This commit is contained in:
zhangsheng 2025-09-02 19:32:01 +08:00
parent f59b9dff3d
commit 95156105a3
8 changed files with 535 additions and 105 deletions

View File

@ -575,13 +575,26 @@ void ConfigMgr::Save(QString & file_path) {
continue;
}
std::shared_ptr<SingleRelayData> ptr = std::dynamic_pointer_cast<SingleRelayData>(base_ptr);
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("active", ptr->single_relay[ch].active);
}
}
}
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();
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);
}

View File

@ -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;

View File

@ -34,9 +34,9 @@
<layout class="QVBoxLayout" name="verticalLayout_15">
<item>
<widget class="QWidget" name="widget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_31">
<layout class="QHBoxLayout" name="horizontalLayout_34">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<layout class="QHBoxLayout" name="horizontalLayout_33">
<item>
<widget class="QLabel" name="label">
<property name="text">
@ -51,19 +51,10 @@
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_31">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
@ -78,8 +69,56 @@
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="horizontalSpacer_2">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string> 分组:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox_3">
<property name="minimumSize">
<size>
<width>50</width>
<height>0</height>
</size>
</property>
<item>
<property name="text">
<string>1</string>
</property>
</item>
<item>
<property name="text">
<string>2</string>
</property>
</item>
<item>
<property name="text">
<string>3</string>
</property>
</item>
<item>
<property name="text">
<string>4</string>
</property>
</item>
<item>
<property name="text">
<string>5</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
@ -92,8 +131,6 @@
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>

View File

@ -46,15 +46,8 @@
<height>50</height>
</size>
</property>
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>10</x>
<y>20</y>
<width>113</width>
<height>21</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_42">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
@ -71,7 +64,67 @@
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_41">
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string> 分组:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox_3">
<property name="minimumSize">
<size>
<width>50</width>
<height>0</height>
</size>
</property>
<item>
<property name="text">
<string>1</string>
</property>
</item>
<item>
<property name="text">
<string>2</string>
</property>
</item>
<item>
<property name="text">
<string>3</string>
</property>
</item>
<item>
<property name="text">
<string>4</string>
</property>
</item>
<item>
<property name="text">
<string>5</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>709</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>

View File

@ -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;
}
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,16 +304,26 @@ void SingleRelay::onComboBoxIndexChanged(int index){
return;
}
qDebug() << "finalExpr" << 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;
relay_data->single_relay[current_index].active = ui->checkBox_active->isChecked();
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();
}
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);
}
ExprNode* SingleRelay::parseExpression(const QString& expr, int& pos) {
auto skipSpaces = [&]() {
while (pos < expr.length() && expr[pos].isSpace()) pos++;
@ -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<QStandardItemModel *>(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;
}

View File

@ -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<SingleRelayData> relay_data = nullptr;
int current_index;
int vote_current_index;
QMap<QString, QString> channelNameMap;
void Init();

View File

@ -17,7 +17,7 @@
<property name="geometry">
<rect>
<x>620</x>
<y>20</y>
<y>180</y>
<width>91</width>
<height>16</height>
</rect>
@ -30,7 +30,7 @@
<property name="geometry">
<rect>
<x>230</x>
<y>350</y>
<y>340</y>
<width>111</width>
<height>16</height>
</rect>
@ -43,7 +43,7 @@
<property name="geometry">
<rect>
<x>10</x>
<y>360</y>
<y>350</y>
<width>201</width>
<height>151</height>
</rect>
@ -51,15 +51,113 @@
<property name="title">
<string>继电器关联</string>
</property>
<widget class="QComboBox" name="comboBox_relay_ch">
<widget class="QCheckBox" name="checkBox_active">
<property name="geometry">
<rect>
<x>20</x>
<y>30</y>
<width>103</width>
<height>32</height>
<y>120</y>
<width>85</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>激活</string>
</property>
</widget>
<widget class="QLabel" name="label_94">
<property name="geometry">
<rect>
<x>10</x>
<y>70</y>
<width>42</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string> 分组:</string>
</property>
</widget>
<widget class="QComboBox" name="comboBox_group">
<property name="geometry">
<rect>
<x>60</x>
<y>60</y>
<width>101</width>
<height>30</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>50</width>
<height>30</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>30</height>
</size>
</property>
<item>
<property name="text">
<string>1</string>
</property>
</item>
<item>
<property name="text">
<string>2</string>
</property>
</item>
<item>
<property name="text">
<string>3</string>
</property>
</item>
<item>
<property name="text">
<string>4</string>
</property>
</item>
<item>
<property name="text">
<string>5</string>
</property>
</item>
</widget>
<widget class="QLabel" name="label_95">
<property name="geometry">
<rect>
<x>10</x>
<y>30</y>
<width>42</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string> 通道:</string>
</property>
</widget>
<widget class="QComboBox" name="comboBox_relay_ch">
<property name="geometry">
<rect>
<x>60</x>
<y>20</y>
<width>103</width>
<height>30</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>50</width>
<height>30</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>30</height>
</size>
</property>
<item>
<property name="text">
<string>通道 1</string>
@ -141,32 +239,6 @@
</property>
</item>
</widget>
<widget class="QCheckBox" name="checkBox_active">
<property name="geometry">
<rect>
<x>26</x>
<y>70</y>
<width>85</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>激活</string>
</property>
</widget>
<widget class="QCheckBox" name="checkBox_2">
<property name="geometry">
<rect>
<x>140</x>
<y>40</y>
<width>71</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>成组</string>
</property>
</widget>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
@ -824,7 +896,7 @@
<property name="geometry">
<rect>
<x>620</x>
<y>40</y>
<y>200</y>
<width>341</width>
<height>301</height>
</rect>
@ -834,8 +906,8 @@
<property name="geometry">
<rect>
<x>230</x>
<y>370</y>
<width>391</width>
<y>360</y>
<width>381</width>
<height>141</height>
</rect>
</property>
@ -926,6 +998,142 @@
</item>
</layout>
</widget>
<widget class="QCheckBox" name="checkBox_vote">
<property name="geometry">
<rect>
<x>640</x>
<y>30</y>
<width>71</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>是否投票</string>
</property>
</widget>
<widget class="QWidget" name="">
<property name="geometry">
<rect>
<x>630</x>
<y>70</y>
<width>100</width>
<height>32</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLabel" name="label_96">
<property name="text">
<string> 逻辑:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox_vote_group">
<property name="enabled">
<bool>false</bool>
</property>
<property name="minimumSize">
<size>
<width>50</width>
<height>30</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>30</height>
</size>
</property>
<item>
<property name="text">
<string>1</string>
</property>
</item>
<item>
<property name="text">
<string>2</string>
</property>
</item>
<item>
<property name="text">
<string>3</string>
</property>
</item>
<item>
<property name="text">
<string>4</string>
</property>
</item>
<item>
<property name="text">
<string>5</string>
</property>
</item>
<item>
<property name="text">
<string>6</string>
</property>
</item>
<item>
<property name="text">
<string>7</string>
</property>
</item>
<item>
<property name="text">
<string>8</string>
</property>
</item>
<item>
<property name="text">
<string>9</string>
</property>
</item>
<item>
<property name="text">
<string>10</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="">
<property name="geometry">
<rect>
<x>631</x>
<y>131</y>
<width>100</width>
<height>27</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="label_97">
<property name="text">
<string> 选择:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_vote_count">
<property name="minimumSize">
<size>
<width>50</width>
<height>25</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>50</width>
<height>25</height>
</size>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<resources/>
<connections/>

View File

@ -19,7 +19,7 @@
<layout class="QVBoxLayout" name="verticalLayout_13">
<item>
<widget class="QWidget" name="widget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<layout class="QHBoxLayout" name="horizontalLayout_61">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
@ -36,22 +36,68 @@
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="horizontalSpacer_2">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label_94">
<property name="text">
<string> 分组:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox_3">
<property name="minimumSize">
<size>
<width>50</width>
<height>0</height>
</size>
</property>
<item>
<property name="text">
<string>1</string>
</property>
</item>
<item>
<property name="text">
<string>2</string>
</property>
</item>
<item>
<property name="text">
<string>3</string>
</property>
</item>
<item>
<property name="text">
<string>4</string>
</property>
</item>
<item>
<property name="text">
<string>5</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<width>604</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>