CreateProjWidget.cpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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. bool i = (mode == Info);
  45. m_task->setEnabled(cu);
  46. m_time->setEnabled(c);
  47. m_purpose->setReadOnly(!cu);
  48. m_unit->setEnabled(cu);
  49. m_crew->setEnabled(cu);
  50. m_rank->setEnabled(cu);
  51. m_note->setReadOnly(!cu);
  52. m_proj->setEnabled(cu);
  53. m_type1->setEnabled(c);
  54. m_type2->setEnabled(c);
  55. m_type3->setEnabled(c);
  56. m_edit->setVisible(i);
  57. m_confirm->setVisible(cu);
  58. m_cancel->setVisible(cu);
  59. }
  60. void CreateProjWidget::resetInputs()
  61. {
  62. m_task->clear();
  63. m_time->setDateTime(QDateTime::currentDateTime());
  64. m_purpose->clear();
  65. m_unit->clear();
  66. m_crew->clear();
  67. m_rank->clear();
  68. m_note->clear();
  69. m_proj->clear();
  70. m_type1->setChecked(false);
  71. m_type2->setChecked(false);
  72. m_type3->setChecked(false);
  73. }
  74. ProjectInfo *CreateProjWidget::projInfo() const
  75. {
  76. return m_projInfo;
  77. }
  78. ProjectInfo CreateProjWidget::editedProjInfo() const
  79. {
  80. ProjectInfo proj;
  81. proj.taskName = m_task->text();
  82. proj.estimateTime = QString::number(m_time->dateTime().toTime_t());
  83. proj.estimateObjective = m_purpose->toPlainText();
  84. proj.estimateDept = m_unit->text();
  85. proj.estimatePerson = m_crew->text();
  86. proj.positionalTitles = m_rank->text();
  87. proj.remark = m_note->toPlainText();
  88. proj.projectName = m_proj->text();
  89. ProjectManager::EvalTypes t;
  90. t |= (m_type1->isChecked() ? ProjectManager::DemandEval : ProjectManager::None);
  91. t |= (m_type2->isChecked() ? ProjectManager::OptimalEval : ProjectManager::None);
  92. t |= (m_type3->isChecked() ? ProjectManager::EfficiencyEval : ProjectManager::None);
  93. if (t != ProjectManager::None) {
  94. proj.estimateType = QString::number(t);
  95. }
  96. return proj;
  97. }
  98. void CreateProjWidget::setProjectInfo(ProjectInfo *info)
  99. {
  100. m_projInfo = info;
  101. m_task->setText(info->taskName);
  102. QDateTime time = QDateTime::fromTime_t(info->estimateTime.toUInt());
  103. m_time->setDateTime(time);
  104. m_purpose->setText(info->estimateObjective);
  105. m_unit->setText(info->estimateDept);
  106. m_crew->setText(info->estimatePerson);
  107. m_rank->setText(info->positionalTitles);
  108. m_note->setText(info->remark);
  109. m_proj->setText(info->projectName);
  110. ProjectManager::EvalTypes types = ProjectManager::evalTypes(*info);
  111. m_type1->setChecked((types & ProjectManager::DemandEval) == ProjectManager::DemandEval);
  112. m_type2->setChecked((types & ProjectManager::OptimalEval) == ProjectManager::OptimalEval);
  113. m_type3->setChecked((types & ProjectManager::EfficiencyEval) == ProjectManager::EfficiencyEval);
  114. }
  115. void CreateProjWidget::initWindow()
  116. {
  117. setWindowTitle("新建工程");
  118. // setWindowFlags(Qt::Window);
  119. // setWindowFlag(Qt::WindowMinMaxButtonsHint, false);
  120. setModal(true);
  121. setWindowFlags(Qt::Dialog);
  122. setWindowFlag(Qt::WindowContextHelpButtonHint, false);
  123. setFixedSize(460, 700);
  124. }
  125. void CreateProjWidget::initWidgets()
  126. {
  127. m_summary = new QLabel(this);
  128. m_summary->setText("项目概要:");
  129. m_task = new LineEdit(this);
  130. m_task->setPlaceholderText("任务名称");
  131. m_time = new DateTimeEdit(this);
  132. m_purpose = new TextEdit(this);
  133. m_purpose->setPlaceholderText("评估目的");
  134. m_unit = new LineEdit(this);
  135. m_unit->setPlaceholderText("评估单位");
  136. m_crew = new LineEdit(this);
  137. m_crew->setPlaceholderText("评估人员");
  138. m_rank = new LineEdit(this);
  139. m_rank->setPlaceholderText("职称");
  140. m_note = new TextEdit(this);
  141. m_note->setPlaceholderText("备注");
  142. m_note->setFontPointSize(10);
  143. m_taskLabel = new QLabel(this);
  144. m_taskLabel->setText("任务名称:");
  145. m_timeLabel = new QLabel(this);
  146. m_timeLabel->setText("评估时间:");
  147. m_purposeLabel = new QLabel(this);
  148. m_purposeLabel->setText("评估目的:");
  149. m_unitLabel = new QLabel(this);
  150. m_unitLabel->setText("评估单位:");
  151. m_crewLabel = new QLabel(this);
  152. m_crewLabel->setText("评估人员:");
  153. m_rankLabel = new QLabel(this);
  154. m_rankLabel->setText("职称:");
  155. m_noteLabel = new QLabel(this);
  156. m_noteLabel->setText("备注:");
  157. m_separator = new QWidget(this);
  158. m_separator->setFixedHeight(1);
  159. m_separator->setStyleSheet("background-color:#dddddd");
  160. m_projLabel = new QLabel(this);
  161. m_projLabel->setText("项目名称:");
  162. m_proj = new LineEdit(this);
  163. m_proj->setPlaceholderText("请输入项目名称");
  164. m_typeLabel = new QLabel(this);
  165. m_typeLabel->setText("评估类型:");
  166. m_type1 = new CheckBox(EngineerInfo::nameOfEvalType(EngineerInfo::Requirements), this);
  167. m_type2 = new CheckBox(EngineerInfo::nameOfEvalType(EngineerInfo::SchemeOptimization), this);
  168. m_type3 = new CheckBox(EngineerInfo::nameOfEvalType(EngineerInfo::OverallEfficiency), this);
  169. m_edit = new PushButton("修改", this);
  170. m_confirm = new PushButton("创建", this);
  171. m_cancel = new PushButton("取消", this);
  172. }
  173. void CreateProjWidget::initLayout()
  174. {
  175. int minEditWidth = 300;
  176. // 总体布局
  177. m_layout = new QVBoxLayout(this);
  178. m_layout->setContentsMargins(20, 20, 20, 20);
  179. m_layout->addWidget(m_summary);
  180. m_summaryLayout = new QGridLayout();
  181. m_layout->addLayout(m_summaryLayout);
  182. m_layout->addWidget(m_separator);
  183. m_projLayout = new QGridLayout();
  184. m_layout->addLayout(m_projLayout);
  185. m_btnLayout = new QHBoxLayout();
  186. m_layout->addLayout(m_btnLayout);
  187. // 项目概要布局
  188. m_task->setFixedWidth(minEditWidth);
  189. m_time->setFixedWidth(minEditWidth);
  190. m_purpose->setFixedWidth(minEditWidth);
  191. m_unit->setFixedWidth(minEditWidth);
  192. m_crew->setFixedWidth(minEditWidth);
  193. m_rank->setFixedWidth(minEditWidth);
  194. m_note->setFixedWidth(minEditWidth);
  195. m_purposeLabel->setContentsMargins(0, 10, 0, 10);
  196. m_noteLabel->setContentsMargins(0, 10, 0, 10);
  197. m_summaryLayout->setMargin(10);
  198. m_summaryLayout->addWidget(m_taskLabel, 1, 0, 1, 1, Qt::AlignRight);
  199. m_summaryLayout->addWidget(m_timeLabel, 2, 0, 1, 1, Qt::AlignRight);
  200. m_summaryLayout->addWidget(m_unitLabel, 3, 0, 1, 1, Qt::AlignRight);
  201. m_summaryLayout->addWidget(m_crewLabel, 4, 0, 1, 1, Qt::AlignRight);
  202. m_summaryLayout->addWidget(m_rankLabel, 5, 0, 1, 1, Qt::AlignRight);
  203. m_summaryLayout->addWidget(m_purposeLabel, 6, 0, 1, 1, Qt::AlignRight | Qt::AlignTop);
  204. m_summaryLayout->addWidget(m_noteLabel, 7, 0, 1, 1, Qt::AlignRight | Qt::AlignTop);
  205. m_summaryLayout->addWidget(m_task, 1, 1, 1, 1, Qt::AlignLeft);
  206. m_summaryLayout->addWidget(m_time, 2, 1, 1, 1, Qt::AlignLeft);
  207. m_summaryLayout->addWidget(m_unit, 3, 1, 1, 1, Qt::AlignLeft);
  208. m_summaryLayout->addWidget(m_crew, 4, 1, 1, 1, Qt::AlignLeft);
  209. m_summaryLayout->addWidget(m_rank, 5, 1, 1, 1, Qt::AlignLeft);
  210. m_summaryLayout->addWidget(m_purpose, 6, 1, 1, 1, Qt::AlignLeft);
  211. m_summaryLayout->addWidget(m_note, 7, 1, 1, 1, Qt::AlignLeft);
  212. // 项目信息布局
  213. m_projLayout->setMargin(10);
  214. m_proj->setFixedWidth(minEditWidth);
  215. m_projLayout->addWidget(m_projLabel, 0, 0, 1, 1, Qt::AlignLeft);
  216. m_projLayout->addWidget(m_proj, 0, 1, 1, 1, Qt::AlignLeft);
  217. m_projLayout->addWidget(new QWidget(this), 1, 1, 1, 1, Qt::AlignLeft);
  218. m_projLayout->addWidget(m_typeLabel, 4, 0, 1, 1, Qt::AlignLeft);
  219. m_projLayout->addWidget(m_type1, 4, 1, 1, 1, Qt::AlignLeft);
  220. m_projLayout->addWidget(m_type2, 5, 1, 1, 1, Qt::AlignLeft);
  221. m_projLayout->addWidget(m_type3, 6, 1, 1, 1, Qt::AlignLeft);
  222. // 按钮布局
  223. m_btnLayout->addStretch();
  224. m_btnLayout->addWidget(m_edit);
  225. m_btnLayout->addWidget(m_confirm);
  226. m_btnLayout->addWidget(m_cancel);
  227. }
  228. void CreateProjWidget::connectSignalsAndSlots()
  229. {
  230. connect(m_task, &LineEdit::textChanged, this, &CreateProjWidget::slotTextChanged);
  231. connect(m_purpose, &TextEdit::textChanged, this, &CreateProjWidget::slotTextChanged);
  232. connect(m_unit, &LineEdit::textChanged, this, &CreateProjWidget::slotTextChanged);
  233. connect(m_crew, &LineEdit::textChanged, this, &CreateProjWidget::slotTextChanged);
  234. connect(m_rank, &LineEdit::textChanged, this, &CreateProjWidget::slotTextChanged);
  235. connect(m_note, &TextEdit::textChanged, this, &CreateProjWidget::slotTextChanged);
  236. connect(m_proj, &LineEdit::textChanged, this, &CreateProjWidget::slotTextChanged);
  237. connect(m_type1, &CheckBox::stateChanged, this, &CreateProjWidget::slotCheckBoxChanged);
  238. connect(m_type2, &CheckBox::stateChanged, this, &CreateProjWidget::slotCheckBoxChanged);
  239. connect(m_type3, &CheckBox::stateChanged, this, &CreateProjWidget::slotCheckBoxChanged);
  240. connect(m_edit, &PushButton::clicked, this, &CreateProjWidget::slotEditClicked);
  241. connect(m_confirm, &PushButton::clicked, this, &CreateProjWidget::slotConfirmClicked);
  242. connect(m_cancel, &PushButton::clicked, this, &CreateProjWidget::slotCancelClicked);
  243. }
  244. void CreateProjWidget::slotTextChanged()
  245. {
  246. LineEdit *lineEdit = dynamic_cast<LineEdit *>(sender());
  247. if (lineEdit) {
  248. lineEdit->setText(lineEdit->text().trimmed());
  249. }
  250. }
  251. void CreateProjWidget::slotCheckBoxChanged() { }
  252. void CreateProjWidget::slotEditClicked()
  253. {
  254. setMode(Update);
  255. }
  256. void CreateProjWidget::slotConfirmClicked()
  257. {
  258. ProjectInfo p = editedProjInfo();
  259. qDebug() << __FUNCTION__ << p.taskName << p.estimateTime << p.estimateObjective << p.estimateDept
  260. << p.estimatePerson << p.positionalTitles << p.remark << p.projectName << p.estimateType;
  261. emit signalConfirm();
  262. }
  263. void CreateProjWidget::slotCancelClicked()
  264. {
  265. if (m_mode == Update) {
  266. setMode(Info);
  267. setProjectInfo(m_projInfo);
  268. } else {
  269. close();
  270. }
  271. }