#include "savetotemplate.h" #include "ui_savetotemplate.h" #include "BroadCastTime.h" #include "ExecPlan.h" SaveToTemplate::SaveToTemplate(PageType type, QWidget *parent) : QDialog(parent), ui(new Ui::SaveToTemplate) { ui->setupUi(this); /* 设置隐藏边框 */ this->setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint); /* 设置底层样式表 */ this->setAttribute(Qt::WA_TranslucentBackground); m_type = type; ui->label_warn->hide(); /* 限制字数类型 */ ui->lineEdit->setMaxLength(15); connect(ui->pBtn_close,SIGNAL(clicked()),this,SLOT(close())); connect(ui->pBtn_cancel,SIGNAL(clicked()),this,SLOT(close())); connect(ui->pBtn_ok,SIGNAL(clicked()),this,SLOT(do_ok())); } SaveToTemplate::~SaveToTemplate() { delete ui; } void SaveToTemplate::do_ok() { ui->label_warn->hide(); setWarning(false); /* 检查这一页的项是否为空 */ if(m_type == PageType::PageExecPlan) { auto p = qobject_cast(this->parent()); if(p->itemIsEmpty()) { ui->label_warn->setText("模版内容不能为空!"); ui->label_warn->show(); setWarning(true); return; } } else if(m_type == PageType::PageBroadCast) { auto p = qobject_cast(this->parent()); if(p->itemIsEmpty()) { ui->label_warn->setText("模版内容不能为空!"); ui->label_warn->show(); setWarning(true); return; } } /* 检查名称是否是空的 */ QString str = ui->lineEdit->text(); if(str.isEmpty()) { ui->label_warn->setText("请输入模版名称!"); ui->label_warn->show(); setWarning(true); return; } /* 检查模板名称是否重复 */ bool flag = false; if(m_type == PageType::PageBroadCast) { auto p = dynamic_cast(this->parent()); if(p->checkDataBaseTableName(ui->lineEdit->text())) { flag = true; } } else if(m_type == PageType::PageExecPlan) { auto p = dynamic_cast(this->parent()); if(p->checkDataBaseTableName(ui->lineEdit->text())) { flag = true; } } if(flag) { ui->label_warn->setText("模版名称重复!"); ui->label_warn->show(); setWarning(true); return; } emit signal_templateName(ui->lineEdit->text()); this->close(); } /* 设置报警 */ void SaveToTemplate::setWarning(bool flag) { if(flag) { ui->lineEdit->setProperty("Warn", true); }else { ui->lineEdit->setProperty("Warn", false); } ui->lineEdit->style()->unpolish(ui->lineEdit); ui->lineEdit->style()->polish(ui->lineEdit); }