#include "singlerelay.h" #include "ui_singlerelay.h" SingleRelay::SingleRelay(int slot,int cardtype,QWidget *parent) : QDialog(parent) , ui(new Ui::SingleRelay) { ui->setupUi(this); slot_no = slot; car_type = static_cast(cardtype); ui->label_slot_no->setText(QString::number(slot_no)); setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); 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); 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::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); } SingleRelay::~SingleRelay() { delete ui; } void SingleRelay::Init(){ QList buttonList = btnGroup_slot->buttons(); for (int i = 1; i < buttonList.count() + 1; i++) { std::shared_ptr 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; } } } std::shared_ptr 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(); 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(base_ptr); } void SingleRelay::on_pushButton_cancel_clicked() { this->close(); } 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){ 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); }