优化逻辑
This commit is contained in:
parent
16bad754f0
commit
c5a57c9678
@ -46,7 +46,8 @@ void ConfigMgr::Save(QString & file_path) {
|
||||
QJsonObject slot_item;
|
||||
if (card_type_[i] != kCardRelaySingle &&
|
||||
card_type_[i] != kCardRelayTMRPrimary &&
|
||||
card_type_[i] != kCardRelaySingleNOK) {
|
||||
card_type_[i] != kCardRelaySingleNOK &&
|
||||
card_type_[i] != kCardRelayTMRBackup) {
|
||||
for (int cid = 0; cid < CHANNEL_COUNT; ++cid) {
|
||||
QJsonObject channel_item;
|
||||
if (card_type_[i] == kCardVibSingle ||
|
||||
|
@ -44,13 +44,14 @@ typedef enum {
|
||||
kVibVelocity = 2 // 速度
|
||||
} VibChannelType;
|
||||
|
||||
typedef struct {
|
||||
typedef struct SlotConfig_{
|
||||
int slot;
|
||||
QString slot_type;
|
||||
QString chan_display;
|
||||
QString rack_type;
|
||||
QPushButton *slot_btn;
|
||||
QLabel *slot_label;
|
||||
SlotConfig_(){
|
||||
slot_type = "";
|
||||
}
|
||||
} SlotConfig;
|
||||
|
||||
enum CMTCommand {
|
||||
|
@ -33,6 +33,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
// QMenuBar *menuBar = this->menuBar();
|
||||
// this->setMenuBar(menuBar); //添加到对象树
|
||||
// menuBar->addMenu(ui->menu_start);
|
||||
current_slot = -1;
|
||||
ui->widget_body->setProperty("flag", "title");
|
||||
ui->menuBar->setProperty("flag", "menuBar");
|
||||
//关联事件过滤器用于双击放大
|
||||
@ -138,41 +139,6 @@ void MainWindow::initStyle() {
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::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;
|
||||
}
|
||||
int slot_id = 0;
|
||||
QJsonArray jsonArray = jsonDoc.array();
|
||||
for (const QJsonValue &value : jsonArray) {
|
||||
SlotConfig slot_config;
|
||||
if (value.isObject()) { // 处理数组中的对象,例如每个对象代表一个记录或用户等。
|
||||
QJsonObject obj = value.toObject();
|
||||
slot_config.slot = obj["slot"].toInt();
|
||||
slot_config.slot_type = obj["slot_type"].toString();
|
||||
slot_config.chan_display = obj["chan_display"].toString();
|
||||
slot_config.rack_type = obj["rack_type"].toString();
|
||||
map_slot_config.insert(slot_id, slot_config);
|
||||
slot_id ++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::createMenu() {
|
||||
QList<QAbstractButton *> buttonList = btnGroup_slot->buttons();
|
||||
for (int i = 0; i < buttonList.count(); i++) {
|
||||
@ -313,69 +279,57 @@ void MainWindow::onMenuActionTriggered() {
|
||||
} else if (slot_type == "OPM844") {
|
||||
chan_display = "转速";
|
||||
}
|
||||
if (card_type == kCardRelayTMRPrimary && (map_slot_config[button_id].slot_type != "" || map_slot_config[button_id + 1].slot_type != "" \
|
||||
|| map_slot_config[button_id + 2].slot_type != "")) {
|
||||
if (card_type == kCardRelayTMRPrimary &&
|
||||
(ConfigMgr::Instance()->card_type_[button_id - 1] != kCardNone ||
|
||||
ConfigMgr::Instance()->card_type_[button_id] != kCardNone ||
|
||||
ConfigMgr::Instance()->card_type_[button_id + 1] != kCardNone)) {
|
||||
QMessageBox::information(this, QStringLiteral("提示"), "不要重叠三冗余板卡配置,请在创建新配置之前移除现有的配置!");
|
||||
return;
|
||||
} else if (card_type == kCardRelayTMRPrimary && map_slot_config[button_id + 1].slot_type == "" \
|
||||
&& map_slot_config[button_id + 2].slot_type == "") {
|
||||
map_slot_config[button_id].slot_type = slot_type;
|
||||
map_slot_config[button_id].rack_type = "TMR1";
|
||||
map_slot_config[button_id].slot_btn->setText(chan_display);
|
||||
map_slot_config[button_id].chan_display = chan_display;
|
||||
map_slot_config[button_id + 1].slot_type = slot_type;
|
||||
map_slot_config[button_id + 1].rack_type = "TMR2";
|
||||
map_slot_config[button_id + 1].slot_btn->setText(chan_display);
|
||||
map_slot_config[button_id + 1].chan_display = chan_display;
|
||||
map_slot_config[button_id + 2].slot_type = slot_type;
|
||||
map_slot_config[button_id + 2].rack_type = "TMR3";
|
||||
map_slot_config[button_id + 2].slot_btn->setText(chan_display);
|
||||
map_slot_config[button_id + 2].chan_display = chan_display;
|
||||
|
||||
ConfigMgr::Instance()->card_type_[button_id - 1] = kCardRelayTMRPrimary;
|
||||
ConfigMgr::Instance()->card_type_[button_id] = kCardRelayTMRBackup;
|
||||
ConfigMgr::Instance()->card_type_[button_id + 1] = kCardRelayTMRBackup;
|
||||
|
||||
}
|
||||
if (rack_type == "两板卡" && (map_slot_config[button_id].slot_type != "" || map_slot_config[button_id + 1].slot_type != "")) {
|
||||
if (rack_type == "两板卡" &&
|
||||
(ConfigMgr::Instance()->card_type_[button_id - 1] != kCardNone ||
|
||||
ConfigMgr::Instance()->card_type_[button_id] != kCardNone)) {
|
||||
QMessageBox::information(this, QStringLiteral("提示"), "不要重叠两板卡配置,请在创建新配置之前移除现有的配置!");
|
||||
return;
|
||||
} else if (rack_type == "两板卡" && map_slot_config[button_id + 1].slot_type == "") {
|
||||
} else if (rack_type == "两板卡" && ConfigMgr::Instance()->card_type_[button_id - 1] != kCardNone) {
|
||||
map_slot_config[button_id].slot_type = slot_type;
|
||||
map_slot_config[button_id].rack_type = "Double1";
|
||||
map_slot_config[button_id].slot_btn->setText(chan_display);
|
||||
map_slot_config[button_id].chan_display = chan_display;
|
||||
map_slot_config[button_id + 1].slot_type = slot_type;
|
||||
map_slot_config[button_id + 1].rack_type = "Double2";
|
||||
map_slot_config[button_id + 1].slot_btn->setText(chan_display);
|
||||
map_slot_config[button_id + 1].chan_display = chan_display;
|
||||
}
|
||||
if (rack_type == "单板卡" && map_slot_config[button_id].slot_type != "") {
|
||||
QMessageBox::information(this, QStringLiteral("提示"), "不要重叠单板卡配置,请在创建新配置之前移除现有的配置!");
|
||||
return;
|
||||
} else if ((card_type == kCardVibSingle || card_type == kCardSpeedSingle ||
|
||||
if ((card_type == kCardVibSingle || card_type == kCardSpeedSingle ||
|
||||
card_type == kCardKeyphaseSingle || card_type == kCardRelaySingle ||
|
||||
kCardRelaySingleNOK) && map_slot_config[button_id].slot_type == "") {
|
||||
card_type == kCardRelaySingleNOK) && ConfigMgr::Instance()->card_type_[button_id - 1] != kCardNone) {
|
||||
map_slot_config[button_id].slot_type = slot_type;
|
||||
map_slot_config[button_id].rack_type = "Single";
|
||||
map_slot_config[button_id].chan_display = chan_display;
|
||||
button->setText(chan_display);
|
||||
ConfigMgr::Instance()->card_type_[button_id - 1] = card_type;
|
||||
}else if ((card_type == kCardVibSingle || card_type == kCardSpeedSingle ||
|
||||
card_type == kCardKeyphaseSingle || card_type == kCardRelaySingle ||
|
||||
card_type == kCardRelaySingleNOK) && ConfigMgr::Instance()->card_type_[button_id - 1] != kCardNone) {
|
||||
QMessageBox::information(this, QStringLiteral("提示"), "不要重叠单板卡配置,请在创建新配置之前移除现有的配置!");
|
||||
return;
|
||||
}
|
||||
if (action->text() == "重置模块") {
|
||||
if (ConfigMgr::Instance()->card_type_[button_id - 1] == kCardRelayTMRPrimary) {
|
||||
map_slot_config[button_id].slot_type = "";
|
||||
map_slot_config[button_id].rack_type = "0";
|
||||
map_slot_config[button_id].slot_btn->setText("");
|
||||
map_slot_config[button_id].chan_display = "";
|
||||
map_slot_config[button_id + 1].slot_type = "";
|
||||
map_slot_config[button_id + 1].rack_type = "0";
|
||||
map_slot_config[button_id + 1].slot_btn->setText("");
|
||||
map_slot_config[button_id + 1].chan_display = "";
|
||||
map_slot_config[button_id + 2].slot_type = "";
|
||||
map_slot_config[button_id + 2].rack_type = "0";
|
||||
map_slot_config[button_id + 2].slot_btn->setText("");
|
||||
map_slot_config[button_id + 2].chan_display = "";
|
||||
std::shared_ptr<CardBase> base_ptr = ConfigMgr::Instance()->GetSlotPtr(button_id);
|
||||
if(base_ptr != nullptr){
|
||||
ConfigMgr::Instance()->RemoveCard(base_ptr);
|
||||
@ -390,22 +344,16 @@ void MainWindow::onMenuActionTriggered() {
|
||||
if(base_ptr_backup2 != nullptr){
|
||||
ConfigMgr::Instance()->RemoveCard(base_ptr_backup2);
|
||||
ConfigMgr::Instance()->card_type_[button_id + 1] = kCardNone;
|
||||
|
||||
}
|
||||
|
||||
} else if (ConfigMgr::Instance()->card_type_[button_id - 1] == kCardRelayTMRBackup) {
|
||||
map_slot_config[button_id - 1].slot_type = "";
|
||||
map_slot_config[button_id - 1].rack_type = "0";
|
||||
map_slot_config[button_id - 1].slot_btn->setText("");
|
||||
map_slot_config[button_id - 1].chan_display = "";
|
||||
map_slot_config[button_id].slot_type = "";
|
||||
map_slot_config[button_id].rack_type = "0";
|
||||
map_slot_config[button_id].slot_btn->setText("");
|
||||
map_slot_config[button_id].chan_display = "";
|
||||
map_slot_config[button_id + 1].slot_type = "";
|
||||
map_slot_config[button_id + 1].rack_type = "0";
|
||||
map_slot_config[button_id + 1].slot_btn->setText("");
|
||||
map_slot_config[button_id + 1].chan_display = "";
|
||||
|
||||
}else if (ConfigMgr::Instance()->card_type_[button_id - 1] == kCardVibSingle ||
|
||||
ConfigMgr::Instance()->card_type_[button_id - 1] == kCardSpeedSingle ||
|
||||
ConfigMgr::Instance()->card_type_[button_id - 1] == kCardKeyphaseSingle) {
|
||||
@ -443,6 +391,9 @@ void MainWindow::OnButtonGroup(QAbstractButton *slot_btn) {
|
||||
int button_id = object_name.right(object_name.length() - 15).toInt();
|
||||
SlotConfig slot_config = map_slot_config[button_id];
|
||||
map_slot_config[button_id].slot_label->setStyleSheet("QLabel { color :#2980b9; font: bold 16px}");
|
||||
if(current_slot != -1)
|
||||
map_slot_config[current_slot].slot_label->setStyleSheet("");
|
||||
current_slot = button_id;
|
||||
std::shared_ptr<CardBase> base_ptr = ConfigMgr::Instance()->GetSlotPtr(button_id);
|
||||
if(base_ptr == nullptr){
|
||||
ConfigMgr::Instance()->card_type_[button_id - 1] = card_type;
|
||||
|
@ -46,6 +46,7 @@ private:
|
||||
|
||||
QProgressBar *progressBar;
|
||||
CardType card_type;
|
||||
int current_slot;
|
||||
|
||||
void createMenu();
|
||||
void createMenu(const QString& rootTitle, QPushButton* button = nullptr);
|
||||
|
@ -92,8 +92,6 @@ void RelaySetting::readJsonFile(const QString &filePath) {
|
||||
QJsonObject obj = value.toObject();
|
||||
slot_config.slot = obj["slot"].toInt();
|
||||
slot_config.slot_type = obj["slot_type"].toInt();
|
||||
slot_config.chan_display = obj["chan_display"].toString();
|
||||
slot_config.rack_type = obj["rack_type"].toString();
|
||||
map_slot_config.insert(slot_id, slot_config);
|
||||
slot_id ++;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user