CreateProjWidget.cpp 7.0 KB

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