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,12 +575,25 @@ void ConfigMgr::Save(QString & file_path) {
continue; continue;
} }
std::shared_ptr<SingleRelayData> ptr = std::dynamic_pointer_cast<SingleRelayData>(base_ptr); std::shared_ptr<SingleRelayData> ptr = std::dynamic_pointer_cast<SingleRelayData>(base_ptr);
if(ptr->single_relay[ch].logic_expression != ""){ if(ptr->single_relay[ch].vote){
qDebug() << "ch" << ch << ptr->single_relay[ch].logic_expression; channel_item.insert("count_vote",ptr->single_relay[ch].count_vote);
channel_item.insert("logic_expression", ptr->single_relay[ch].logic_expression); QJsonArray array_logic;
channel_item.insert("active", ptr->single_relay[ch].active); 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() ){ if(!channel_item.isEmpty() ){
slot_item[QString::number(ch + 1)] = channel_item; slot_item[QString::number(ch + 1)] = channel_item;
@ -1084,9 +1097,18 @@ void ConfigMgr::Load(QString filename) {
singlerelay_data->version_ = temp_obj["version"].toInt(); singlerelay_data->version_ = temp_obj["version"].toInt();
for (int j = 0; j < RELAY_COUNT; ++j) { for (int j = 0; j < RELAY_COUNT; ++j) {
channel = temp_obj[QString::number(j + 1)].toObject(); 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].active = channel["active"].toBool();
singlerelay_data->single_relay[j].group = channel["group"].toInt();
} }
cards_.push_back(singlerelay_data); cards_.push_back(singlerelay_data);
} }

View File

@ -497,9 +497,14 @@ typedef struct SpeedAlert_{
typedef struct SingleRelayNOK_{ typedef struct SingleRelayNOK_{
QString logic_expression; QString logic_expression;
bool active; bool active;
int group;
bool vote;
QString logic[10];
int count_vote;
SingleRelayNOK_(){ SingleRelayNOK_(){
logic_expression = ""; logic_expression = "";
active = false; active = false;
vote = false;
} }
} SingleRelayNOK; } SingleRelayNOK;

View File

@ -34,9 +34,9 @@
<layout class="QVBoxLayout" name="verticalLayout_15"> <layout class="QVBoxLayout" name="verticalLayout_15">
<item> <item>
<widget class="QWidget" name="widget" native="true"> <widget class="QWidget" name="widget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_31"> <layout class="QHBoxLayout" name="horizontalLayout_34">
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout_33">
<item> <item>
<widget class="QLabel" name="label"> <widget class="QLabel" name="label">
<property name="text"> <property name="text">
@ -51,19 +51,10 @@
</property> </property>
</widget> </widget>
</item> </item>
<item> </layout>
<spacer name="horizontalSpacer"> </item>
<property name="orientation"> <item>
<enum>Qt::Horizontal</enum> <layout class="QHBoxLayout" name="horizontalLayout_31">
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item> <item>
<widget class="QLabel" name="label_2"> <widget class="QLabel" name="label_2">
<property name="text"> <property name="text">
@ -78,21 +69,67 @@
</property> </property>
</widget> </widget>
</item> </item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item> <item>
<spacer name="horizontalSpacer_2"> <widget class="QLabel" name="label_5">
<property name="orientation"> <property name="text">
<enum>Qt::Horizontal</enum> <string> 分组:</string>
</property> </property>
<property name="sizeHint" stdset="0"> </widget>
</item>
<item>
<widget class="QComboBox" name="comboBox_3">
<property name="minimumSize">
<size> <size>
<width>40</width> <width>50</width>
<height>20</height> <height>0</height>
</size> </size>
</property> </property>
</spacer> <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> </item>
</layout> </layout>
</item> </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>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>

View File

@ -46,32 +46,85 @@
<height>50</height> <height>50</height>
</size> </size>
</property> </property>
<widget class="QWidget" name="layoutWidget"> <layout class="QHBoxLayout" name="horizontalLayout_42">
<property name="geometry"> <item>
<rect> <layout class="QHBoxLayout" name="horizontalLayout">
<x>10</x> <item>
<y>20</y> <widget class="QLabel" name="label">
<width>113</width> <property name="text">
<height>21</height> <string> 槽位号:</string>
</rect> </property>
</property> </widget>
<layout class="QHBoxLayout" name="horizontalLayout"> </item>
<item> <item>
<widget class="QLabel" name="label"> <widget class="QLabel" name="label_slot_no">
<property name="text"> <property name="text">
<string> 槽位号:</string> <string>7</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> </layout>
<widget class="QLabel" name="label_slot_no"> </item>
<property name="text"> <item>
<string>7</string> <layout class="QHBoxLayout" name="horizontalLayout_41">
</property> <item>
</widget> <widget class="QLabel" name="label_5">
</item> <property name="text">
</layout> <string> 分组:</string>
</widget> </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> </widget>
</item> </item>
<item> <item>

View File

@ -52,6 +52,7 @@ SingleRelay::SingleRelay(int slot,int cardtype,QWidget *parent)
treeView_relay->setContextMenuPolicy(Qt::CustomContextMenu); treeView_relay->setContextMenuPolicy(Qt::CustomContextMenu);
connect(treeView_relay,&QTreeView::customContextMenuRequested,this,&SingleRelay::on_treeView_Relay_customContextMenuRequested); connect(treeView_relay,&QTreeView::customContextMenuRequested,this,&SingleRelay::on_treeView_Relay_customContextMenuRequested);
current_index = ui->comboBox_relay_ch->currentIndex(); current_index = ui->comboBox_relay_ch->currentIndex();
vote_current_index = ui->comboBox_vote_group->currentIndex();
Init(); Init();
onComboBoxIndexChanged(current_index); onComboBoxIndexChanged(current_index);
@ -149,6 +150,7 @@ void SingleRelay::Init(){
setExpressionToTreeView(treeView_relay, relay_data->single_relay[current_index].logic_expression); setExpressionToTreeView(treeView_relay, relay_data->single_relay[current_index].logic_expression);
} }
ui->checkBox_active->setChecked(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);
} }
void SingleRelay::on_pushButton_cancel_clicked() { void SingleRelay::on_pushButton_cancel_clicked() {
this->close(); this->close();
@ -272,8 +274,13 @@ void SingleRelay::on_pushButton_confirm_clicked()
QString("错误位置:%1\n错误描述:%2").arg(result.errorPos).arg(result.errorMsg)); QString("错误位置:%1\n错误描述:%2").arg(result.errorPos).arg(result.errorMsg));
return; 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].active = ui->checkBox_active->isChecked();
relay_data->single_relay[current_index].group = ui->comboBox_group->currentIndex() + 1;
qDebug() << "逻辑表达式:" << finalExpr; qDebug() << "逻辑表达式:" << finalExpr;
this->close(); this->close();
} }
@ -297,15 +304,25 @@ void SingleRelay::onComboBoxIndexChanged(int index){
return; return;
} }
qDebug() << "finalExpr" << finalExpr; 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].active = ui->checkBox_active->isChecked();
relay_data->single_relay[current_index].group = ui->comboBox_group->currentIndex() + 1;
current_index = index; current_index = index;
qDebug() << "active" << relay_data->single_relay[index].active; qDebug() << "active" << relay_data->single_relay[index].active;
ui->checkBox_active->setChecked(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) { ExprNode* SingleRelay::parseExpression(const QString& expr, int& pos) {
auto skipSpaces = [&]() { auto skipSpaces = [&]() {
@ -477,3 +494,40 @@ void SingleRelay::on_treeView_Relay_customContextMenuRequested(const QPoint &pos
} }
menu.exec(QCursor::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_treeView_Relay_customContextMenuRequested(const QPoint &pos);
void on_checkBox_vote_clicked(bool checked);
void on_comboBox_vote_group_currentIndexChanged(int index);
private: private:
Ui::SingleRelay *ui; Ui::SingleRelay *ui;
QButtonGroup * btnGroup_slot = nullptr; QButtonGroup * btnGroup_slot = nullptr;
@ -42,6 +46,7 @@ private:
QStandardItemModel *model_Relay; QStandardItemModel *model_Relay;
std::shared_ptr<SingleRelayData> relay_data = nullptr; std::shared_ptr<SingleRelayData> relay_data = nullptr;
int current_index; int current_index;
int vote_current_index;
QMap<QString, QString> channelNameMap; QMap<QString, QString> channelNameMap;
void Init(); void Init();

View File

@ -17,7 +17,7 @@
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>620</x> <x>620</x>
<y>20</y> <y>180</y>
<width>91</width> <width>91</width>
<height>16</height> <height>16</height>
</rect> </rect>
@ -30,7 +30,7 @@
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>230</x> <x>230</x>
<y>350</y> <y>340</y>
<width>111</width> <width>111</width>
<height>16</height> <height>16</height>
</rect> </rect>
@ -43,7 +43,7 @@
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>10</x> <x>10</x>
<y>360</y> <y>350</y>
<width>201</width> <width>201</width>
<height>151</height> <height>151</height>
</rect> </rect>
@ -51,15 +51,113 @@
<property name="title"> <property name="title">
<string>继电器关联</string> <string>继电器关联</string>
</property> </property>
<widget class="QComboBox" name="comboBox_relay_ch"> <widget class="QCheckBox" name="checkBox_active">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>20</x> <x>20</x>
<y>30</y> <y>120</y>
<width>103</width> <width>85</width>
<height>32</height> <height>20</height>
</rect> </rect>
</property> </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> <item>
<property name="text"> <property name="text">
<string>通道 1</string> <string>通道 1</string>
@ -141,32 +239,6 @@
</property> </property>
</item> </item>
</widget> </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>
<widget class="QLabel" name="label"> <widget class="QLabel" name="label">
<property name="geometry"> <property name="geometry">
@ -824,7 +896,7 @@
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>620</x> <x>620</x>
<y>40</y> <y>200</y>
<width>341</width> <width>341</width>
<height>301</height> <height>301</height>
</rect> </rect>
@ -834,8 +906,8 @@
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>230</x> <x>230</x>
<y>370</y> <y>360</y>
<width>391</width> <width>381</width>
<height>141</height> <height>141</height>
</rect> </rect>
</property> </property>
@ -926,6 +998,142 @@
</item> </item>
</layout> </layout>
</widget> </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> </widget>
<resources/> <resources/>
<connections/> <connections/>

View File

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