123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- #include "CreateProjWidget.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();
- initLayout();
- connectSignalsAndSlots();
- }
- const QString CreateProjWidget::projName() const
- {
- return m_name->text();
- }
- void CreateProjWidget::clearInputs()
- {
- m_name->clear();
- m_type1->setChecked(false);
- m_type2->setChecked(false);
- m_type3->setChecked(false);
- }
- 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_evalTime->setDateTime(QDateTime::currentDateTime());
- 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_name, &LineEdit::textChanged, this, &CreateProjWidget::slotProjNameChanged);
- connect(m_confirm, &PushButton::clicked, this, &CreateProjWidget::slotCreateClicked);
- connect(m_cancel, &PushButton::clicked, this, &CreateProjWidget::slotCancelClicked);
- }
- void CreateProjWidget::updateCreateButtonState()
- {
- bool summaryValid;
- bool nameValid;
- bool typeValid;
- m_confirm->setEnabled(summaryValid && nameValid && typeValid);
- }
- void CreateProjWidget::slotProjNameChanged(const QString &text)
- {
- m_name->setText(text.trimmed());
- updateCreateButtonState();
- }
- void CreateProjWidget::slotCreateClicked()
- {
- emit signalCreate();
- close();
- }
- void CreateProjWidget::slotCancelClicked()
- {
- close();
- }
|