#include "FlowGraphNodeWidget.h" #include "SchemePlanManager.h" #include "ProjectManager.h" #include #include #include #include #include #include FlowGraphNodeWidget::FlowGraphNodeWidget(NodeWidgetType type, QWidget *parent) : QWidget(parent), m_type(type) { setFixedSize(QSize(130, 30)); m_layout = new QVBoxLayout(this); m_layout->setMargin(0); } FlowGraphNodeWidget::NodeWidgetType FlowGraphNodeWidget::type() const { return m_type; } FlowGraphPlainNodeWidget::FlowGraphPlainNodeWidget(QWidget *parent) : FlowGraphNodeWidget(Plain, parent) { m_label = new QLabel(this); m_label->setText("test"); m_label->setStyleSheet("{font: bold}"); m_label->setAlignment(Qt::AlignCenter); m_layout->setMargin(0); m_layout->addWidget(m_label); } void FlowGraphPlainNodeWidget::setText(const QString text) { m_label->setText(text); } FlowGraphCheckNodeWidget::FlowGraphCheckNodeWidget(QWidget *parent) : FlowGraphNodeWidget(CheckBox, parent) { m_checkBox = new QCheckBox("执行", this); m_layout->setMargin(0); m_layout->setAlignment(Qt::AlignCenter); m_layout->addWidget(m_checkBox); } FlowGraphComboNodeWidget::FlowGraphComboNodeWidget(QWidget *parent) : FlowGraphNodeWidget(ComboBox, parent) { m_combo = new QComboBox(this); setStyleSheet("QComboBox {" "border: 1px solid gray;" "border-radius: 3px;" "padding: 1px 18px 1px 3px;" "min-width: 6em;" "}" "QComboBox:editable {" "background: white;" "}" "QComboBox:!editable, QComboBox::drop-down:editable {" "background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1," "stop: 0 #E1E1E1, stop: 0.4 #DDDDDD," "stop: 0.5 #D8D8D8, stop: 1.0 #D3D3D3);" "}"); m_layout->addWidget(m_combo); } QList FlowGraphComboNodeWidget::items() const { return m_items; } void FlowGraphComboNodeWidget::setItems(QList items) { m_items = items; m_combo->clear(); m_combo->addItems(items); } FlowGraphSpinNodeWidget::FlowGraphSpinNodeWidget(QWidget *parent) : FlowGraphNodeWidget(SpinBox, parent) { m_spinBox = new QSpinBox(this); m_spinBox->setMinimum(1); m_spinBox->setMaximum(10); m_spinBox->setValue(3); m_layout->addWidget(m_spinBox); } FlowGraphCommonNodeWidget::FlowGraphCommonNodeWidget(QWidget *parent) : QWidget(parent) { initWidget(); connectSignalsAndSlots(); } SchemePlanManager::SchemeProcessInfo FlowGraphCommonNodeWidget::process() const { return m_process; } void FlowGraphCommonNodeWidget::setProcess(SchemePlanManager::SchemeProcessInfo &i) { m_process = i; loadInfo(); } void FlowGraphCommonNodeWidget::setProcessId(int id) { m_process.id = id; } bool FlowGraphCommonNodeWidget::isTitleHidden() const { QList algs = SchemePlanManager::processOptionalAlgorithms(m_process); QList dsrc = SchemePlanManager::processOptionalDataSource(m_process); bool opt = SchemePlanManager::processIsOptional(m_process); return (algs.count() > 0 || dsrc.count() > 0 || opt); } void FlowGraphCommonNodeWidget::setAllowEdit(bool allow) { m_allowEdit = allow; m_algCombo->setEnabled(allow); m_dataCombo->setEnabled(allow); m_spinBox->setEnabled(allow); m_checkBox->setEnabled(allow); } void FlowGraphCommonNodeWidget::initWidget() { setFixedWidth(300); m_label = new QLabel(); m_algCombo = new QComboBox(); m_dataCombo = new QComboBox(); m_spinBox = new QSpinBox(); m_spinBox->setPrefix("效能分级:"); m_spinBox->setMaximum(100); m_spinBox->setMinimum(3); m_checkBox = new QCheckBox("执行"); m_layout = new QVBoxLayout(this); m_layout->setMargin(0); m_layout->setAlignment(Qt::AlignCenter); m_layout->addWidget(m_label); m_layout->addWidget(m_algCombo); m_layout->addWidget(m_dataCombo); m_layout->addWidget(m_spinBox); m_layout->addWidget(m_checkBox); } void FlowGraphCommonNodeWidget::connectSignalsAndSlots() { connect(m_algCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(slotAlgComboChanged(int))); connect(m_dataCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(slotDataComboChanged(int))); connect(m_spinBox, SIGNAL(valueChanged(int)), this, SLOT(slotSpinBoxChanged(int))); connect(m_spinBox, SIGNAL(valueChanged(int)), this, SLOT(slotSpinBoxChanged(int))); connect(m_checkBox, &QCheckBox::stateChanged, this, &FlowGraphCommonNodeWidget::slotCheckBoxChanged); } void FlowGraphCommonNodeWidget::loadInfo() { m_isLoaded = false; QList algs = optionalAlgs(); QList dsrc = optionaldSource(); bool opt = isOptional(); /// 标题 /// 在其他子控件都不显示时, 将标题居中显示 m_label->setHidden(algs.count() > 0 || dsrc.count() > 0 || opt); m_label->setText(title()); /// 算法选择组件 m_algCombo->setHidden(algs.count() < 1); m_algCombo->clear(); for (SchemePlanManager::Algorithm alg : algs) { m_algCombo->addItem(SchemePlanManager::nameOfAlgorithm(alg)); } int algIndex = 0; if (algs.count() > 0 && m_process.algorithm != SchemePlanManager::NoAlg) { algIndex = algs.indexOf(m_process.algorithm); } m_algCombo->setCurrentIndex(algIndex); /// 数据来源选择组件 m_dataCombo->setHidden(dsrc.count() < 1); m_dataCombo->clear(); for (SchemePlanManager::SchemeDataSource scr : dsrc) { m_dataCombo->addItem(SchemePlanManager::stringFromDataSource(scr)); } int dataIndex = 0; if (dsrc.count() > 0 && m_process.dSource != SchemePlanManager::NoData) { dataIndex = dsrc.indexOf(m_process.dSource); } m_dataCombo->setCurrentIndex(dataIndex); /// 选择执行组件 m_checkBox->setVisible(opt); m_checkBox->setChecked(m_process.isChecked); /// 效能分级组件 m_spinBox->setHidden(m_process.indexType != ProjectManager::EfficiencyIndex || m_process.type != SchemePlanManager::RunEvaluate); m_spinBox->setValue(m_process.efficiencyGrades); m_isLoaded = true; } QString FlowGraphCommonNodeWidget::title() const { return SchemePlanManager::processName(m_process); } QList FlowGraphCommonNodeWidget::optionalAlgs() const { return SchemePlanManager::processOptionalAlgorithms(m_process); } QList FlowGraphCommonNodeWidget::optionaldSource() const { return SchemePlanManager::processOptionalDataSource(m_process); } bool FlowGraphCommonNodeWidget::isOptional() const { return SchemePlanManager::processIsOptional(m_process); } void FlowGraphCommonNodeWidget::slotAlgComboChanged(int index) { QList list = optionalAlgs(); if (list.size() <= index) { return; } if (m_process.algorithm == list.at(index)) { return; } if (m_isLoaded) { m_process.algorithm = list.at(index); qDebug() << __FUNCTION__ << __LINE__ << m_process.algorithm << endl; emit sigProcessEdited(m_process); } } void FlowGraphCommonNodeWidget::slotDataComboChanged(int index) { QList list = optionaldSource(); if (list.size() <= index) { return; } if (m_process.dSource == list.at(index)) { return; } if (m_isLoaded) { m_process.dSource = list.at(index); emit sigProcessEdited(m_process); } } void FlowGraphCommonNodeWidget::slotSpinBoxChanged(int value) { if (m_process.efficiencyGrades == value) { return; } if (m_isLoaded) { m_process.efficiencyGrades = value; emit sigProcessEdited(m_process); } } void FlowGraphCommonNodeWidget::slotCheckBoxChanged() { if (m_process.isChecked == m_checkBox->isChecked()) { return; } if (m_isLoaded) { m_process.isChecked = m_checkBox->isChecked(); emit sigProcessEdited(m_process); } }