TSI_Config/singlerelay.cpp

211 lines
8.6 KiB
C++
Raw Normal View History

2024-12-18 16:46:39 +08:00
#include "singlerelay.h"
#include "ui_singlerelay.h"
2025-04-21 20:30:12 +08:00
#include "vibrationdata.h"
2025-04-19 16:25:33 +08:00
SingleRelay::SingleRelay(int slot,int cardtype,QWidget *parent)
2024-12-18 16:46:39 +08:00
: QDialog(parent)
2025-03-27 10:16:01 +08:00
, ui(new Ui::SingleRelay) {
2024-12-18 16:46:39 +08:00
ui->setupUi(this);
2025-04-19 16:25:33 +08:00
slot_no = slot;
car_type = static_cast<CardType>(cardtype);
ui->label_slot_no->setText(QString::number(slot_no));
2025-03-27 10:16:01 +08:00
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
2025-04-19 16:25:33 +08:00
QVBoxLayout *layout_available = new QVBoxLayout(ui->widget_available);
2025-04-25 14:28:27 +08:00
list_widget_available = new QListWidget();
2025-04-19 16:25:33 +08:00
layout_available->addWidget(list_widget_available);
2025-04-23 17:13:05 +08:00
list_widget_available->setDragEnabled(true);
2025-04-19 16:25:33 +08:00
2025-04-25 14:28:27 +08:00
QVBoxLayout *layout_relay = new QVBoxLayout(ui->widget_relay);
treeView_relay = new QTreeView;
layout_relay->addWidget(treeView_relay);
treeView_relay->setDragEnabled(true); // 启用拖动
treeView_relay->setAcceptDrops(true); // 接受放下
treeView_relay->setDropIndicatorShown(true); // 显示放置指示器
treeView_relay->setDragDropMode(QAbstractItemView::DropOnly);
model_Relay = new DropTreeModel(this); //创建模型指定父类
treeView_relay->setModel(model_Relay);
treeView_relay->setHeaderHidden(true);
2025-04-19 16:25:33 +08:00
btnGroup_slot = new QButtonGroup(this);
btnGroup_slot->addButton(ui->pushButton_slot1);
btnGroup_slot->addButton(ui->pushButton_slot2);
btnGroup_slot->addButton(ui->pushButton_slot3);
btnGroup_slot->addButton(ui->pushButton_slot4);
btnGroup_slot->addButton(ui->pushButton_slot5);
btnGroup_slot->addButton(ui->pushButton_slot6);
btnGroup_slot->addButton(ui->pushButton_slot7);
btnGroup_slot->addButton(ui->pushButton_slot8);
btnGroup_slot->addButton(ui->pushButton_slot9);
btnGroup_slot->addButton(ui->pushButton_slot10);
btnGroup_slot->addButton(ui->pushButton_slot11);
btnGroup_slot->addButton(ui->pushButton_slot12);
btnGroup_slot->addButton(ui->pushButton_slot13);
btnGroup_slot->addButton(ui->pushButton_slot14);
btnGroup_slot->addButton(ui->pushButton_slot15);
btnGroup_slot->addButton(ui->pushButton_slot16);
2025-04-17 20:33:26 +08:00
2025-04-19 16:25:33 +08:00
connect(btnGroup_slot, SIGNAL(buttonClicked(QAbstractButton *)), this, SLOT(OnButtonGroup(QAbstractButton *)));
connect(ui->comboBox_relay_ch, QOverload<int>::of(&QComboBox::currentIndexChanged),
this, &SingleRelay::onComboBoxIndexChanged);
Init();
current_index = ui->comboBox_relay_ch->currentIndex();
2025-04-23 17:13:05 +08:00
if(single_relay_nok_data->single_relay_nok[current_index].logic_expression != ""){
QString channel_name = channelNameMap[single_relay_nok_data->single_relay_nok[current_index].logic_expression];
2025-04-25 14:28:27 +08:00
QStandardItem *item = new QStandardItem(channel_name);
item->setData(single_relay_nok_data->single_relay_nok[current_index].logic_expression,Qt::UserRole);
model_Relay->appendRow(item);
2025-04-23 17:13:05 +08:00
}
2024-12-18 16:46:39 +08:00
}
2025-03-27 10:16:01 +08:00
SingleRelay::~SingleRelay() {
2024-12-18 16:46:39 +08:00
delete ui;
}
2025-03-27 10:16:01 +08:00
2025-04-19 16:25:33 +08:00
void SingleRelay::Init(){
2025-04-19 19:54:56 +08:00
QList<QAbstractButton *> buttonList = btnGroup_slot->buttons();
for (int i = 1; i < buttonList.count() + 1; i++) {
std::shared_ptr<CardBase> base_ptr = ConfigMgr::Instance()->GetSlotPtr(i);
if(base_ptr != nullptr){
switch (base_ptr->card_type_) {
case kCardVibSingle :{
buttonList[i - 1]->setText("振动");
break;
}
case kCardKeyphaseSingle:{
buttonList[i - 1]->setText("键相");
break;
}
case kCardSpeedSingle:{
buttonList[i - 1]->setText("转速");
break;
}
case kCardRelaySingle:
case kCardRelaySingleNOK:
case kCardRelayTMRPrimary:{
buttonList[i - 1]->setText("继电器");
break;
}
default:
break;
}
}
}
2025-04-19 16:25:33 +08:00
std::shared_ptr<CardBase> base_ptr = ConfigMgr::Instance()->GetSlotPtr(slot_no);
if (base_ptr == nullptr) {
// do nothing or use template to init it.
single_relay_nok_data = std::make_shared<SingleRelayDataNOK>();
single_relay_nok_data->card_type_ = car_type;
single_relay_nok_data->slot_ = slot_no;
ConfigMgr::Instance()->AddCard(single_relay_nok_data);
return;
}
single_relay_nok_data = std::dynamic_pointer_cast<SingleRelayDataNOK>(base_ptr);
2025-04-23 17:13:05 +08:00
for(int i = 0 ; i < SLOT_NUM ; i++){
std::shared_ptr<CardBase> cardbase_ptr = ConfigMgr::Instance()->GetSlotPtr(i + 1);
if(cardbase_ptr != nullptr &&
cardbase_ptr->card_type_ == kCardVibSingle){
std::shared_ptr<VibrationData> ptr = std::dynamic_pointer_cast<VibrationData>(cardbase_ptr);
for (int var = 0; var < CHANNEL_COUNT; ++var) {
QString item_data,item_str;
item_str = QString("%1 (槽位 %2 通道 %3 非OK)").arg(ptr->base_config_[var].point_name).arg(ptr->base_config_[var].chan_id.mid(1,2)).arg(ptr->base_config_[var].chan_id.mid(4,2));
item_data = QString("%1P##NO").arg(ptr->base_config_[var].chan_id);
channelNameMap[item_data] = item_str;
}
}else if(cardbase_ptr != nullptr &&
cardbase_ptr->card_type_ == kCardSpeedSingle){
2025-04-19 19:54:56 +08:00
2025-04-23 17:13:05 +08:00
}
}
2025-04-19 16:25:33 +08:00
}
2025-03-27 10:16:01 +08:00
void SingleRelay::on_pushButton_cancel_clicked() {
this->close();
}
2025-04-19 16:25:33 +08:00
void SingleRelay::OnButtonGroup(QAbstractButton *slot_btn) {
if (slot_btn != NULL) {
list_widget_available->clear();
QString object_name = slot_btn->objectName();
qDebug() << object_name ;
int button_id = object_name.right(object_name.length() - 15).toInt();
for(int var = 0; var < CHANNEL_COUNT ; ++var){
2025-04-21 20:30:12 +08:00
std::shared_ptr<CardBase> base_ptr = ConfigMgr::Instance()->GetSlotPtr(button_id);
2025-04-25 14:28:27 +08:00
if(base_ptr->card_type_ == kCardVibSingle){
std::shared_ptr<VibrationData> vib_data = std::dynamic_pointer_cast<VibrationData>(base_ptr);
if((vib_data->base_config_[var].standby && vib_data->base_config_[var + 1].standby && !(var % 2)))
continue;
QString item_str = QString("%1 (槽位 %2 通道 %3 非OK)").arg(vib_data->base_config_[var].point_name).arg(button_id).arg(var+1);
QListWidgetItem *item = new QListWidgetItem(item_str);
QString item_data = QString("S%1C%2P##NO").arg(QString::number(button_id, 10).rightJustified(2, '0')).arg(QString::number(var+1, 10).rightJustified(2, '0'));
item->setData(Qt::UserRole, item_data);
list_widget_available->addItem(item);
}else if(base_ptr->card_type_ == kCardSpeedSingle){
}
2025-04-19 16:25:33 +08:00
}
}
}
void SingleRelay::on_pushButton_enter_clicked()
{
}
void SingleRelay::on_pushButton_clr_clicked()
{
2025-04-25 14:28:27 +08:00
2025-04-19 16:25:33 +08:00
}
void SingleRelay::on_pushButton_backspace_clicked()
{
}
void SingleRelay::keyPressEvent(QKeyEvent *event) {
// if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) {
// removeLastElement();
// return;
// }
// QTextEdit::keyPressEvent(event);
}
void SingleRelay::on_pushButton_confirm_clicked()
{
2025-04-25 14:28:27 +08:00
QStandardItemModel *model = qobject_cast<QStandardItemModel *>(treeView_relay->model());
if (!model) return;
QStandardItem *root = model->invisibleRootItem();
QStandardItem *topItem = root->child(0);
QString finalExpr;
QVariant userData = topItem->data(Qt::UserRole);
QString user_text = userData.toString().trimmed();
single_relay_nok_data->single_relay_nok[current_index].logic_expression = user_text;
2025-04-19 16:25:33 +08:00
this->close();
}
void SingleRelay::onComboBoxIndexChanged(int index){
qDebug()<< "[SingleRelay]:index " << index;
2025-04-25 14:28:27 +08:00
QStandardItemModel *model = qobject_cast<QStandardItemModel *>(treeView_relay->model());
if (!model) return;
QStandardItem *root = model->invisibleRootItem();
if(root->rowCount() > 0){
QStandardItem *topItem = root->child(0);
QString finalExpr;
QVariant userData = topItem->data(Qt::UserRole);
QString user_text = userData.toString().trimmed();
single_relay_nok_data->single_relay_nok[current_index].logic_expression = user_text;
2025-04-23 17:13:05 +08:00
}
2025-04-19 16:25:33 +08:00
current_index = index;
2025-04-25 14:28:27 +08:00
if(single_relay_nok_data->single_relay_nok[index].logic_expression != ""){
model_Relay->clear();
QString channel_name = channelNameMap[single_relay_nok_data->single_relay_nok[current_index].logic_expression];
QStandardItem *item = new QStandardItem(channel_name);
item->setData(single_relay_nok_data->single_relay_nok[current_index].logic_expression,Qt::UserRole);
model_Relay->appendRow(item);
}else{
model_Relay->clear();
}
2025-04-19 16:25:33 +08:00
}