#include "addnormalitem.h" #include "ui_addnormalitem.h" #include #include #include #include #include "common/combobox/customcombobox.h" #include "LHQLogAPI.h" #include "transmitterswitchinfo.h" #include "common/SelectTime/timewidget.h" AddNormalItem::AddNormalItem(QWidget *parent) : QDialog(parent), ui(new Ui::AddNormalItem) { ui->setupUi(this); /* 设置无边框 */ setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint); /* 设置底层样式表,让最底层的透明 */ this->setAttribute(Qt::WA_TranslucentBackground); /* 加载QSS */ QFile file(":/QSS/QSS/AddNormalItem_Light.qss"); if(file.open(QIODevice::ReadOnly)) { QString stylesheet = file.readAll(); this->setStyleSheet(stylesheet); file.close(); } else { LH_WRITE_ERROR(QString("打开文件失败:%1").arg(file.fileName())); } /* 设置comboBox阴影 */ ui->comBox_devSelect->setViewShadowEffect(); ui->comBox_actionSelect->setViewShadowEffect(); /* 获取父指针 */ // m_p = dynamic_cast(parent); ui->label_timeWarn->hide(); ui->label_devWarn->hide(); ui->label_actionWarn->hide(); /* 连接信号和槽 */ connect(ui->pBtn_Close, &QPushButton::clicked, this, &QDialog::close); connect(ui->pBtn_cancel, &QPushButton::clicked, this, &QDialog::close); connect(ui->pBtn_ok, &QPushButton::clicked, this, &AddNormalItem::do_ok); connect(ui->pBtn_cancel, &QPushButton::clicked, this, &AddNormalItem::close); /* 设备选择 */ connect(ui->comBox_devSelect, QOverload::of(&QComboBox::currentTextChanged), this, &AddNormalItem::do_selectDev); /* 动作选择 */ connect(ui->comBox_actionSelect,QOverload::of(&QComboBox::currentTextChanged),this, &AddNormalItem::do_selectAction); /* 打开时间选择器 */ connect(ui->pBtn_selectTime, &QPushButton::clicked, this, &AddNormalItem::do_selectTime); /* 设置默认时间 */ m_time.setHMS(0, 0, 0); } AddNormalItem::~AddNormalItem() { delete ui; } /* 设置父指针,时间选择器需要使用 */ void AddNormalItem::setParentPointer(QWidget* p) { /* 设置时间选择器 */ } /* 添加可选设备 */ void AddNormalItem::setDevice(QMap& mapDev) { ui->comBox_devSelect->clear(); for(const auto& it : mapDev) { ui->comBox_devSelect->addItem(it.devName); } /* 设置显示第一个设备,并设置可选的动作 */ ui->comBox_devSelect->setCurrentIndex(0); m_devName = ui->comBox_devSelect->currentText(); setAction(m_devName); } /* 进行查重和关闭页面 */ void AddNormalItem::do_ok() { ui->label_timeWarn->hide(); ui->label_devWarn->hide(); ui->label_actionWarn->hide(); setComboBoxWarning(ui->comBox_devSelect,false); setComboBoxWarning(ui->comBox_actionSelect, false); setTimeEditWarning(false); /* 检查设备是否为空 */ if(ui->comBox_devSelect->currentText().isEmpty()) { ui->label_devWarn->setText("不能为空!"); ui->label_devWarn->show(); setComboBoxWarning(ui->comBox_devSelect, true); return; } /* 检查动作是否为空 */ if(ui->comBox_actionSelect->currentText().isEmpty()) { ui->label_actionWarn->setText("不能为空!"); ui->label_actionWarn->show(); setComboBoxWarning(ui->comBox_actionSelect, true); } /* 时间赋值 */ /* 检查时间是否为空 */ if(m_time.isNull()) { ui->label_timeWarn->setText("不能为空!"); ui->label_timeWarn->show(); setTimeEditWarning(true); return; } /* 进行设备查重 */ // bool ret = m_p->judgeTimeRepetition(*m_p->m_vecItem[m_p->m_stack->currentIndex()],m_devName,m_time); // if(ret) // { // ui->label_timeWarn->setText("一个时间点,单个设备仅能执行一个操作!"); // ui->label_timeWarn->show(); // setTimeEditWarning(true); // return; // } /* 发送信号 */ emit signal_addNormalItem(m_devName,m_action,m_time); close(); } /* 选择了设备,设置其对应的动作 */ void AddNormalItem::do_selectDev() { m_devName = ui->comBox_devSelect->currentText(); setAction(m_devName); } /* 选择了动作 */ void AddNormalItem::do_selectAction() { m_action = ui->comBox_actionSelect->currentText(); } /* 点击了时间选择按钮,打开时间选择器 */ void AddNormalItem::do_selectTime() { LH_WRITE_LOG_DEBUG("选择时间"); std::shared_ptr tw = std::make_shared(this, TimeWidget::ShowType::Dialog); tw->showTimeEditArea(); } /* 设置选择框报警 */ void AddNormalItem::setComboBoxWarning(QComboBox* bo, bool flag) { if(flag) { bo->setProperty("Warn", true); } else { bo->setProperty("Warn", false); } bo->style()->unpolish(bo); bo->style()->polish(bo); } /* 设置时间报警 */ void AddNormalItem::setTimeEditWarning(bool flag) { if(flag) { ui->pBtn_selectTime->setProperty("Warn", true); } else { ui->pBtn_selectTime->setProperty("Warn", false); } ui->pBtn_selectTime->style()->unpolish(ui->pBtn_selectTime); ui->pBtn_selectTime->style()->polish(ui->pBtn_selectTime); } /* 设置动作 */ void AddNormalItem::setAction(const QString& devName) { QMap devAction; if(!DeviceContainer.getDevAction(devName, devAction)) { return; } ui->comBox_actionSelect->clear(); for(auto it = devAction.begin();it != devAction.end();it++) { ui->comBox_actionSelect->addItem(it.value(), it.key()); } }