123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- #include "EditNodeWidget.h"
- #include "SchemePlanManager.h"
- #include <Widgets/LineEdit.h>
- #include <Widgets/Button.h>
- #include <Widgets/CheckBox.h>
- #include <QLabel>
- #include <QBoxLayout>
- #include <QGridLayout>
- #include <QComboBox>
- #include <QCheckBox>
- #include <QMetaEnum>
- #include <QDebug>
- 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<SchemePlanManager::IndexCostType>();
- 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);
- }
|