|
@@ -0,0 +1,194 @@
|
|
|
+#include "addnormalitem.h"
|
|
|
+#include "ui_addnormalitem.h"
|
|
|
+
|
|
|
+#include <memory>
|
|
|
+#include <QDebug>
|
|
|
+#include <QListView>
|
|
|
+#include <QFile>
|
|
|
+
|
|
|
+#include "common/combobox/customcombobox.h"
|
|
|
+#include "LHQLogAPI.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.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<ExecPlan*>(parent);
|
|
|
+
|
|
|
+
|
|
|
+ ui->timeEdit->setTimeAreaWidth(132);
|
|
|
+ ui->timeEdit->SetMainWindow(this);
|
|
|
+
|
|
|
+ ui->label_timeWarn->hide();
|
|
|
+ ui->label_devWarn->hide();
|
|
|
+ ui->label_actionWarn->hide();
|
|
|
+
|
|
|
+ /* 添加设备项 */
|
|
|
+ // ui->comBox_devSelect->clear();
|
|
|
+ // for(const auto& it : DevInfo.cfgDevInfo())
|
|
|
+ // {
|
|
|
+ // ui->comBox_devSelect->addItem(it->devName);
|
|
|
+ // for(auto it1 = it->DevType.getDevAction().begin();it1 != it->DevType.getDevAction().end();it1++)
|
|
|
+ // {
|
|
|
+ // ui->comBox_actionSelect->addItem(it1.value());
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // ui->comBox_devSelect->setCurrentIndex(0);
|
|
|
+ // m_devName = ui->comBox_devSelect->currentText();
|
|
|
+ // /* 添加动作项 */
|
|
|
+ // ui->comBox_actionSelect->clear();
|
|
|
+ // auto it = DevInfo.cfgDevInfo().value(ui->comBox_devSelect->currentText(),nullptr);
|
|
|
+ // if(it != nullptr )
|
|
|
+ // {
|
|
|
+ // for(auto it1 = it->DevType.getDevAction().begin();it1 != it->DevType.getDevAction().end();it1++)
|
|
|
+ // {
|
|
|
+ // ui->comBox_actionSelect->addItem(it1.value());
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+
|
|
|
+
|
|
|
+ /* 连接信号和槽 */
|
|
|
+ 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<const QString&>::of(&QComboBox::currentTextChanged),this,[this](){
|
|
|
+ m_devName = ui->comBox_devSelect->currentText();
|
|
|
+ /* 根据选择的设备,设置该设备的动作 */
|
|
|
+ // ui->comBox_actionSelect->clear();
|
|
|
+ // auto it = DevInfo.cfgDevInfo().value(ui->comBox_devSelect->currentText(),nullptr);
|
|
|
+ // if(it != nullptr )
|
|
|
+ // {
|
|
|
+ // /* 将该设备支持的动作设置到选项中 */
|
|
|
+ // for(auto it1 = it->DevType.getDevAction().begin();it1 != it->DevType.getDevAction().end();it1++)
|
|
|
+ // {
|
|
|
+ // ui->comBox_actionSelect->addItem(it1.value());
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ });
|
|
|
+ /* 动作选择 */
|
|
|
+ connect(ui->comBox_actionSelect,QOverload<const QString&>::of(&QComboBox::currentTextChanged),this,[this](){
|
|
|
+ m_action = ui->comBox_actionSelect->currentText();
|
|
|
+ });
|
|
|
+// connect(ui->pBtn_selectTime,SIGNAL(clicked()),this,SLOT(do_selectTime()));
|
|
|
+
|
|
|
+ /* 设置默认时间 */
|
|
|
+ ui->timeEdit->setTime("00:00:00");
|
|
|
+}
|
|
|
+
|
|
|
+AddNormalItem::~AddNormalItem()
|
|
|
+{
|
|
|
+ delete ui;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+/* 进行查重和关闭页面 */
|
|
|
+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);
|
|
|
+ }
|
|
|
+
|
|
|
+ /* 时间赋值 */
|
|
|
+ m_time = ui->timeEdit->getFormTime();
|
|
|
+ /* 检查时间是否为空 */
|
|
|
+ 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::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->timeEdit->setProperty("Warn", true);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ ui->timeEdit->setProperty("Warn", false);
|
|
|
+ }
|
|
|
+
|
|
|
+ ui->timeEdit->style()->unpolish(ui->timeEdit);
|
|
|
+ ui->timeEdit->style()->polish(ui->timeEdit);
|
|
|
+}
|
|
|
+
|