CreateProjWidget.cpp 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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. CreateProjWidget::Mode CreateProjWidget::mode() const
  20. {
  21. return m_mode;
  22. }
  23. void CreateProjWidget::setMode(CreateProjWidget::Mode mode)
  24. {
  25. m_mode = mode;
  26. switch (mode) {
  27. case Create: {
  28. setWindowTitle("创建项目");
  29. m_confirm->setText("创建");
  30. break;
  31. }
  32. case Update: {
  33. setWindowTitle("修改项目");
  34. m_confirm->setText("修改");
  35. break;
  36. }
  37. case Info: {
  38. setWindowTitle("项目信息");
  39. break;
  40. }
  41. }
  42. bool c = (mode == Create);
  43. bool cu = (mode == Update || mode == Create);
  44. m_taskName->setEnabled(cu);
  45. m_evalTime->setEnabled(c);
  46. m_evalPurpose->setEnabled(cu);
  47. m_evalUnit->setEnabled(cu);
  48. m_evalCrew->setEnabled(cu);
  49. m_rank->setEnabled(cu);
  50. m_note->setEnabled(cu);
  51. m_name->setEnabled(cu);
  52. m_type1->setEnabled(c);
  53. m_type2->setEnabled(c);
  54. m_type3->setEnabled(c);
  55. m_confirm->setVisible(cu);
  56. m_cancel->setVisible(cu);
  57. }
  58. void CreateProjWidget::resetInputs()
  59. {
  60. m_taskName->clear();
  61. m_evalTime->setDateTime(QDateTime::currentDateTime());
  62. m_evalPurpose->clear();
  63. m_evalUnit->clear();
  64. m_evalCrew->clear();
  65. m_rank->clear();
  66. m_note->clear();
  67. m_name->clear();
  68. m_type1->setChecked(false);
  69. m_type2->setChecked(false);
  70. m_type3->setChecked(false);
  71. }
  72. ProjectInfo *CreateProjWidget::projInfo() const
  73. {
  74. return m_projInfo;
  75. }
  76. ProjectInfo CreateProjWidget::editedProjInfo() const
  77. {
  78. ProjectInfo proj;
  79. proj.taskName = m_taskName->text();
  80. proj.estimateTime = QString::number(m_evalTime->dateTime().toTime_t());
  81. proj.estimateObjective = m_evalPurpose->text();
  82. proj.estimateDept = m_evalUnit->text();
  83. proj.estimatePerson = m_evalCrew->text();
  84. proj.positionalTitles = m_rank->text();
  85. proj.remark = m_note->toPlainText();
  86. proj.projectName = m_name->text();
  87. ProjectManager::EvalTypes t;
  88. t |= (m_type1->isChecked() ? ProjectManager::Requirements : ProjectManager::None);
  89. t |= (m_type2->isChecked() ? ProjectManager::SchemeOptimization : ProjectManager::None);
  90. t |= (m_type3->isChecked() ? ProjectManager::OverallEfficiency : ProjectManager::None);
  91. if (t != ProjectManager::None) {
  92. proj.estimateType = QString::number(t);
  93. }
  94. return proj;
  95. }
  96. void CreateProjWidget::setProjectInfo(ProjectInfo *info)
  97. {
  98. m_projInfo = info;
  99. m_taskName->setText(info->taskName);
  100. QDateTime time = QDateTime::fromTime_t(info->estimateTime.toUInt());
  101. m_evalTime->setDateTime(time);
  102. m_evalPurpose->setText(info->estimateObjective);
  103. m_evalUnit->setText(info->estimateDept);
  104. m_evalCrew->setText(info->estimatePerson);
  105. m_rank->setText(info->positionalTitles);
  106. m_note->setPlainText(info->remark);
  107. m_name->setText(info->projectName);
  108. ProjectManager::EvalTypes types = ProjectManager::evalTypes(*info);
  109. m_type1->setChecked((types & ProjectManager::Requirements) == ProjectManager::Requirements);
  110. m_type2->setChecked((types & ProjectManager::Requirements) == ProjectManager::SchemeOptimization);
  111. m_type3->setChecked((types & ProjectManager::Requirements) == ProjectManager::OverallEfficiency);
  112. }
  113. void CreateProjWidget::initWindow()
  114. {
  115. setWindowTitle("新建工程");
  116. // setWindowFlags(Qt::Window);
  117. // setWindowFlag(Qt::WindowMinMaxButtonsHint, false);
  118. setModal(true);
  119. setWindowFlags(Qt::Dialog);
  120. setWindowFlag(Qt::WindowContextHelpButtonHint, false);
  121. resize(400, 600);
  122. }
  123. void CreateProjWidget::initWidgets()
  124. {
  125. m_summary = new QLabel(this);
  126. m_summary->setText("项目概要:");
  127. m_taskName = new LineEdit(this);
  128. m_taskName->setPlaceholderText("任务名称");
  129. m_evalTime = new DateTimeEdit(this);
  130. m_evalPurpose = new LineEdit(this);
  131. m_evalPurpose->setPlaceholderText("评估目的");
  132. m_evalUnit = new LineEdit(this);
  133. m_evalUnit->setPlaceholderText("评估单位");
  134. m_evalCrew = new LineEdit(this);
  135. m_evalCrew->setPlaceholderText("评估人员");
  136. m_rank = new LineEdit(this);
  137. m_rank->setPlaceholderText("职称");
  138. m_note = new TextEdit(this);
  139. m_note->setPlaceholderText("备注");
  140. m_separator = new QWidget(this);
  141. m_separator->setFixedHeight(1);
  142. m_separator->setStyleSheet("background-color:#dddddd");
  143. m_nameLabel = new QLabel(this);
  144. m_nameLabel->setText("项目名称:");
  145. m_name = new LineEdit(this);
  146. m_name->setPlaceholderText("请输入项目名称");
  147. m_typeLabel = new QLabel(this);
  148. m_typeLabel->setText("评估类型:");
  149. m_type1 = new CheckBox(EngineerInfo::nameOfEvalType(EngineerInfo::Requirements), this);
  150. m_type2 = new CheckBox(EngineerInfo::nameOfEvalType(EngineerInfo::SchemeOptimization), this);
  151. m_type3 = new CheckBox(EngineerInfo::nameOfEvalType(EngineerInfo::OverallEfficiency), this);
  152. m_confirm = new PushButton("创建", this);
  153. m_cancel = new PushButton("取消", this);
  154. }
  155. void CreateProjWidget::initLayout()
  156. {
  157. // 总体布局
  158. m_layout = new QVBoxLayout(this);
  159. m_layout->setContentsMargins(50, 20, 50, 20);
  160. m_summaryLayout = new QVBoxLayout();
  161. m_layout->addLayout(m_summaryLayout);
  162. m_layout->addWidget(m_separator);
  163. m_projLayout = new QGridLayout();
  164. m_layout->addLayout(m_projLayout);
  165. m_btnLayout = new QHBoxLayout();
  166. m_layout->addLayout(m_btnLayout);
  167. // 项目概要布局
  168. m_summaryLayout->addWidget(m_summary);
  169. m_summaryLayout->addWidget(m_taskName);
  170. m_summaryLayout->addWidget(m_evalTime);
  171. m_summaryLayout->addWidget(m_evalPurpose);
  172. m_summaryLayout->addWidget(m_evalUnit);
  173. m_summaryLayout->addWidget(m_evalCrew);
  174. m_summaryLayout->addWidget(m_rank);
  175. m_summaryLayout->addWidget(m_note);
  176. // 项目信息布局
  177. m_projLayout->addWidget(m_nameLabel, 0, 0, 1, 1, Qt::AlignLeft);
  178. m_projLayout->addWidget(m_name, 0, 1, 1, 5, Qt::AlignLeft);
  179. m_name->setMinimumWidth(200);
  180. m_projLayout->addWidget(new QWidget(this), 1, 1, 4, 1, Qt::AlignLeft);
  181. m_projLayout->addWidget(m_typeLabel, 4, 0, 1, 1, Qt::AlignLeft);
  182. m_projLayout->addWidget(m_type1, 4, 1, 1, 5, Qt::AlignLeft);
  183. m_projLayout->addWidget(m_type2, 5, 1, 1, 5, Qt::AlignLeft);
  184. m_projLayout->addWidget(m_type3, 6, 1, 1, 5, Qt::AlignLeft);
  185. // 按钮布局
  186. m_btnLayout->addStretch();
  187. m_btnLayout->addWidget(m_confirm);
  188. m_btnLayout->addWidget(m_cancel);
  189. }
  190. void CreateProjWidget::connectSignalsAndSlots()
  191. {
  192. connect(m_taskName, &LineEdit::textChanged, this, &CreateProjWidget::slotTextChanged);
  193. connect(m_evalPurpose, &LineEdit::textChanged, this, &CreateProjWidget::slotTextChanged);
  194. connect(m_evalUnit, &LineEdit::textChanged, this, &CreateProjWidget::slotTextChanged);
  195. connect(m_evalCrew, &LineEdit::textChanged, this, &CreateProjWidget::slotTextChanged);
  196. connect(m_rank, &LineEdit::textChanged, this, &CreateProjWidget::slotTextChanged);
  197. connect(m_note, &TextEdit::textChanged, this, &CreateProjWidget::slotTextChanged);
  198. connect(m_name, &LineEdit::textChanged, this, &CreateProjWidget::slotTextChanged);
  199. connect(m_type1, &CheckBox::stateChanged, this, &CreateProjWidget::slotCheckBoxChanged);
  200. connect(m_type2, &CheckBox::stateChanged, this, &CreateProjWidget::slotCheckBoxChanged);
  201. connect(m_type3, &CheckBox::stateChanged, this, &CreateProjWidget::slotCheckBoxChanged);
  202. connect(m_confirm, &PushButton::clicked, this, &CreateProjWidget::slotCreateClicked);
  203. connect(m_cancel, &PushButton::clicked, this, &CreateProjWidget::slotCancelClicked);
  204. }
  205. void CreateProjWidget::updateCreateButtonState()
  206. {
  207. bool summaryValid = false;
  208. bool nameValid;
  209. bool typeValid;
  210. m_confirm->setEnabled(summaryValid && nameValid && typeValid);
  211. }
  212. void CreateProjWidget::slotTextChanged()
  213. {
  214. LineEdit *lineEdit = dynamic_cast<LineEdit *>(sender());
  215. if (lineEdit) {
  216. lineEdit->setText(lineEdit->text().trimmed());
  217. }
  218. }
  219. void CreateProjWidget::slotCheckBoxChanged() { }
  220. void CreateProjWidget::slotCreateClicked()
  221. {
  222. ProjectInfo p = editedProjInfo();
  223. qDebug() << __FUNCTION__ << p.taskName << p.estimateTime << p.estimateObjective << p.estimateDept
  224. << p.estimatePerson << p.positionalTitles << p.remark << p.projectName << p.estimateType;
  225. emit signalCreate();
  226. }
  227. void CreateProjWidget::slotCancelClicked()
  228. {
  229. close();
  230. }