savetotemplate.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #include "savetotemplate.h"
  2. #include "ui_savetotemplate.h"
  3. #include "BroadCastTime.h"
  4. #include "ExecPlan.h"
  5. SaveToTemplate::SaveToTemplate(PageType type, QWidget *parent) :
  6. QDialog(parent),
  7. ui(new Ui::SaveToTemplate)
  8. {
  9. ui->setupUi(this);
  10. /* 设置隐藏边框 */
  11. this->setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint);
  12. /* 设置底层样式表 */
  13. this->setAttribute(Qt::WA_TranslucentBackground);
  14. m_type = type;
  15. ui->label_warn->hide();
  16. /* 限制字数类型 */
  17. ui->lineEdit->setMaxLength(15);
  18. connect(ui->pBtn_close,SIGNAL(clicked()),this,SLOT(close()));
  19. connect(ui->pBtn_cancel,SIGNAL(clicked()),this,SLOT(close()));
  20. connect(ui->pBtn_ok,SIGNAL(clicked()),this,SLOT(do_ok()));
  21. }
  22. SaveToTemplate::~SaveToTemplate()
  23. {
  24. delete ui;
  25. }
  26. void SaveToTemplate::do_ok()
  27. {
  28. ui->label_warn->hide();
  29. setWarning(false);
  30. /* 检查这一页的项是否为空 */
  31. if(m_type == PageType::PageExecPlan)
  32. {
  33. auto p = qobject_cast<ExecPlan*>(this->parent());
  34. if(p->itemIsEmpty())
  35. {
  36. ui->label_warn->setText("模版内容不能为空!");
  37. ui->label_warn->show();
  38. setWarning(true);
  39. return;
  40. }
  41. }
  42. else if(m_type == PageType::PageBroadCast)
  43. {
  44. auto p = qobject_cast<BroadCastTime*>(this->parent());
  45. if(p->itemIsEmpty())
  46. {
  47. ui->label_warn->setText("模版内容不能为空!");
  48. ui->label_warn->show();
  49. setWarning(true);
  50. return;
  51. }
  52. }
  53. /* 检查名称是否是空的 */
  54. QString str = ui->lineEdit->text();
  55. if(str.isEmpty())
  56. {
  57. ui->label_warn->setText("请输入模版名称!");
  58. ui->label_warn->show();
  59. setWarning(true);
  60. return;
  61. }
  62. /* 检查模板名称是否重复 */
  63. bool flag = false;
  64. if(m_type == PageType::PageBroadCast)
  65. {
  66. auto p = dynamic_cast<BroadCastTime*>(this->parent());
  67. if(p->checkDataBaseTableName(ui->lineEdit->text()))
  68. {
  69. flag = true;
  70. }
  71. }
  72. else if(m_type == PageType::PageExecPlan)
  73. {
  74. auto p = dynamic_cast<ExecPlan*>(this->parent());
  75. if(p->checkDataBaseTableName(ui->lineEdit->text()))
  76. {
  77. flag = true;
  78. }
  79. }
  80. if(flag)
  81. {
  82. ui->label_warn->setText("模版名称重复!");
  83. ui->label_warn->show();
  84. setWarning(true);
  85. return;
  86. }
  87. emit signal_templateName(ui->lineEdit->text());
  88. this->close();
  89. }
  90. /* 设置报警 */
  91. void SaveToTemplate::setWarning(bool flag)
  92. {
  93. if(flag)
  94. {
  95. ui->lineEdit->setProperty("Warn", true);
  96. }else
  97. {
  98. ui->lineEdit->setProperty("Warn", false);
  99. }
  100. ui->lineEdit->style()->unpolish(ui->lineEdit);
  101. ui->lineEdit->style()->polish(ui->lineEdit);
  102. }