123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- #include "CreateProjWidget.h"
- #include <common/ProjectManager.h>
- #include <dbService/ClassSet.h>
- #include <Widgets/LineEdit.h>
- #include <Widgets/Button.h>
- #include <Widgets/CheckBox.h>
- #include <Widgets/SpinBox.h>
- #include <QGridLayout>
- #include <QLabel>
- #include <QDebug>
- CreateProjWidget::CreateProjWidget(QWidget *parent) : QDialog(parent)
- {
- initWindow();
- initWidgets();
- resetInputs();
- initLayout();
- connectSignalsAndSlots();
- }
- void CreateProjWidget::resetInputs()
- {
- m_taskName->clear();
- m_evalTime->setDateTime(QDateTime::currentDateTime());
- m_evalPurpose->clear();
- m_evalUnit->clear();
- m_evalCrew->clear();
- m_rank->clear();
- m_note->clear();
- m_name->clear();
- m_type1->setChecked(false);
- m_type2->setChecked(false);
- m_type3->setChecked(false);
- }
- ProjectInfo CreateProjWidget::projectInfo() const
- {
- ProjectInfo proj;
- proj.taskName = m_taskName->text();
- proj.estimateTime = QString::number(m_evalTime->dateTime().toTime_t());
- proj.estimateObjective = m_evalPurpose->text();
- proj.estimateDept = m_evalUnit->text();
- proj.estimatePerson = m_evalCrew->text();
- proj.positionalTitles = m_rank->text();
- proj.remark = m_note->toPlainText();
- proj.projectName = m_name->text();
- ProjectManager::EvalTypes t;
- t |= (m_type1->isChecked() ? ProjectManager::Requirements : ProjectManager::None);
- t |= (m_type2->isChecked() ? ProjectManager::SchemeOptimization : ProjectManager::None);
- t |= (m_type3->isChecked() ? ProjectManager::OverallEfficiency : ProjectManager::None);
- if (t != ProjectManager::None) {
- proj.estimateType = QString::number(t);
- }
- return proj;
- }
- void CreateProjWidget::initWindow()
- {
- setWindowTitle("新建工程");
- // setWindowFlags(Qt::Window);
- // setWindowFlag(Qt::WindowMinMaxButtonsHint, false);
- setModal(true);
- setWindowFlags(Qt::Dialog);
- setWindowFlag(Qt::WindowContextHelpButtonHint, false);
- resize(400, 600);
- }
- void CreateProjWidget::initWidgets()
- {
- m_summary = new QLabel(this);
- m_summary->setText("项目概要:");
- m_taskName = new LineEdit(this);
- m_taskName->setPlaceholderText("任务名称");
- m_evalTime = new DateTimeEdit(this);
- m_evalPurpose = new LineEdit(this);
- m_evalPurpose->setPlaceholderText("评估目的");
- m_evalUnit = new LineEdit(this);
- m_evalUnit->setPlaceholderText("评估单位");
- m_evalCrew = new LineEdit(this);
- m_evalCrew->setPlaceholderText("评估人员");
- m_rank = new LineEdit(this);
- m_rank->setPlaceholderText("职称");
- m_note = new TextEdit(this);
- m_note->setPlaceholderText("备注");
- m_separator = new QWidget(this);
- m_separator->setFixedHeight(1);
- m_separator->setStyleSheet("background-color:#dddddd");
- m_nameLabel = new QLabel(this);
- m_nameLabel->setText("项目名称:");
- m_name = new LineEdit(this);
- m_name->setPlaceholderText("请输入项目名称");
- m_typeLabel = new QLabel(this);
- m_typeLabel->setText("评估类型:");
- m_type1 = new CheckBox(EngineerInfo::nameOfEvalType(EngineerInfo::Requirements), this);
- m_type2 = new CheckBox(EngineerInfo::nameOfEvalType(EngineerInfo::SchemeOptimization), this);
- m_type3 = new CheckBox(EngineerInfo::nameOfEvalType(EngineerInfo::OverallEfficiency), this);
- m_confirm = new PushButton("创建", this);
- m_cancel = new PushButton("取消", this);
- }
- void CreateProjWidget::initLayout()
- {
- // 总体布局
- m_layout = new QVBoxLayout(this);
- m_layout->setContentsMargins(50, 20, 50, 20);
- m_summaryLayout = new QVBoxLayout();
- m_layout->addLayout(m_summaryLayout);
- m_layout->addWidget(m_separator);
- m_projLayout = new QGridLayout();
- m_layout->addLayout(m_projLayout);
- m_btnLayout = new QHBoxLayout();
- m_layout->addLayout(m_btnLayout);
- // 项目概要布局
- m_summaryLayout->addWidget(m_summary);
- m_summaryLayout->addWidget(m_taskName);
- m_summaryLayout->addWidget(m_evalTime);
- m_summaryLayout->addWidget(m_evalPurpose);
- m_summaryLayout->addWidget(m_evalUnit);
- m_summaryLayout->addWidget(m_evalCrew);
- m_summaryLayout->addWidget(m_rank);
- m_summaryLayout->addWidget(m_note);
- // 项目信息布局
- m_projLayout->addWidget(m_nameLabel, 0, 0, 1, 1, Qt::AlignLeft);
- m_projLayout->addWidget(m_name, 0, 1, 1, 5, Qt::AlignLeft);
- m_projLayout->addWidget(new QWidget(this), 1, 1, 4, 1, Qt::AlignLeft);
- m_projLayout->addWidget(m_typeLabel, 4, 0, 1, 1, Qt::AlignLeft);
- m_projLayout->addWidget(m_type1, 4, 1, 1, 5, Qt::AlignLeft);
- m_projLayout->addWidget(m_type2, 5, 1, 1, 5, Qt::AlignLeft);
- m_projLayout->addWidget(m_type3, 6, 1, 1, 5, Qt::AlignLeft);
- // 按钮布局
- m_btnLayout->addStretch();
- m_btnLayout->addWidget(m_confirm);
- m_btnLayout->addWidget(m_cancel);
- }
- void CreateProjWidget::connectSignalsAndSlots()
- {
- connect(m_taskName, &LineEdit::textChanged, this, &CreateProjWidget::slotTextChanged);
- connect(m_evalPurpose, &LineEdit::textChanged, this, &CreateProjWidget::slotTextChanged);
- connect(m_evalUnit, &LineEdit::textChanged, this, &CreateProjWidget::slotTextChanged);
- connect(m_evalCrew, &LineEdit::textChanged, this, &CreateProjWidget::slotTextChanged);
- connect(m_rank, &LineEdit::textChanged, this, &CreateProjWidget::slotTextChanged);
- connect(m_note, &TextEdit::textChanged, this, &CreateProjWidget::slotTextChanged);
- connect(m_name, &LineEdit::textChanged, this, &CreateProjWidget::slotTextChanged);
- connect(m_type1, &CheckBox::stateChanged, this, &CreateProjWidget::slotCheckBoxChanged);
- connect(m_type2, &CheckBox::stateChanged, this, &CreateProjWidget::slotCheckBoxChanged);
- connect(m_type3, &CheckBox::stateChanged, this, &CreateProjWidget::slotCheckBoxChanged);
- connect(m_confirm, &PushButton::clicked, this, &CreateProjWidget::slotCreateClicked);
- connect(m_cancel, &PushButton::clicked, this, &CreateProjWidget::slotCancelClicked);
- }
- void CreateProjWidget::updateCreateButtonState()
- {
- bool summaryValid = false;
- bool nameValid;
- bool typeValid;
- m_confirm->setEnabled(summaryValid && nameValid && typeValid);
- }
- void CreateProjWidget::slotTextChanged()
- {
- LineEdit *lineEdit = dynamic_cast<LineEdit *>(sender());
- if (lineEdit) {
- lineEdit->setText(lineEdit->text().trimmed());
- }
- }
- void CreateProjWidget::slotCheckBoxChanged() { }
- void CreateProjWidget::slotCreateClicked()
- {
- ProjectInfo p = projectInfo();
- qDebug() << __FUNCTION__ << p.taskName << p.estimateTime << p.estimateObjective << p.estimateDept
- << p.estimatePerson << p.positionalTitles << p.remark << p.projectName << p.estimateType;
- emit signalCreate();
- close();
- }
- void CreateProjWidget::slotCancelClicked()
- {
- close();
- }
|