CreateProjWidget.cpp 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. #include "CreateProjWidget.h"
  2. #include <common/ProjectManager.h>
  3. #include <dbService/ClassSet.h>
  4. #include <Widgets/LineEdit.h>
  5. #include <Widgets/Button.h>
  6. #include <Widgets/CheckBox.h>
  7. #include <Widgets/SpinBox.h>
  8. #include <QGridLayout>
  9. #include <QLabel>
  10. #include <QDebug>
  11. CreateProjWidget::CreateProjWidget(QWidget *parent) : QDialog(parent)
  12. {
  13. initWindow();
  14. initWidgets();
  15. resetInputs();
  16. initLayout();
  17. connectSignalsAndSlots();
  18. }
  19. void CreateProjWidget::resetInputs()
  20. {
  21. m_taskName->clear();
  22. m_evalTime->setDateTime(QDateTime::currentDateTime());
  23. m_evalPurpose->clear();
  24. m_evalUnit->clear();
  25. m_evalCrew->clear();
  26. m_rank->clear();
  27. m_note->clear();
  28. m_name->clear();
  29. m_type1->setChecked(false);
  30. m_type2->setChecked(false);
  31. m_type3->setChecked(false);
  32. }
  33. ProjectInfo CreateProjWidget::projectInfo() const
  34. {
  35. ProjectInfo proj;
  36. proj.taskName = m_taskName->text();
  37. proj.estimateTime = QString::number(m_evalTime->dateTime().toTime_t());
  38. proj.estimateObjective = m_evalPurpose->text();
  39. proj.estimateDept = m_evalUnit->text();
  40. proj.estimatePerson = m_evalCrew->text();
  41. proj.positionalTitles = m_rank->text();
  42. proj.remark = m_note->toPlainText();
  43. proj.projectName = m_name->text();
  44. ProjectManager::EvalTypes t;
  45. t |= (m_type1->isChecked() ? ProjectManager::Requirements : ProjectManager::None);
  46. t |= (m_type2->isChecked() ? ProjectManager::SchemeOptimization : ProjectManager::None);
  47. t |= (m_type3->isChecked() ? ProjectManager::OverallEfficiency : ProjectManager::None);
  48. if (t != ProjectManager::None) {
  49. proj.estimateType = QString::number(t);
  50. }
  51. return proj;
  52. }
  53. void CreateProjWidget::initWindow()
  54. {
  55. setWindowTitle("新建工程");
  56. // setWindowFlags(Qt::Window);
  57. // setWindowFlag(Qt::WindowMinMaxButtonsHint, false);
  58. setModal(true);
  59. setWindowFlags(Qt::Dialog);
  60. setWindowFlag(Qt::WindowContextHelpButtonHint, false);
  61. resize(400, 600);
  62. }
  63. void CreateProjWidget::initWidgets()
  64. {
  65. m_summary = new QLabel(this);
  66. m_summary->setText("项目概要:");
  67. m_taskName = new LineEdit(this);
  68. m_taskName->setPlaceholderText("任务名称");
  69. m_evalTime = new DateTimeEdit(this);
  70. m_evalPurpose = new LineEdit(this);
  71. m_evalPurpose->setPlaceholderText("评估目的");
  72. m_evalUnit = new LineEdit(this);
  73. m_evalUnit->setPlaceholderText("评估单位");
  74. m_evalCrew = new LineEdit(this);
  75. m_evalCrew->setPlaceholderText("评估人员");
  76. m_rank = new LineEdit(this);
  77. m_rank->setPlaceholderText("职称");
  78. m_note = new TextEdit(this);
  79. m_note->setPlaceholderText("备注");
  80. m_separator = new QWidget(this);
  81. m_separator->setFixedHeight(1);
  82. m_separator->setStyleSheet("background-color:#dddddd");
  83. m_nameLabel = new QLabel(this);
  84. m_nameLabel->setText("项目名称:");
  85. m_name = new LineEdit(this);
  86. m_name->setPlaceholderText("请输入项目名称");
  87. m_typeLabel = new QLabel(this);
  88. m_typeLabel->setText("评估类型:");
  89. m_type1 = new CheckBox(EngineerInfo::nameOfEvalType(EngineerInfo::Requirements), this);
  90. m_type2 = new CheckBox(EngineerInfo::nameOfEvalType(EngineerInfo::SchemeOptimization), this);
  91. m_type3 = new CheckBox(EngineerInfo::nameOfEvalType(EngineerInfo::OverallEfficiency), this);
  92. m_confirm = new PushButton("创建", this);
  93. m_cancel = new PushButton("取消", this);
  94. }
  95. void CreateProjWidget::initLayout()
  96. {
  97. // 总体布局
  98. m_layout = new QVBoxLayout(this);
  99. m_layout->setContentsMargins(50, 20, 50, 20);
  100. m_summaryLayout = new QVBoxLayout();
  101. m_layout->addLayout(m_summaryLayout);
  102. m_layout->addWidget(m_separator);
  103. m_projLayout = new QGridLayout();
  104. m_layout->addLayout(m_projLayout);
  105. m_btnLayout = new QHBoxLayout();
  106. m_layout->addLayout(m_btnLayout);
  107. // 项目概要布局
  108. m_summaryLayout->addWidget(m_summary);
  109. m_summaryLayout->addWidget(m_taskName);
  110. m_summaryLayout->addWidget(m_evalTime);
  111. m_summaryLayout->addWidget(m_evalPurpose);
  112. m_summaryLayout->addWidget(m_evalUnit);
  113. m_summaryLayout->addWidget(m_evalCrew);
  114. m_summaryLayout->addWidget(m_rank);
  115. m_summaryLayout->addWidget(m_note);
  116. // 项目信息布局
  117. m_projLayout->addWidget(m_nameLabel, 0, 0, 1, 1, Qt::AlignLeft);
  118. m_projLayout->addWidget(m_name, 0, 1, 1, 5, Qt::AlignLeft);
  119. m_projLayout->addWidget(new QWidget(this), 1, 1, 4, 1, Qt::AlignLeft);
  120. m_projLayout->addWidget(m_typeLabel, 4, 0, 1, 1, Qt::AlignLeft);
  121. m_projLayout->addWidget(m_type1, 4, 1, 1, 5, Qt::AlignLeft);
  122. m_projLayout->addWidget(m_type2, 5, 1, 1, 5, Qt::AlignLeft);
  123. m_projLayout->addWidget(m_type3, 6, 1, 1, 5, Qt::AlignLeft);
  124. // 按钮布局
  125. m_btnLayout->addStretch();
  126. m_btnLayout->addWidget(m_confirm);
  127. m_btnLayout->addWidget(m_cancel);
  128. }
  129. void CreateProjWidget::connectSignalsAndSlots()
  130. {
  131. connect(m_taskName, &LineEdit::textChanged, this, &CreateProjWidget::slotTextChanged);
  132. connect(m_evalPurpose, &LineEdit::textChanged, this, &CreateProjWidget::slotTextChanged);
  133. connect(m_evalUnit, &LineEdit::textChanged, this, &CreateProjWidget::slotTextChanged);
  134. connect(m_evalCrew, &LineEdit::textChanged, this, &CreateProjWidget::slotTextChanged);
  135. connect(m_rank, &LineEdit::textChanged, this, &CreateProjWidget::slotTextChanged);
  136. connect(m_note, &TextEdit::textChanged, this, &CreateProjWidget::slotTextChanged);
  137. connect(m_name, &LineEdit::textChanged, this, &CreateProjWidget::slotTextChanged);
  138. connect(m_type1, &CheckBox::stateChanged, this, &CreateProjWidget::slotCheckBoxChanged);
  139. connect(m_type2, &CheckBox::stateChanged, this, &CreateProjWidget::slotCheckBoxChanged);
  140. connect(m_type3, &CheckBox::stateChanged, this, &CreateProjWidget::slotCheckBoxChanged);
  141. connect(m_confirm, &PushButton::clicked, this, &CreateProjWidget::slotCreateClicked);
  142. connect(m_cancel, &PushButton::clicked, this, &CreateProjWidget::slotCancelClicked);
  143. }
  144. void CreateProjWidget::updateCreateButtonState()
  145. {
  146. bool summaryValid = false;
  147. bool nameValid;
  148. bool typeValid;
  149. m_confirm->setEnabled(summaryValid && nameValid && typeValid);
  150. }
  151. void CreateProjWidget::slotTextChanged()
  152. {
  153. LineEdit *lineEdit = dynamic_cast<LineEdit *>(sender());
  154. if (lineEdit) {
  155. lineEdit->setText(lineEdit->text().trimmed());
  156. }
  157. }
  158. void CreateProjWidget::slotCheckBoxChanged() { }
  159. void CreateProjWidget::slotCreateClicked()
  160. {
  161. ProjectInfo p = projectInfo();
  162. qDebug() << __FUNCTION__ << p.taskName << p.estimateTime << p.estimateObjective << p.estimateDept
  163. << p.estimatePerson << p.positionalTitles << p.remark << p.projectName << p.estimateType;
  164. emit signalCreate();
  165. close();
  166. }
  167. void CreateProjWidget::slotCancelClicked()
  168. {
  169. close();
  170. }