优化代码
This commit is contained in:
parent
3461aa9e4a
commit
3ec608686f
@ -19,6 +19,7 @@ SOURCES += \
|
|||||||
keyphase_data.cpp \
|
keyphase_data.cpp \
|
||||||
main.cpp \
|
main.cpp \
|
||||||
mainwindow.cpp \
|
mainwindow.cpp \
|
||||||
|
pointname.cpp \
|
||||||
radial_vibration.cpp \
|
radial_vibration.cpp \
|
||||||
rangeslider.cpp \
|
rangeslider.cpp \
|
||||||
relaysetting.cpp \
|
relaysetting.cpp \
|
||||||
@ -47,6 +48,7 @@ HEADERS += \
|
|||||||
keyphase.h \
|
keyphase.h \
|
||||||
keyphase_data.h \
|
keyphase_data.h \
|
||||||
mainwindow.h \
|
mainwindow.h \
|
||||||
|
pointname.h \
|
||||||
radial_vibration.h \
|
radial_vibration.h \
|
||||||
rangeslider.h \
|
rangeslider.h \
|
||||||
relaysetting.h \
|
relaysetting.h \
|
||||||
@ -68,6 +70,7 @@ FORMS += \
|
|||||||
connect.ui \
|
connect.ui \
|
||||||
keyphase.ui \
|
keyphase.ui \
|
||||||
mainwindow.ui \
|
mainwindow.ui \
|
||||||
|
pointname.ui \
|
||||||
radial_vibration.ui \
|
radial_vibration.ui \
|
||||||
relaysetting.ui \
|
relaysetting.ui \
|
||||||
seismic_monitor.ui \
|
seismic_monitor.ui \
|
||||||
|
@ -273,26 +273,42 @@ void ConfigMgr::Save(QString & file_path) {
|
|||||||
}
|
}
|
||||||
slot_item["version"] = 1;
|
slot_item["version"] = 1;
|
||||||
}else{
|
}else{
|
||||||
QJsonObject channel_item;
|
|
||||||
for(int ch = 0;ch < RELAY_COUNT;++ch){
|
for(int ch = 0;ch < RELAY_COUNT;++ch){
|
||||||
|
QJsonObject channel_item;
|
||||||
if(card_type_[i] == kCardRelaySingleNOK){
|
if(card_type_[i] == kCardRelaySingleNOK){
|
||||||
std::shared_ptr<CardBase> base_ptr = ConfigMgr::Instance()->GetSlotPtr(slot);
|
std::shared_ptr<CardBase> base_ptr = ConfigMgr::Instance()->GetSlotPtr(slot);
|
||||||
if (base_ptr == nullptr) {
|
if (base_ptr == nullptr) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
std::shared_ptr<SingleRelayDataNOK> ptr = std::dynamic_pointer_cast<SingleRelayDataNOK>(base_ptr);
|
std::shared_ptr<SingleRelayDataNOK> ptr = std::dynamic_pointer_cast<SingleRelayDataNOK>(base_ptr);
|
||||||
channel_item.insert("logic_expression", ptr->single_relay_nok[ch].logic_expression);
|
if(ptr->single_relay_nok[ch].logic_expression != ""){
|
||||||
|
qDebug() << "ch" << ch << ptr->single_relay_nok[ch].logic_expression;
|
||||||
|
channel_item.insert("logic_expression", ptr->single_relay_nok[ch].logic_expression);
|
||||||
|
}
|
||||||
|
|
||||||
}else if(card_type_[i] == kCardRelaySingle || card_type_[i] == kCardRelayTMRPrimary){
|
}else if(card_type_[i] == kCardRelaySingle){
|
||||||
std::shared_ptr<CardBase> base_ptr = ConfigMgr::Instance()->GetSlotPtr(slot);
|
std::shared_ptr<CardBase> base_ptr = ConfigMgr::Instance()->GetSlotPtr(slot);
|
||||||
if (base_ptr == nullptr) {
|
if (base_ptr == nullptr) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
std::shared_ptr<TmrrelayassociationData> ptr = std::dynamic_pointer_cast<TmrrelayassociationData>(base_ptr);
|
std::shared_ptr<TmrrelayassociationData> ptr = std::dynamic_pointer_cast<TmrrelayassociationData>(base_ptr);
|
||||||
channel_item.insert("logic_expression", ptr->tmr_relay[ch].logic_expression);
|
if(ptr->tmr_relay[ch].logic_expression != "")
|
||||||
channel_item.insert("sgcc_enable", ptr->tmr_relay[ch].sgcc_enable);
|
channel_item.insert("logic_expression", ptr->tmr_relay[ch].logic_expression);
|
||||||
|
}else if(card_type_[i] == kCardRelayTMRPrimary){
|
||||||
|
std::shared_ptr<CardBase> base_ptr = ConfigMgr::Instance()->GetSlotPtr(slot);
|
||||||
|
if (base_ptr == nullptr) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
std::shared_ptr<TmrrelayassociationData> ptr = std::dynamic_pointer_cast<TmrrelayassociationData>(base_ptr);
|
||||||
|
if(ptr->tmr_relay[ch].logic_expression != "" && !ptr->tmr_relay[ch].sgcc_enable){
|
||||||
|
channel_item.insert("logic_expression", ptr->tmr_relay[ch].logic_expression);
|
||||||
|
channel_item.insert("sgcc_enable", ptr->tmr_relay[ch].sgcc_enable);
|
||||||
|
}else if(ptr->tmr_relay[ch].logic_expression == "" && ptr->tmr_relay[ch].sgcc_enable){
|
||||||
|
channel_item.insert("sgcc_enable", ptr->tmr_relay[ch].sgcc_enable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
slot_item[QString::number(ch + 1)] = channel_item;
|
if(!channel_item.isEmpty())
|
||||||
|
slot_item[QString::number(ch + 1)] = channel_item;
|
||||||
}
|
}
|
||||||
slot_item["version"] = 1;
|
slot_item["version"] = 1;
|
||||||
}
|
}
|
||||||
@ -555,7 +571,17 @@ void ConfigMgr::Load(QString filename) {
|
|||||||
singlerelay_data->single_relay_nok[j].logic_expression = channel["logic_expression"].toString();
|
singlerelay_data->single_relay_nok[j].logic_expression = channel["logic_expression"].toString();
|
||||||
}
|
}
|
||||||
cards_.push_back(singlerelay_data);
|
cards_.push_back(singlerelay_data);
|
||||||
}else if(card_type_[i] == kCardRelayTMRPrimary || card_type_[i] == kCardRelaySingle){
|
}else if(card_type_[i] == kCardRelaySingle){
|
||||||
|
std::shared_ptr<TmrrelayassociationData> relay_data = std::make_shared<TmrrelayassociationData>();
|
||||||
|
relay_data->slot_ = slot;
|
||||||
|
relay_data->card_type_ = static_cast<CardType>(card_type_[i]);
|
||||||
|
relay_data->version_ = temp_obj["version"].toInt();
|
||||||
|
for (int j = 0; j < RELAY_COUNT; ++j) {
|
||||||
|
channel = temp_obj[QString::number(j + 1)].toObject();
|
||||||
|
relay_data->tmr_relay[j].logic_expression = channel["logic_expression"].toString();
|
||||||
|
}
|
||||||
|
cards_.push_back(relay_data);
|
||||||
|
}else if(card_type_[i] == kCardRelayTMRPrimary){
|
||||||
std::shared_ptr<TmrrelayassociationData> relay_data = std::make_shared<TmrrelayassociationData>();
|
std::shared_ptr<TmrrelayassociationData> relay_data = std::make_shared<TmrrelayassociationData>();
|
||||||
relay_data->slot_ = slot;
|
relay_data->slot_ = slot;
|
||||||
relay_data->card_type_ = static_cast<CardType>(card_type_[i]);
|
relay_data->card_type_ = static_cast<CardType>(card_type_[i]);
|
||||||
|
@ -103,7 +103,7 @@ typedef enum {
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int id;
|
int id;
|
||||||
// QString channel_name;
|
QString point_name;
|
||||||
bool standby;
|
bool standby;
|
||||||
bool active;
|
bool active;
|
||||||
int rack_type; // VibRackType
|
int rack_type; // VibRackType
|
||||||
@ -357,6 +357,7 @@ typedef struct {
|
|||||||
uint8_t ethn; // 0: eth0, 1: eth1
|
uint8_t ethn; // 0: eth0, 1: eth1
|
||||||
char ip[16];
|
char ip[16];
|
||||||
char netmask[16];
|
char netmask[16];
|
||||||
|
char gw[16];
|
||||||
} ConfigIPv4Req;
|
} ConfigIPv4Req;
|
||||||
|
|
||||||
// 配置IP的响应结构为CommonRsp
|
// 配置IP的响应结构为CommonRsp
|
||||||
|
@ -96,7 +96,7 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
//connectServer();
|
//connectServer();
|
||||||
// 设置自定义日志处理函数
|
// 设置自定义日志处理函数
|
||||||
#ifndef QT_DEBUG
|
#ifndef QT_DEBUG
|
||||||
qInstallMessageHandler(messageHandler);
|
//qInstallMessageHandler(messageHandler);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -246,6 +246,7 @@ void MainWindow::createMenu(const QString &rootTitle, QPushButton *parent) {
|
|||||||
QObject::connect(rpm_1, &QAction::triggered, this, &MainWindow::onMenuActionTriggered);
|
QObject::connect(rpm_1, &QAction::triggered, this, &MainWindow::onMenuActionTriggered);
|
||||||
QObject::connect(relays_1, &QAction::triggered, this, &MainWindow::onMenuActionTriggered);
|
QObject::connect(relays_1, &QAction::triggered, this, &MainWindow::onMenuActionTriggered);
|
||||||
QObject::connect(relays_2, &QAction::triggered, this, &MainWindow::onMenuActionTriggered);
|
QObject::connect(relays_2, &QAction::triggered, this, &MainWindow::onMenuActionTriggered);
|
||||||
|
QObject::connect(relays_3, &QAction::triggered, this, &MainWindow::onMenuActionTriggered);
|
||||||
QObject::connect(keyphasor_1, &QAction::triggered, this, &MainWindow::onMenuActionTriggered);
|
QObject::connect(keyphasor_1, &QAction::triggered, this, &MainWindow::onMenuActionTriggered);
|
||||||
QObject::connect(keyphasor_2, &QAction::triggered, this, &MainWindow::onMenuActionTriggered);
|
QObject::connect(keyphasor_2, &QAction::triggered, this, &MainWindow::onMenuActionTriggered);
|
||||||
QObject::connect(reset, &QAction::triggered, this, &MainWindow::onMenuActionTriggered);
|
QObject::connect(reset, &QAction::triggered, this, &MainWindow::onMenuActionTriggered);
|
||||||
@ -462,6 +463,12 @@ void MainWindow::OnButtonGroup(QAbstractButton *slot_btn) {
|
|||||||
key_phase->show();
|
key_phase->show();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case kCardSpeedSingle:{
|
||||||
|
Tachometer *tachometer = new Tachometer(button_id,card_type);
|
||||||
|
tachometer->setWindowModality(Qt::ApplicationModal);
|
||||||
|
tachometer->show();
|
||||||
|
break;
|
||||||
|
}
|
||||||
case kCardRelaySingleNOK:{
|
case kCardRelaySingleNOK:{
|
||||||
SingleRelay *single_relay = new SingleRelay(button_id,card_type);
|
SingleRelay *single_relay = new SingleRelay(button_id,card_type);
|
||||||
single_relay->setWindowModality(Qt::ApplicationModal);
|
single_relay->setWindowModality(Qt::ApplicationModal);
|
||||||
|
@ -50,7 +50,7 @@
|
|||||||
<widget class="QPushButton" name="pushButton_save">
|
<widget class="QPushButton" name="pushButton_save">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>20</x>
|
<x>80</x>
|
||||||
<y>20</y>
|
<y>20</y>
|
||||||
<width>45</width>
|
<width>45</width>
|
||||||
<height>45</height>
|
<height>45</height>
|
||||||
@ -75,7 +75,7 @@
|
|||||||
<widget class="QPushButton" name="pushButton_open">
|
<widget class="QPushButton" name="pushButton_open">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>80</x>
|
<x>20</x>
|
||||||
<y>20</y>
|
<y>20</y>
|
||||||
<width>45</width>
|
<width>45</width>
|
||||||
<height>45</height>
|
<height>45</height>
|
||||||
|
@ -34,8 +34,6 @@ Seismic_monitor::Seismic_monitor(int slot,int cardtype, QWidget *parent) :
|
|||||||
car_type = static_cast<CardType>(cardtype);
|
car_type = static_cast<CardType>(cardtype);
|
||||||
QString slot_no_ = QString("%1").arg(slot_no);
|
QString slot_no_ = QString("%1").arg(slot_no);
|
||||||
ui->label_slot_no->setText(slot_no_);
|
ui->label_slot_no->setText(slot_no_);
|
||||||
// QString filePath = QCoreApplication::applicationDirPath() + QString("\\config\\%1\\seismic_monitor_slot.json").arg(slot_no);
|
|
||||||
// readJsonFile(filePath);
|
|
||||||
Init();
|
Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,71 +41,6 @@ Seismic_monitor::~Seismic_monitor() {
|
|||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
//void Seismic_monitor::readJsonFile(const QString &filePath) {
|
|
||||||
// // 创建文件对象
|
|
||||||
// QFile file(filePath);
|
|
||||||
// if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
|
||||||
// qDebug() << "Cannot open file for reading:" << filePath;
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// QString content = file.readAll();
|
|
||||||
// file.close();
|
|
||||||
// QByteArray jsonData = content.toUtf8();
|
|
||||||
// QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonData);
|
|
||||||
// if (jsonDoc.isNull()) {
|
|
||||||
// qDebug() << "Cannot parse JSON document";
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// if (!jsonDoc.isObject() && !jsonDoc.isArray()) {
|
|
||||||
// qDebug() << "JSON document is not an object or an array";
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// QJsonObject json_obj = jsonDoc.object();
|
|
||||||
// card_type = json_obj["card_type"].toInt();
|
|
||||||
// QJsonArray chan_array = json_obj["chan"].toArray();
|
|
||||||
// for (int i = 0; i < chan_array.size(); i++) {
|
|
||||||
// QJsonObject temp_obj = chan_array[i].toObject();
|
|
||||||
// seismic_monitor[i].id = temp_obj["id"].toInt();
|
|
||||||
//// seismic_monitor[i].channel_name = temp_obj["channle_name"].toString();
|
|
||||||
// seismic_monitor[i].standby = temp_obj["standby"].toBool();
|
|
||||||
// seismic_monitor[i].active = temp_obj["active"].toBool();
|
|
||||||
// seismic_monitor[i].rack_type = temp_obj["rack_type"].toInt();
|
|
||||||
// seismic_monitor[i].tmr_group = temp_obj["tmr_group"].toString();
|
|
||||||
// seismic_monitor[i].channel_type = temp_obj["channel_type"].toInt();
|
|
||||||
// seismic_monitor[i].transducer_name = temp_obj["transducer_name"].toString();
|
|
||||||
// seismic_monitor[i].scale_factor = temp_obj["scale_factor"].toDouble();
|
|
||||||
// seismic_monitor[i].sampling_rate = temp_obj["sampling_rate"].toInt();
|
|
||||||
// QJsonArray voltage_range_array = temp_obj["normal_voltage_range"].toArray();
|
|
||||||
// seismic_monitor[i].normal_voltage_low = voltage_range_array[0].toDouble();
|
|
||||||
// seismic_monitor[i].normal_voltage_high = voltage_range_array[1].toDouble();
|
|
||||||
// }
|
|
||||||
// QFile file_transducer(QCoreApplication::applicationDirPath() + QString("\\config\\transducer.json"));
|
|
||||||
// if (!file_transducer.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
|
||||||
// qDebug() << "Cannot open file for reading:" << filePath;
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// QString content_transducer = file_transducer.readAll();
|
|
||||||
// file_transducer.close();
|
|
||||||
// QByteArray jsonData2 = content_transducer.toUtf8();
|
|
||||||
// QJsonDocument jsonDoc2 = QJsonDocument::fromJson(jsonData2);
|
|
||||||
// if (jsonDoc2.isNull()) {
|
|
||||||
// qDebug() << "Cannot parse JSON document";
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// if (!jsonDoc2.isObject() && !jsonDoc2.isArray()) {
|
|
||||||
// qDebug() << "JSON document is not an object or an array";
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// QJsonArray json_array = jsonDoc2.array();
|
|
||||||
// for (int var = 0; var < json_array.size(); ++var) {
|
|
||||||
// Transducer transducer;
|
|
||||||
// QJsonObject temp_obj = json_array[var].toObject();
|
|
||||||
// transducer.transducer_name = temp_obj["transducer_name"].toString();
|
|
||||||
// transducer.scale_factor = temp_obj["scale_factor"].toDouble();
|
|
||||||
// vec_transducer.push_back(transducer);
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
void Seismic_monitor::Init() {
|
void Seismic_monitor::Init() {
|
||||||
// for (int var = 0; var < vec_transducer.size(); ++var) {
|
// for (int var = 0; var < vec_transducer.size(); ++var) {
|
||||||
// ui->comboBox_transducer_name_1->addItem(vec_transducer[var].transducer_name);
|
// ui->comboBox_transducer_name_1->addItem(vec_transducer[var].transducer_name);
|
||||||
|
@ -3,9 +3,7 @@
|
|||||||
#include "vibrationdata.h"
|
#include "vibrationdata.h"
|
||||||
#include <QStack>
|
#include <QStack>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TMRRelayAssociation::TMRRelayAssociation(int slot,int cardtype,QWidget *parent)
|
TMRRelayAssociation::TMRRelayAssociation(int slot,int cardtype,QWidget *parent)
|
||||||
: QDialog(parent)
|
: QDialog(parent)
|
||||||
@ -14,6 +12,9 @@ TMRRelayAssociation::TMRRelayAssociation(int slot,int cardtype,QWidget *parent)
|
|||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
slot_no = slot;
|
slot_no = slot;
|
||||||
car_type = static_cast<CardType>(cardtype);
|
car_type = static_cast<CardType>(cardtype);
|
||||||
|
if(car_type == kCardRelaySingle){
|
||||||
|
ui->checkBox_sgcc->setVisible(0);
|
||||||
|
}
|
||||||
ui->label_slot_no->setText(QString::number(slot_no));
|
ui->label_slot_no->setText(QString::number(slot_no));
|
||||||
QVBoxLayout *layout_available = new QVBoxLayout(ui->widget_available);
|
QVBoxLayout *layout_available = new QVBoxLayout(ui->widget_available);
|
||||||
list_widget_available = new DraggableListWidget;
|
list_widget_available = new DraggableListWidget;
|
||||||
@ -54,9 +55,9 @@ TMRRelayAssociation::TMRRelayAssociation(int slot,int cardtype,QWidget *parent)
|
|||||||
this, &TMRRelayAssociation::onComboBoxIndexChanged);
|
this, &TMRRelayAssociation::onComboBoxIndexChanged);
|
||||||
treeView_relay->setContextMenuPolicy(Qt::CustomContextMenu);
|
treeView_relay->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
connect(treeView_relay,&QTreeView::customContextMenuRequested,this,&TMRRelayAssociation::on_treeView_Relay_customContextMenuRequested);
|
connect(treeView_relay,&QTreeView::customContextMenuRequested,this,&TMRRelayAssociation::on_treeView_Relay_customContextMenuRequested);
|
||||||
|
|
||||||
Init();
|
|
||||||
current_index = ui->comboBox_relay_ch->currentIndex();
|
current_index = ui->comboBox_relay_ch->currentIndex();
|
||||||
|
Init();
|
||||||
|
|
||||||
// QString expr = "((S01C01A1 + S01C02A1 + (S02C01A1 * S02C01A2)) * (S02C01A2 + S02C01A1 + (S02C01A1 + S02C01A2)) * (S02C01A1 * S02C01A2))";
|
// QString expr = "((S01C01A1 + S01C02A1 + (S02C01A1 * S02C01A2)) * (S02C01A2 + S02C01A1 + (S02C01A1 + S02C01A2)) * (S02C01A1 * S02C01A2))";
|
||||||
// setExpressionToTreeView(treeView_relay, expr);
|
// setExpressionToTreeView(treeView_relay, expr);
|
||||||
}
|
}
|
||||||
@ -104,6 +105,8 @@ void TMRRelayAssociation::Init(){
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
relay_data = std::dynamic_pointer_cast<TmrrelayassociationData>(base_ptr);
|
relay_data = std::dynamic_pointer_cast<TmrrelayassociationData>(base_ptr);
|
||||||
|
qDebug() << "logic" <<relay_data->tmr_relay[current_index].logic_expression;
|
||||||
|
ui->checkBox_sgcc->setChecked(relay_data->tmr_relay[current_index].sgcc_enable);
|
||||||
setExpressionToTreeView(treeView_relay, relay_data->tmr_relay[current_index].logic_expression);
|
setExpressionToTreeView(treeView_relay, relay_data->tmr_relay[current_index].logic_expression);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -268,6 +271,63 @@ QStandardItem* TMRRelayAssociation::parseExpression(const QString &expr) {
|
|||||||
// 返回栈顶的节点,应该是根节点
|
// 返回栈顶的节点,应该是根节点
|
||||||
return stack.isEmpty() ? nullptr : stack.pop();
|
return stack.isEmpty() ? nullptr : stack.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ExprValidationResult TMRRelayAssociation::validateLogicExpression(const QString& expr) {
|
||||||
|
int bracketCount = 0;
|
||||||
|
bool lastWasOperator = true;
|
||||||
|
bool lastWasOpenParen = false;
|
||||||
|
|
||||||
|
for (int i = 0; i < expr.length(); ++i) {
|
||||||
|
QChar ch = expr[i];
|
||||||
|
|
||||||
|
if (ch.isSpace()) continue;
|
||||||
|
|
||||||
|
if (ch == '(') {
|
||||||
|
bracketCount++;
|
||||||
|
lastWasOpenParen = true;
|
||||||
|
lastWasOperator = true;
|
||||||
|
} else if (ch == ')') {
|
||||||
|
bracketCount--;
|
||||||
|
if (bracketCount < 0) {
|
||||||
|
return {false, i, "多余的右括号 ')'"};
|
||||||
|
}
|
||||||
|
lastWasOpenParen = false;
|
||||||
|
lastWasOperator = false;
|
||||||
|
} else if (ch == '+' || ch == '*') {
|
||||||
|
if (lastWasOperator || lastWasOpenParen) {
|
||||||
|
return {false, i, QString("无效的运算符 '%1' 的位置").arg(ch)};
|
||||||
|
}
|
||||||
|
lastWasOperator = true;
|
||||||
|
lastWasOpenParen = false;
|
||||||
|
} else if (ch.isLetterOrNumber()) {
|
||||||
|
QString token;
|
||||||
|
int start = i;
|
||||||
|
while (i < expr.length() && expr[i].isLetterOrNumber()) {
|
||||||
|
token += expr[i];
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
--i; // 修正多读了一位
|
||||||
|
if (token.isEmpty()) {
|
||||||
|
return {false, start, "变量名称缺失"};
|
||||||
|
}
|
||||||
|
lastWasOperator = false;
|
||||||
|
lastWasOpenParen = false;
|
||||||
|
} else {
|
||||||
|
return {false, i, QString("不支持的字符 '%1'").arg(ch)};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bracketCount != 0) {
|
||||||
|
return {false, expr.length(), "括号不匹配"};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lastWasOperator) {
|
||||||
|
return {false, expr.length() - 1, "表达式不能以运算符结尾"};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {true, -1, ""};
|
||||||
|
}
|
||||||
|
|
||||||
void TMRRelayAssociation::buildTreeFromExpression(QTreeView *treeView, const QString &expr) {
|
void TMRRelayAssociation::buildTreeFromExpression(QTreeView *treeView, const QString &expr) {
|
||||||
QStandardItemModel* model = new QStandardItemModel();
|
QStandardItemModel* model = new QStandardItemModel();
|
||||||
QStandardItem* rootItem = parseExpression(expr);
|
QStandardItem* rootItem = parseExpression(expr);
|
||||||
@ -283,10 +343,20 @@ void TMRRelayAssociation::OnButtonGroup(QAbstractButton *slot_btn) {
|
|||||||
if (slot_btn != NULL) {
|
if (slot_btn != NULL) {
|
||||||
list_widget_available->clear();
|
list_widget_available->clear();
|
||||||
QString object_name = slot_btn->objectName();
|
QString object_name = slot_btn->objectName();
|
||||||
qDebug() << object_name ;
|
if(slot_btn->text().isEmpty())
|
||||||
|
return;
|
||||||
|
qDebug() << object_name;
|
||||||
int button_id = object_name.right(object_name.length() - 15).toInt();
|
int button_id = object_name.right(object_name.length() - 15).toInt();
|
||||||
std::shared_ptr<CardBase> base_ptr = ConfigMgr::Instance()->GetSlotPtr(button_id);
|
std::shared_ptr<CardBase> base_ptr = ConfigMgr::Instance()->GetSlotPtr(button_id);
|
||||||
std::shared_ptr<VibrationData> ptr = std::dynamic_pointer_cast<VibrationData>(base_ptr);
|
std::shared_ptr<VibrationData> ptr = std::dynamic_pointer_cast<VibrationData>(base_ptr);
|
||||||
|
QString item_str = QString("*");
|
||||||
|
QListWidgetItem *item_or = new QListWidgetItem("*");
|
||||||
|
item_or->setData(Qt::UserRole, "*");
|
||||||
|
list_widget_available->addItem(item_or);
|
||||||
|
|
||||||
|
QListWidgetItem *item_and = new QListWidgetItem("+");
|
||||||
|
item_and->setData(Qt::UserRole, "+");
|
||||||
|
list_widget_available->addItem(item_and);
|
||||||
for(int var = 0; var < CHANNEL_COUNT ; ++var){
|
for(int var = 0; var < CHANNEL_COUNT ; ++var){
|
||||||
if(ptr->alert_danger[var].direct_enable ||
|
if(ptr->alert_danger[var].direct_enable ||
|
||||||
ptr->alert_danger[var].x1_ampl_enable ||
|
ptr->alert_danger[var].x1_ampl_enable ||
|
||||||
@ -304,17 +374,7 @@ void TMRRelayAssociation::OnButtonGroup(QAbstractButton *slot_btn) {
|
|||||||
item->setData(Qt::UserRole, item_data);
|
item->setData(Qt::UserRole, item_data);
|
||||||
list_widget_available->addItem(item);
|
list_widget_available->addItem(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString item_str = QString("*");
|
|
||||||
QListWidgetItem *item_or = new QListWidgetItem("*");
|
|
||||||
item_or->setData(Qt::UserRole, "*");
|
|
||||||
list_widget_available->addItem(item_or);
|
|
||||||
|
|
||||||
QListWidgetItem *item_and = new QListWidgetItem("+");
|
|
||||||
item_and->setData(Qt::UserRole, "+");
|
|
||||||
list_widget_available->addItem(item_and);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void TMRRelayAssociation::on_pushButton_cancel_clicked()
|
void TMRRelayAssociation::on_pushButton_cancel_clicked()
|
||||||
@ -338,6 +398,12 @@ void TMRRelayAssociation::on_pushButton_confirm_clicked()
|
|||||||
// }
|
// }
|
||||||
finalExpr += expr;
|
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;
|
||||||
|
}
|
||||||
relay_data->tmr_relay[current_index].logic_expression = finalExpr;
|
relay_data->tmr_relay[current_index].logic_expression = finalExpr;
|
||||||
relay_data->tmr_relay[current_index].sgcc_enable = ui->checkBox_sgcc->checkState();
|
relay_data->tmr_relay[current_index].sgcc_enable = ui->checkBox_sgcc->checkState();
|
||||||
qDebug() << "逻辑表达式:" << finalExpr;
|
qDebug() << "逻辑表达式:" << finalExpr;
|
||||||
@ -357,6 +423,12 @@ void TMRRelayAssociation::onComboBoxIndexChanged(int index){
|
|||||||
// }
|
// }
|
||||||
finalExpr += expr;
|
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;
|
||||||
|
}
|
||||||
relay_data->tmr_relay[current_index].logic_expression = finalExpr;
|
relay_data->tmr_relay[current_index].logic_expression = finalExpr;
|
||||||
relay_data->tmr_relay[current_index].sgcc_enable = ui->checkBox_sgcc->checkState();
|
relay_data->tmr_relay[current_index].sgcc_enable = ui->checkBox_sgcc->checkState();
|
||||||
current_index = index;
|
current_index = index;
|
||||||
@ -399,3 +471,36 @@ void TMRRelayAssociation::on_treeView_Relay_customContextMenuRequested(const QPo
|
|||||||
}
|
}
|
||||||
menu.exec(QCursor::pos()); //显示菜单
|
menu.exec(QCursor::pos()); //显示菜单
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TMRRelayAssociation::on_checkBox_sgcc_stateChanged(int arg1)
|
||||||
|
{
|
||||||
|
if(ui->checkBox_sgcc->checkState()){
|
||||||
|
treeView_relay->setEnabled(false);
|
||||||
|
list_widget_available->setEnabled(false);
|
||||||
|
}else{
|
||||||
|
treeView_relay->setEnabled(true);
|
||||||
|
list_widget_available->setEnabled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void TMRRelayAssociation::on_pushButton_logic_clicked()
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
ui->textEdit_logic->setPlainText(finalExpr);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,11 @@ struct ExprNode {
|
|||||||
QString value;
|
QString value;
|
||||||
QList<ExprNode*> children;
|
QList<ExprNode*> children;
|
||||||
};
|
};
|
||||||
|
struct ExprValidationResult {
|
||||||
|
bool isValid;
|
||||||
|
int errorPos;
|
||||||
|
QString errorMsg;
|
||||||
|
};
|
||||||
class DropTreeModel : public QStandardItemModel {
|
class DropTreeModel : public QStandardItemModel {
|
||||||
public:
|
public:
|
||||||
using QStandardItemModel::QStandardItemModel;
|
using QStandardItemModel::QStandardItemModel;
|
||||||
@ -79,6 +83,10 @@ private slots:
|
|||||||
|
|
||||||
void on_treeView_Relay_customContextMenuRequested(const QPoint &pos);
|
void on_treeView_Relay_customContextMenuRequested(const QPoint &pos);
|
||||||
void slotDeleteItem();
|
void slotDeleteItem();
|
||||||
|
void on_checkBox_sgcc_stateChanged(int arg1);
|
||||||
|
|
||||||
|
void on_pushButton_logic_clicked();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::TMRRelayAssociation *ui;
|
Ui::TMRRelayAssociation *ui;
|
||||||
QButtonGroup * btnGroup_slot = nullptr;
|
QButtonGroup * btnGroup_slot = nullptr;
|
||||||
@ -95,6 +103,7 @@ private:
|
|||||||
void setExpressionToTreeView(QTreeView* treeView, const QString& expr);
|
void setExpressionToTreeView(QTreeView* treeView, const QString& expr);
|
||||||
QStandardItem* parseExpression(const QString &expr);
|
QStandardItem* parseExpression(const QString &expr);
|
||||||
QString buildLogicExpression(QStandardItem *item);
|
QString buildLogicExpression(QStandardItem *item);
|
||||||
|
ExprValidationResult validateLogicExpression(const QString& expr);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TMRRELAYASSOCIATION_H
|
#endif // TMRRELAYASSOCIATION_H
|
||||||
|
@ -6,12 +6,12 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>869</width>
|
<width>821</width>
|
||||||
<height>624</height>
|
<height>634</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>Dialog</string>
|
<string>继电器组态</string>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QLabel" name="label">
|
<widget class="QLabel" name="label">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
@ -185,11 +185,23 @@
|
|||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>110</x>
|
<x>110</x>
|
||||||
<y>540</y>
|
<y>538</y>
|
||||||
<width>691</width>
|
<width>691</width>
|
||||||
<height>31</height>
|
<height>40</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>0</width>
|
||||||
|
<height>40</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>16777215</width>
|
||||||
|
<height>40</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QPushButton" name="pushButton_9">
|
<widget class="QPushButton" name="pushButton_9">
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
@ -198,7 +210,7 @@
|
|||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>450</x>
|
<x>450</x>
|
||||||
<y>580</y>
|
<y>590</y>
|
||||||
<width>71</width>
|
<width>71</width>
|
||||||
<height>32</height>
|
<height>32</height>
|
||||||
</rect>
|
</rect>
|
||||||
@ -211,7 +223,7 @@
|
|||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>240</x>
|
<x>240</x>
|
||||||
<y>580</y>
|
<y>590</y>
|
||||||
<width>71</width>
|
<width>71</width>
|
||||||
<height>32</height>
|
<height>32</height>
|
||||||
</rect>
|
</rect>
|
||||||
@ -227,7 +239,7 @@
|
|||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>550</x>
|
<x>550</x>
|
||||||
<y>580</y>
|
<y>590</y>
|
||||||
<width>81</width>
|
<width>81</width>
|
||||||
<height>32</height>
|
<height>32</height>
|
||||||
</rect>
|
</rect>
|
||||||
@ -240,7 +252,7 @@
|
|||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>350</x>
|
<x>350</x>
|
||||||
<y>580</y>
|
<y>590</y>
|
||||||
<width>71</width>
|
<width>71</width>
|
||||||
<height>32</height>
|
<height>32</height>
|
||||||
</rect>
|
</rect>
|
||||||
@ -252,8 +264,8 @@
|
|||||||
<widget class="QLabel" name="label_5">
|
<widget class="QLabel" name="label_5">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>760</x>
|
<x>740</x>
|
||||||
<y>595</y>
|
<y>600</y>
|
||||||
<width>71</width>
|
<width>71</width>
|
||||||
<height>20</height>
|
<height>20</height>
|
||||||
</rect>
|
</rect>
|
||||||
@ -1014,17 +1026,17 @@
|
|||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QLabel" name="label_21">
|
<widget class="QPushButton" name="pushButton_logic">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>30</x>
|
<x>20</x>
|
||||||
<y>550</y>
|
<y>540</y>
|
||||||
<width>71</width>
|
<width>75</width>
|
||||||
<height>16</height>
|
<height>31</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>逻辑表达式:</string>
|
<string>逻辑表达式</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user