CreateProjWidget.cpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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_task->setEnabled(cu);
  45. m_time->setEnabled(c);
  46. m_purpose->setEnabled(cu);
  47. m_unit->setEnabled(cu);
  48. m_crew->setEnabled(cu);
  49. m_rank->setEnabled(cu);
  50. m_note->setEnabled(cu);
  51. m_proj->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_task->clear();
  61. m_time->setDateTime(QDateTime::currentDateTime());
  62. m_purpose->clear();
  63. m_unit->clear();
  64. m_crew->clear();
  65. m_rank->clear();
  66. m_note->clear();
  67. m_proj->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_task->text();
  80. proj.estimateTime = QString::number(m_time->dateTime().toTime_t());
  81. proj.estimateObjective = m_purpose->text();
  82. proj.estimateDept = m_unit->text();
  83. proj.estimatePerson = m_crew->text();
  84. proj.positionalTitles = m_rank->text();
  85. proj.remark = m_note->toPlainText();
  86. proj.projectName = m_proj->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_task->setText(info->taskName);
  100. QDateTime time = QDateTime::fromTime_t(info->estimateTime.toUInt());
  101. m_time->setDateTime(time);
  102. m_purpose->setText(info->estimateObjective);
  103. m_unit->setText(info->estimateDept);
  104. m_crew->setText(info->estimatePerson);
  105. m_rank->setText(info->positionalTitles);
  106. m_note->setPlainText(info->remark);
  107. m_proj->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::SchemeOptimization) == ProjectManager::SchemeOptimization);
  111. m_type3->setChecked((types & ProjectManager::OverallEfficiency) == 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_task = new LineEdit(this);
  128. m_task->setPlaceholderText("任务名称");
  129. m_time = new DateTimeEdit(this);
  130. m_purpose = new LineEdit(this);
  131. m_purpose->setPlaceholderText("评估目的");
  132. m_unit = new LineEdit(this);
  133. m_unit->setPlaceholderText("评估单位");
  134. m_crew = new LineEdit(this);
  135. m_crew->setPlaceholderText("评估人员");
  136. m_rank = new LineEdit(this);
  137. m_rank->setPlaceholderText("职称");
  138. m_note = new TextEdit(this);
  139. m_note->setPlaceholderText("备注");
  140. m_taskLabel = new QLabel(this);
  141. m_taskLabel->setText("任务名称:");
  142. m_timeLabel = new QLabel(this);
  143. m_timeLabel->setText("评估时间:");
  144. m_purposeLabel = new QLabel(this);
  145. m_purposeLabel->setText("评估目的:");
  146. m_unitLabel = new QLabel(this);
  147. m_unitLabel->setText("评估单位:");
  148. m_crewLabel = new QLabel(this);
  149. m_crewLabel->setText("评估人员:");
  150. m_rankLabel = new QLabel(this);
  151. m_rankLabel->setText("职称:");
  152. m_noteLabel = new QLabel(this);
  153. m_noteLabel->setText("备注:");
  154. m_separator = new QWidget(this);
  155. m_separator->setFixedHeight(1);
  156. m_separator->setStyleSheet("background-color:#dddddd");
  157. m_projLabel = new QLabel(this);
  158. m_projLabel->setText("项目名称:");
  159. m_proj = new LineEdit(this);
  160. m_proj->setPlaceholderText("请输入项目名称");
  161. m_typeLabel = new QLabel(this);
  162. m_typeLabel->setText("评估类型:");
  163. m_type1 = new CheckBox(EngineerInfo::nameOfEvalType(EngineerInfo::Requirements), this);
  164. m_type2 = new CheckBox(EngineerInfo::nameOfEvalType(EngineerInfo::SchemeOptimization), this);
  165. m_type3 = new CheckBox(EngineerInfo::nameOfEvalType(EngineerInfo::OverallEfficiency), this);
  166. m_confirm = new PushButton("创建", this);
  167. m_cancel = new PushButton("取消", this);
  168. }
  169. void CreateProjWidget::initLayout()
  170. {
  171. int minEditWidth = 240;
  172. // 总体布局
  173. m_layout = new QVBoxLayout(this);
  174. m_layout->setContentsMargins(50, 20, 50, 20);
  175. m_layout->addWidget(m_summary);
  176. m_summaryLayout = new QGridLayout();
  177. m_layout->addLayout(m_summaryLayout);
  178. m_layout->addWidget(m_separator);
  179. m_projLayout = new QGridLayout();
  180. m_layout->addLayout(m_projLayout);
  181. m_btnLayout = new QHBoxLayout();
  182. m_layout->addLayout(m_btnLayout);
  183. // 项目概要布局
  184. m_task->setMinimumWidth(minEditWidth);
  185. m_time->setMinimumWidth(minEditWidth);
  186. m_purpose->setMinimumWidth(minEditWidth);
  187. m_unit->setMinimumWidth(minEditWidth);
  188. m_crew->setMinimumWidth(minEditWidth);
  189. m_rank->setMinimumWidth(minEditWidth);
  190. m_note->setMinimumWidth(minEditWidth);
  191. m_summaryLayout->setMargin(10);
  192. m_summaryLayout->addWidget(m_taskLabel, 1, 0, 1, 1, Qt::AlignRight);
  193. m_summaryLayout->addWidget(m_timeLabel, 2, 0, 1, 1, Qt::AlignRight);
  194. m_summaryLayout->addWidget(m_purposeLabel, 3, 0, 1, 1, Qt::AlignRight);
  195. m_summaryLayout->addWidget(m_unitLabel, 4, 0, 1, 1, Qt::AlignRight);
  196. m_summaryLayout->addWidget(m_crewLabel, 5, 0, 1, 1, Qt::AlignRight);
  197. m_summaryLayout->addWidget(m_rankLabel, 6, 0, 1, 1, Qt::AlignRight);
  198. m_summaryLayout->addWidget(m_noteLabel, 7, 0, 1, 1, Qt::AlignRight | Qt::AlignTop);
  199. m_summaryLayout->addWidget(m_task, 1, 1, 1, 1, Qt::AlignLeft);
  200. m_summaryLayout->addWidget(m_time, 2, 1, 1, 1, Qt::AlignLeft);
  201. m_summaryLayout->addWidget(m_purpose, 3, 1, 1, 1, Qt::AlignLeft);
  202. m_summaryLayout->addWidget(m_unit, 4, 1, 1, 1, Qt::AlignLeft);
  203. m_summaryLayout->addWidget(m_crew, 5, 1, 1, 1, Qt::AlignLeft);
  204. m_summaryLayout->addWidget(m_rank, 6, 1, 1, 1, Qt::AlignLeft);
  205. m_summaryLayout->addWidget(m_note, 7, 1, 1, 1, Qt::AlignLeft);
  206. // 项目信息布局
  207. m_projLayout->setMargin(10);
  208. m_proj->setMinimumWidth(minEditWidth);
  209. m_projLayout->addWidget(m_projLabel, 0, 0, 1, 1, Qt::AlignLeft);
  210. m_projLayout->addWidget(m_proj, 0, 1, 1, 5, Qt::AlignLeft);
  211. m_projLayout->addWidget(new QWidget(this), 1, 1, 4, 1, Qt::AlignLeft);
  212. m_projLayout->addWidget(m_typeLabel, 4, 0, 1, 1, Qt::AlignLeft);
  213. m_projLayout->addWidget(m_type1, 4, 1, 1, 5, Qt::AlignLeft);
  214. m_projLayout->addWidget(m_type2, 5, 1, 1, 5, Qt::AlignLeft);
  215. m_projLayout->addWidget(m_type3, 6, 1, 1, 5, Qt::AlignLeft);
  216. // 按钮布局
  217. m_btnLayout->addStretch();
  218. m_btnLayout->addWidget(m_confirm);
  219. m_btnLayout->addWidget(m_cancel);
  220. }
  221. void CreateProjWidget::connectSignalsAndSlots()
  222. {
  223. connect(m_task, &LineEdit::textChanged, this, &CreateProjWidget::slotTextChanged);
  224. connect(m_purpose, &LineEdit::textChanged, this, &CreateProjWidget::slotTextChanged);
  225. connect(m_unit, &LineEdit::textChanged, this, &CreateProjWidget::slotTextChanged);
  226. connect(m_crew, &LineEdit::textChanged, this, &CreateProjWidget::slotTextChanged);
  227. connect(m_rank, &LineEdit::textChanged, this, &CreateProjWidget::slotTextChanged);
  228. connect(m_note, &TextEdit::textChanged, this, &CreateProjWidget::slotTextChanged);
  229. connect(m_proj, &LineEdit::textChanged, this, &CreateProjWidget::slotTextChanged);
  230. connect(m_type1, &CheckBox::stateChanged, this, &CreateProjWidget::slotCheckBoxChanged);
  231. connect(m_type2, &CheckBox::stateChanged, this, &CreateProjWidget::slotCheckBoxChanged);
  232. connect(m_type3, &CheckBox::stateChanged, this, &CreateProjWidget::slotCheckBoxChanged);
  233. connect(m_confirm, &PushButton::clicked, this, &CreateProjWidget::slotCreateClicked);
  234. connect(m_cancel, &PushButton::clicked, this, &CreateProjWidget::slotCancelClicked);
  235. }
  236. void CreateProjWidget::updateCreateButtonState()
  237. {
  238. bool summaryValid = false;
  239. bool nameValid;
  240. bool typeValid;
  241. m_confirm->setEnabled(summaryValid && nameValid && typeValid);
  242. }
  243. void CreateProjWidget::slotTextChanged()
  244. {
  245. LineEdit *lineEdit = dynamic_cast<LineEdit *>(sender());
  246. if (lineEdit) {
  247. lineEdit->setText(lineEdit->text().trimmed());
  248. }
  249. }
  250. void CreateProjWidget::slotCheckBoxChanged() { }
  251. void CreateProjWidget::slotCreateClicked()
  252. {
  253. ProjectInfo p = editedProjInfo();
  254. qDebug() << __FUNCTION__ << p.taskName << p.estimateTime << p.estimateObjective << p.estimateDept
  255. << p.estimatePerson << p.positionalTitles << p.remark << p.projectName << p.estimateType;
  256. emit signalCreate();
  257. }
  258. void CreateProjWidget::slotCancelClicked()
  259. {
  260. close();
  261. }