123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- #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<ExecPlan*>(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<BroadCastTime*>(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<BroadCastTime*>(this->parent());
- if(p->checkDataBaseTableName(ui->lineEdit->text()))
- {
- flag = true;
- }
- }
- else if(m_type == PageType::PageExecPlan)
- {
- auto p = dynamic_cast<ExecPlan*>(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);
- }
|