TSI_Config/singlerelay.cpp

155 lines
6.0 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_relay = new QVBoxLayout(ui->widget_relay);
textEdit_relay = new DropTextEdit;
layout_relay->addWidget(textEdit_relay);
QVBoxLayout *layout_available = new QVBoxLayout(ui->widget_available);
list_widget_available = new DraggableListWidget;
layout_available->addWidget(list_widget_available);
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->pushButton_backspace, &QPushButton::clicked, textEdit_relay, &DropTextEdit::removeLastElement);
connect(ui->comboBox_relay_ch, QOverload<int>::of(&QComboBox::currentIndexChanged),
this, &SingleRelay::onComboBoxIndexChanged);
Init();
current_index = ui->comboBox_relay_ch->currentIndex();
if(single_relay_nok_data->single_relay_nok[current_index].logic_expression != "")
textEdit_relay->setPlainText(single_relay_nok_data->single_relay_nok[current_index].logic_expression);
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-19 19:54:56 +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);
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;
2025-04-19 16:25:33 +08:00
QString item_str = QString("S%1C%2P##NO (Slot %3 Channel %4 Not OK)").arg(QString::number(button_id, 10).rightJustified(2, '0')).arg(QString::number(var+1, 10).rightJustified(2, '0')).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);
}
}
}
void SingleRelay::on_pushButton_enter_clicked()
{
}
void SingleRelay::on_pushButton_clr_clicked()
{
textEdit_relay->setText("");
}
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()
{
single_relay_nok_data->single_relay_nok[current_index].logic_expression = textEdit_relay->toPlainText();
this->close();
}
void SingleRelay::onComboBoxIndexChanged(int index){
qDebug()<< "[SingleRelay]:index " << index;
single_relay_nok_data->single_relay_nok[current_index].logic_expression = textEdit_relay->toPlainText();
current_index = index;
textEdit_relay->setPlainText(single_relay_nok_data->single_relay_nok[index].logic_expression);
}