#include "EditNodeWidget.h" #include "SchemePlanManager.h" #include #include #include #include #include #include #include #include #include #include EditNodeWidget::EditNodeWidget(QWidget *parent) : QDialog(parent) { initWindow(); initWidgets(); initLayout(); connectSignalsAndSlots(); } CNodeData EditNodeWidget::node() const { return m_node; } void EditNodeWidget::setNode(CNodeData n) { m_node = n; m_name->setText(n.name); m_remark->setText(n.remark); m_dimen->setText(n.dimension); m_costComboBox->setCurrentIndex(n.type); m_validCheckBox->setChecked(!n.isEffective); m_confirm->setEnabled(false); } void EditNodeWidget::initWindow() { setWindowTitle("编辑节点"); // setWindowFlags(Qt::Window); // setWindowFlag(Qt::WindowMinMaxButtonsHint, false); setModal(true); setWindowFlags(Qt::Dialog); setWindowFlag(Qt::WindowContextHelpButtonHint, false); setFixedSize(400, 350); } void EditNodeWidget::initWidgets() { m_nameLabel = new QLabel("名称:", this); m_name = new LineEdit(this); m_remarkLabel = new QLabel("内涵:", this); m_remarkLabel->setContentsMargins(0, 10, 0, 10); m_remark = new TextEdit(this); m_dimen = new LineEdit(this); m_dimenLabel = new QLabel("量纲:", this); m_costLabel = new QLabel("类型:", this); m_costComboBox = new QComboBox(this); setUpCostTypes(); m_validLabel = new QLabel("生效:", this); m_validCheckBox = new CheckBox("", this); m_validCheckBox->setChecked(true); m_confirm = new PushButton("保存", this); m_cancel = new PushButton("取消", this); } void EditNodeWidget::initLayout() { m_layout = new QVBoxLayout(this); m_layout->setMargin(20); m_gridLayout = new QGridLayout(); m_layout->addLayout(m_gridLayout); m_layout->addSpacing(20); m_btnLayout = new QHBoxLayout(); m_layout->addLayout(m_btnLayout); int minW = 280; m_name->setMinimumWidth(minW); m_remark->setMinimumWidth(minW); m_dimen->setMinimumWidth(minW); m_gridLayout->addWidget(m_nameLabel, 0, 0, 1, 1, Qt::AlignRight); m_gridLayout->addWidget(m_name, 0, 1, 1, 1, Qt::AlignLeft); m_gridLayout->addWidget(m_remarkLabel, 1, 0, 1, 1, Qt::AlignRight | Qt::AlignTop); m_gridLayout->addWidget(m_remark, 1, 1, 1, 1, Qt::AlignLeft); m_gridLayout->addWidget(m_dimenLabel, 2, 0, 1, 1, Qt::AlignRight); m_gridLayout->addWidget(m_dimen, 2, 1, 1, 1, Qt::AlignLeft); m_gridLayout->addWidget(m_costLabel, 3, 0, 1, 1, Qt::AlignRight); m_gridLayout->addWidget(m_costComboBox, 3, 1, 1, 1, Qt::AlignLeft); m_gridLayout->addWidget(m_validLabel, 4, 0, 1, 1, Qt::AlignRight); m_gridLayout->addWidget(m_validCheckBox, 4, 1, 1, 1, Qt::AlignLeft); m_btnLayout->addStretch(); m_btnLayout->addWidget(m_confirm); m_btnLayout->addSpacing(20); m_btnLayout->addWidget(m_cancel); } void EditNodeWidget::connectSignalsAndSlots() { connect(m_name, &LineEdit::textChanged, this, &EditNodeWidget::slotEditChanged); connect(m_remark, &TextEdit::textChanged, this, &EditNodeWidget::slotEditChanged); connect(m_dimen, &LineEdit::textChanged, this, &EditNodeWidget::slotEditChanged); connect(m_costComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCostComboChanged(int))); connect(m_validCheckBox, &QCheckBox::stateChanged, this, &EditNodeWidget::slotEditChanged); connect(m_confirm, &PushButton::clicked, this, &EditNodeWidget::slotConfirmCLicked); connect(m_cancel, &PushButton::clicked, this, &EditNodeWidget::slotConcelClicked); } void EditNodeWidget::slotEditChanged() { m_confirm->setEnabled(true); m_node.name = m_name->text(); m_node.remark = m_remark->toPlainText(); m_node.dimension = m_dimen->text(); m_node.type = m_costComboBox->currentIndex(); m_node.isEffective = !m_validCheckBox->isChecked(); } void EditNodeWidget::slotCostComboChanged(int) { slotEditChanged(); } void EditNodeWidget::slotConfirmCLicked() { emit sigSaveNode(m_node); close(); } void EditNodeWidget::slotConcelClicked() { close(); } void EditNodeWidget::setUpCostTypes() { QMetaEnum metaEnum = QMetaEnum::fromType(); for (int i = 0; i < metaEnum.keyCount(); i++) { SchemePlanManager::IndexCostType value = (SchemePlanManager::IndexCostType)metaEnum.value(i); QString str = SchemePlanManager::stringFromIndexCostType(value); m_costComboBox->addItem(str); } m_costComboBox->setCurrentIndex(0); }